×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Aug 2012
    Location
    Rhine Valley
    Posts
    78

    Any idea on how to change the language dynamically?

    Hi all,

    I wondered if it is possible to change the UI language of a running WP(8) XAML app dynamically.

    The scenario I have on my mind is an app that is localized in some languages, say English, German and French. English is the Default language. Now say you have an user in Africa. As English is not the first foreign language everywhere in the world my user might want to switch the UI language to French. Can this be done?

    I searched on the web and found the following resources:

    - [http://code.msdn.microsoft.com/wpapp...ample-a2237b7a The MSDN Globalization Sample]
    - [http://stackoverflow.com/questions/6...during-runtime SO: How to change windows phone APP language during runtime?]

    I tried to change the MSDN sample with code to chnage the UI but wasn't successful. Even if I save the language selection in iso store and set the thread UI culture on app start to the selected language the UI is not switched.

    Any ideas?

    Thomas

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Any idea on how to change the language dynamically?

    Some opinions without actual experience:
    Quote Originally Posted by influencer View Post
    The scenario I have on my mind is an app that is localized in some languages, say English, German and French. English is the Default language. Now say you have an user in Africa. As English is not the first foreign language everywhere in the world my user might want to switch the UI language to French. Can this be done?
    Generally I would assume if the user wants French language, she or he is already using the entire device in French. So switching languages in runtime, for a single application, may have limited importance.
    I searched on the web and found the following resources
    Following the referred articles and some other articles they suggest reading, my impression is that you have to notify the UI elements manually in order to have them re-read text labels, etc.
    Even if I save the language selection in iso store and set the thread UI culture on app start to the selected language the UI is not switched.
    "Magic" based frameworks often initialize a large part of the UI (based on descriptor files) before executing a single line of your actual executable code.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Any idea on how to change the language dynamically?

    Tottaly agree, @wizard_hu_.

    But if @influencer still want to offer the option to explicitly set the language for the app, t can inform the user that it will only take effect on the next run or invalidate all UI.

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    419

    Re: Any idea on how to change the language dynamically?

    If I read it correctly he is already trying to set the UI Thread culture on Startup and it still does not work.

    The class that is responsible for the actual localization is defined as Resource in App.xaml:

    <Application.Resources>
    <local:LocalizedStrings xmlns:local="clr-namespace:Refocus" x:Key="LocalizedStrings"/>
    </Application.Resources>

    This class basically only has a property LocalizedResources which is of Type AppResources. In AppResources there is a private field called resourceCulture. This can be accessed using a public Property called Culture.

    To test this I put the following code into App.xaml.cs:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    AppResources.Culture = new System.Globalization.CultureInfo("de-DE");
    }

    My App then comes up in German instead of in English (which is it's default culture and the one the OS uses (in the Emulator)).

    I have not tried switching language at runtime per-se but using the default classes provided with every new WP8 XAML App this should work at least upon navigation. If you need it to work immediately you perhaps would have to modify the LocalizedStrings class to not use AppResources directly but rather an observable Wrapper around it. You would perhaps need a Code Generator though as you would have to make sure that all properties on AppResources are wrapped to be Observable (and doing this by hand would be rather tedious). The Binding to that Wrapper could possibly be the same or perhaps you would have to specify "BindingType=OneWay" on the Text-Bindings (without checking though I believe that is the default anyway).

    Sry if the reply is rather curiously structured but I wrote it down while following the trail (so to say) from Button to RESX-File to find out how it's inner workings are. Hope it helps.

  5. #5
    Regular Contributor
    Join Date
    Aug 2012
    Location
    Rhine Valley
    Posts
    78

    Re: Any idea on how to change the language dynamically?

    Quote Originally Posted by wizard_hu_ View Post
    Generally I would assume if the user wants French language, she or he is already using the entire device in French. So switching languages in runtime, for a single application, may have limited importance.
    Agreed, if the phone's UI language is supported by the app. If the phone is set to Suaheli, maybe the user wants to choose between English or French.

  6. #6
    Regular Contributor
    Join Date
    Aug 2012
    Location
    Rhine Valley
    Posts
    78

    Re: Any idea on how to change the language dynamically?

    Quote Originally Posted by SB Dev View Post
    This class basically only has a property LocalizedResources which is of Type AppResources. In AppResources there is a private field called resourceCulture. This can be accessed using a public Property called Culture.

    To test this I put the following code into App.xaml.cs:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    AppResources.Culture = new System.Globalization.CultureInfo("de-DE");
    }

    My App then comes up in German instead of in English (which is it's default culture and the one the OS uses (in the Emulator)).
    I'll try this. Maybe that's the missing brick.

    Thanks

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    419

    Re: Any idea on how to change the language dynamically?

    Did it work? I'm curious?

  8. #8
    Regular Contributor
    Join Date
    Aug 2012
    Location
    Rhine Valley
    Posts
    78

    Re: Any idea on how to change the language dynamically?

    I didn't try yet.
    I'll tell when it's implemented.

Similar Threads

  1. Replies: 1
    Last Post: 2010-08-10, 11:08
  2. Replies: 9
    Last Post: 2010-08-02, 11:41
  3. change language dynamically.
    By vineet.jain in forum Symbian C++
    Replies: 2
    Last Post: 2009-09-14, 19:23
  4. Changing language dynamically
    By ramanathan_s12 in forum Symbian C++
    Replies: 1
    Last Post: 2009-06-24, 14:57
  5. SetTextL - Dynamically change
    By tronicart in forum Symbian C++
    Replies: 3
    Last Post: 2005-09-27, 11:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •