0

I have a default datepicker control in Windows Phone 8.1 app. When the device language is changed, the datepicker fields still retains the English text rather than the translated text. Should I be adding any separate logic to translate these texts, like explicitly defining the month names and days in Templates with necessary logic for translations?

Image with Highlighted Text to be translated

enter image description here

Any help or suggestions would greatly help.

Thanks in advance

VVN
  • 1,607
  • 2
  • 16
  • 25
Sriram
  • 55
  • 1
  • 9
  • You have Language property to specify in which language control should be – Archana Apr 18 '16 at 07:16
  • Have you try to reboot after changing language? – Alexej Sommer Apr 18 '16 at 07:18
  • @Archana.I have added the Language attribute to the Datepicker control with explicitly setting the language value to "fr-FR" (French). But no changes. – Sriram Apr 18 '16 at 07:46
  • @Alexej Yes. After updating the device language, the devices prompts us to change the language. I am already localising my app with resource strings supporting a few translations when the device language is changed. But this datepicker control is a plain control and does not have any modifications. Not sure whether I need to explicitly define the strings for this to support translations – Sriram Apr 18 '16 at 07:51
  • If you add support for that particular language in Package.appmanifest file,it will work. There is default language field – Archana Apr 18 '16 at 09:13

2 Answers2

0

There is Language property to specify language.

<DatePicker Name="date" />
     CultureInfo ci = new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]);
                date.Language = ci.ToString();

Update

To get it work done you have to add support for that particular language in Package.appmanifest file. There is default language field in manifest file. You can do this programmatically

 CultureInfo ci = new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = ci.Name;
            CultureInfo.DefaultThreadCurrentCulture = ci;
            CultureInfo.DefaultThreadCurrentUICulture = ci; 
Archana
  • 3,213
  • 1
  • 15
  • 21
0

DatePicker supports Globalization and localization by default. There is no need to set anything in DatePicker to support multi-language.

What we need to do is Specify the supported languages in the app's manifest.

An app developer specifies the list of supported languages in the Resources element of the app's manifest file (typically Package.appxmanifest), or Visual Studio automatically generates the list of languages in the manifest file based on the languages found in the project. The manifest should accurately describe the supported languages at the appropriate level of granularity. The languages listed in the manifest are the languages displayed to users in the Windows Store.

To make sure the app supports "fr-FR", we can select the "Package.appxmanifest" in "Solution Explorer" and right click, then select "View Code" and use

<Resources>
  <Resource Language="EN-US" />
  <Resource Language="FR-FR" />
</Resources>

instead of

<Resources>
  <Resource Language="x-generate" />
</Resources>

After this when you change your device's language to "France", the DatePicker will automatically display in France. However this won't take effect immediately, a reboot is required.
enter image description here

Update:

The PrimaryLanguageOverride is a simple override setting for apps that give users their own independent language choice, or apps that have some strong reason to override the default language choices.

So you can use PrimaryLanguageOverride to implement what you want.

The PrimaryLanguageOverride setting is persisted between sessions. It should not be set each time the app is loaded. It should only be set based on user input presented in settings UI. The property can be read at any time. If the property has never been set, it returns an empty string.

You can add a "Automatic" option in your drop down control. And when user selects this option, you can set PrimaryLanguageOverride to empty string like:

ApplicationLanguages.PrimaryLanguageOverride = string.Empty;

Then your app will using device language setting according to your supported languages. For more information about which language will display in your app, please see Create the application language list and Language matching.

When use selects other languages in your drop down control, you can set PrimaryLanguageOverride to the selected language to force your app to display in this language. For more info about the use of PrimaryLanguageOverride, you can check Remarks in ApplicationLanguages.PrimaryLanguageOverride | primaryLanguageOverride property.

Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • Thanks for the suggestion Jay. Currently my application supports localisation in two modes. One is through Device language setting and another one through a drop down control provided in the app itself which offers the users a list of languages we support. Would this methodology support both of the modes? App language preference actually has the higher priority over the device language. – Sriram Apr 20 '16 at 06:14
  • @Sriram: Yeah, `PrimaryLanguageOverride` has the higher priority and I think it's possible to support both of your modes. Please check my updated answer. – Jay Zuo Apr 20 '16 at 07:11
  • Thanks for the update Jay. Your suggestion logic matches with my implementation. I'm overriding the PrimaryLanguage when the user explicitly selects a specific language in the App. Or else it would default to device language. – Sriram Apr 20 '16 at 16:03