How to get OS primary language and localize UI text acoordingly RRS feed

  • Question

  • We need to add localization feature to our app to support at least English, German, and Chinese. First, we try to find out the primary language of users' system. In win32, we used GetThreadLocale, now in Metro, we use the method:

    String^ strAppLanguage = ref new String();
    strAppLanguage = Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride;

    But the content of strAppLanguage is always NULL after executing the statements. So how can I find out the primary language?

    Next, we have prepared three resources.resw files under the directories "en", "de" and "zh-tw", and add "x:Uid" to UI elements in XAML files. But how to load one of these resource files?

    I've read the "Application resources and localization sample" but this sample is not intuitive at all. Is there any step-by-step tutorial on localization in Metro-style app? Thanks.

    Monday, October 29, 2012 3:55 PM


All replies

  • Start with Globalizing your app . There are several quick starts which cover the topics in a more step-by-step fashion than the sample.

    There is no direct equivalent to GetThreadLocale, and if you follow the recommended pattern you don't need it. If you use and provide resources as described the ResourceManager will automatically follow the user's chosen language. You don't need to explicitly choose the language.

    If you have specific questions about how to use the ResourceManager or about what specific parts of the Application resources and localization sample are confusing you then please provide details of what you need to know.



    Tuesday, October 30, 2012 6:36 AM
  • Thanks a lot Rob, your reference is what I'm looking for.

    But now I have problems in localizing button text in AppBar. Here is the definition of "open file" button in bottom AppBar

                        <Button x:Uid="AppBar_Open"  Style="{StaticResource AppBarButtonStyle}" 
                                AutomationProperties.AutomationId="OpenFileAppBarButton" Content="&#xE1A5;"  
                                AutomationProperties.Name="Open File" 

    And here is the definition of "edit" button in top AppBar

                        <Button x:Uid="GraphLayerEdit" Grid.Row="0" Grid.Column="1"
                                Style="{StaticResource AppBarButtonStyle}" 
                                AutomationProperties.AutomationId="DiscardAppBarButton" Content="&#xE107;"  

    The relevant content in en-us/Resources.resw is:

    <GraphLayerEdit.ToolTipService.ToolTip, "Remove current layer">

    <AppBar_Open.AutomationProperties.Name, "Open files">

    when I run the app, it throws an exception reporting

    “WinRT information: Unable to resolve property 'ToolTipService.ToolTip' while processing properties for Uid 'GraphLayerEdit'.

    Tuesday, October 30, 2012 11:21 AM
    • Marked as answer by Leonard Tuesday, October 30, 2012 3:15 PM
    Tuesday, October 30, 2012 3:15 PM