Monday, September 29, 2014

sideloaded app can not change language programmatically

Hi there,



for an Enterprise solution the Client demands switching languages in app. I provided two different Solutions, which both are working fine. However - if the app is sideloaded I can't Switch the languages anymore... the code is being executed without any exceptions thrown. The language remains the same.


Is there some Kind of restrictions when the app is sideloaded? Because if I remote deploy to those devices, the language Switch is fine. After switching I'm recreating the views of course.


Here's the code I'm using:



if (newLanguage == "en")
{
var culture = new CultureInfo("en-US");
ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en";
}
if (newLanguage == "fr")
{
var culture = new CultureInfo("fr-FR");
ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "fr";
}



or second (also working) solution:



if (prevLanguage != newLanguage)
{
ResourceContext defaultContextForCurrentView = ResourceContext.GetForCurrentView();
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = newLanguage;
ApplicationData.Current.LocalSettings.Values["currentLanguage"] = newLanguage;
defaultContextForCurrentView.Reset();
prevLanguage = newLanguage;
}






No comments:

Post a Comment