An easy way to build a localized app is to use resources file (.resx).
First of all remember to set the default "neutral" language in the project properties! This is an important step because the "AppResources.resx" file is used from all not specified languages.
Add new file, and name it "AppResources.resx" for default language. For a new language, just add a new resource named with the CultureInfo ISO letters:
- AppResources.it-IT.resx for italian language.
- AppResources.cs-CZ.resx for czech language.
- AppResources.fr-FR.resx for french language.
- etc..
Now unload your project and edit the csproj file to add your supported language:
<SupportedCultures>it-IT;en-US;cs-CZ;fr-FR</SupportedCultures>
Create a class to get your resources.
public class LocalizedStrings { private static AppResources localizedResources = new AppResources(); public AppResources Strings { get { return localizedResources; } } }
In your xaml you need to declare your class as resource:
<phone:PhoneApplicationPage.Resources> <local:LocalizedStrings x:Key="LocalizedStrings"/> </phone:PhoneApplicationPage.Resources>
Now you can use your localized string like this:
Text="{Binding Strings.Loading, Source={StaticResource LocalizedStrings}}"Or from code behind:
txtLoading.Text = AppResources.Loading;
To test your app you can insert this code in application launching event:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("it-IT"); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
All CultureInfo codes here.