Did you know that almost 75% of the app are not using the english language? According to statistica, three quarter of the users on the internet are non-english speaking users. Languages play an important role for your branding and marketing. If you app is able to display the local languages, you can target a wider audience who are only fluent in their native language. This is why making your application to support multiple languages may increase downloads of your app and promote the brand as well.
Multilingual WPF Applications
For WPF applications, I can think of two ways to do it. First is to go through the method of dependencies, by using engines, Nuget packages that are predesigned and can be easily port over and used in our applications.
The 2nd method is to to dynamically change the string resources at runtime. In this stackoverflow post, the method is briefly explained. But lets talk about it here.
As mentioned, there is no dependencies needed in this method. The only thing you need is to prepare the language resources (*.xaml) and load it at runtime according to the language you pick. Voila, all the magic is done by WPF. Check out the workflow:
- Set a generic label for every strings
- Load the selected language during application start.
- Change the label immediately based on the specified language.
- Store selected language flag into settings for next launch.
So what do we need in the code behind. There are two major components. The first is the resource dictionary files needed. They are usually named according to the language that it refers to, for example StringResources.es.xaml or StringResources.zh-Hans.xaml. The middle part indicating which language the file is used for.
Secondly, the labels needs binding to the DynamicResource key that will make it capable of updating at real-time based on the selected language.
Runtime loads the resource dictionary into application resources. The snippet below shows that If the key exists, the later will overwrite the previous one. So you do not need to remove the language dictionary before changing to another language.
The important part in this approach is loading the right resources into the WPF application.
Use language standard naming i.e. en for English, es for Spanish, zh-Hans for Simplified Chinese, etc. Although we can use whatever file name for the language resources, it is good if we follow the set standard for language files. See Culture Code for infos.
One challenge when it comes to implementing multilingual apps are usually programmers are not proficient in translation. Generally, a person is only proficient in one or two languages. But to implement a comprehensive multilingual support requires understanding of way more languages than a programmer may know.
Luckily there are a lot of translation services offered out there like Google translation, Crowdin, ackuna etc.
Another concern when doing translation works is the translator or author of a language file might prefer to use normal documents to maintain rather than directly modifying the value in *.xaml/*.resx files. However, its worth noting that learning up the translation services is not hard.
However, most of the authors still prefer to enter the value in document format like Excel/Text. In that case, automation is probably required to easily convert excel values into *.xaml/*.resx albeit as an additional step in the overall workflow compared to directly modifying.
To Do or Not To Do?
Ultimately, having a multilingual support in apps are a good feature. But the challenge is definitely there. Lets say your app has 100 wordings/strings. To have 5 language supports would mean you have to maintain 5×100=500 words in your app. So perhaps its worth pondering if the cost and effort needed to set it up is worth it? What do you think?
Originally published at http://filpal.wordpress.com on April 18, 2021.