locked
sideloaded app can not change language programmatically RRS feed

  • Question

  • 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;
                             }



    • Edited by SW_Andy Friday, September 26, 2014 1:46 PM
    Friday, September 26, 2014 8:37 AM

Answers

  • In order to respond right away, you would need to reset the context of the resource manager.

    For Windows 8.1: var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();

    resourceContext.Reset();

    You will still need to force your page to redraw itself and thus re-request the resources to get the changes to take place. For Windows 8, you can see https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx

    Monday, September 29, 2014 6:53 AM

All replies

  • Hmmm.. I think I was able to kinda workaround that behaviour. What I've done originally after the language Switch code, was to navigate directly back to the very first page of the app (which then is newley built) - since the language-switch should also act like a reset.

    As mentioned before that worked fine for direct deploy on my machine and remote deploy on several other machines and tablets (tested Laptops, tablets and Desktops).

    Sideloading seemed to Change that behaviour - I do not know why (and maybe if it would be a store app it would have acted the same way). So my solution was to create a blank page with nothing in it and after short delay of about 50ms Forward to the first page of the app. Kind of quirky, but it works. If there's no delay the same behaviour as above illustrated occurs... language Change has no effect. With a Little delay - it has.

    Friday, September 26, 2014 2:38 PM
  • In order to respond right away, you would need to reset the context of the resource manager.

    For Windows 8.1: var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();

    resourceContext.Reset();

    You will still need to force your page to redraw itself and thus re-request the resources to get the changes to take place. For Windows 8, you can see https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx

    Monday, September 29, 2014 6:53 AM