locked
Localizing Windows 8.1 App

    Question

  • Hello,

    I'm in the process of moving my Windows Phone 8 app to a universal Windows 8.1 app, but I'm having difficulty adjusting to the new way apps are localized in Windows 8.1.  In my application I'd like to make use of the data model provided, but I can't figure out how to localize it. For example in a shared application a SampleData.json is created under the DataModel folder. How do I change the phrases into localized text? I've already read this document: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965329.aspx

    Sample Code:

    "Groups":[
      {
        "UniqueId": "Group-1",
        "Title": "Group Title: 1",
        "Subtitle": "Group subtitle: 1",
        "ImagePath": "Assets/DarkGray.png",
        "Description" : "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante",
        "Items":

    What I'm trying to do:

    "Groups":[
      {
        "UniqueId": "Group-1",
        "Title": Resources.GroupTitle1,
        "Subtitle": Resources.GroupSubtitle1,
        "ImagePath": "Assets/DarkGray.png",
        "Description" : Resources.GroupTitleDescription1,
        "Items":

    Thanks,

    Dylan

    Edit: Posted this under HTML5/JavaScript by accident but I'm using C#
    Monday, July 28, 2014 4:45 AM

Answers

  • Hi!

    To localize your Windows 8.1 App on C# it's about the same as localizing a Windows Phone App. I would advice first to read Creating and retrieving resources in Windows Store apps.

    You have two possible approaches:

    In the first one, you first need a Resources (.resw) file in your project (I often create a folder called "strings" to put them in), you can create it with the "Add new > File" dialog. The file name can be anything (most common scenario is Resources.resw). If you want to support several languages, you can create several files with the same name in a folder structure where the folder name is the culture code, for example, strings/en-US/Resources.resw for your base language, strings/es/Resources.resw for spanish and so on (list of supported cultures is here).

    This Resource file will be presented as a two-column table, the first one for the Name of the resource (how do you want to access it programatically), the second for the string in the language (the third column is optional).

    You then use the "Uid" property of a control to bind it to the resource, for example:

    You declare a resource called MyTitle.Text with the string "My App".

    Then on the XAML you can use it like this:

    <TextBlock x:Uid="MyTitle" />
    

    This will alter the Text property of the control according to the Resource file.

    You can then localize any control property by using the Uid.

    You can use the ResourceManager to access these strings on the C# code (not the XAML) as it was suggested on previous posts, but this is the way on the XAML.

    The second one, uses a separate DLL project for the Resources, you can see the official Windows 8 Application Resources and Localization sample. This approach works when you have several projects (maybe a Universal App solution) that shares the resources. When you use any Template for a Universal App in VS2013, it creates the Resources in the Shared project for you.

    Wednesday, July 30, 2014 2:02 AM
  • Hi

    Refer this video and you will get your full solution

    Localization in windows 8.1

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpfull


    Er.Rasik Ambaliya

    Thursday, July 31, 2014 5:55 AM

All replies

  • you need to do this from cod. You can use th ResourceLoader class to retrieve strings form your resource file

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, July 28, 2014 5:12 AM
  • Thanks for your response. I found this webpage http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.resources.resourceloader.aspx about the ResourceLoader. However, I'm still confused about using it in a data bound list view like the one in the sample Hub project.

    Sample:

    <HubSection x:Uid="HubSection4" Header="SECTION 4"
                            DataContext="{Binding Groups[2]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
                    <DataTemplate>
                        <ListView 
                            AutomationProperties.AutomationId="ItemListViewSection4"
                            AutomationProperties.Name="Items In Group"
                            SelectionMode="None"
                            IsItemClickEnabled="True"
                            ItemsSource="{Binding Items}"
                            ItemClick="ItemView_ItemClick"
                            ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0,0,0,19">
                                        <TextBlock Text="{Binding Title}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                                        <TextBlock Text="{Binding Subtitle}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </DataTemplate>
                </HubSection>

    Best,

    Dylan


    Tuesday, July 29, 2014 3:29 AM
  • Hi!

    To localize your Windows 8.1 App on C# it's about the same as localizing a Windows Phone App. I would advice first to read Creating and retrieving resources in Windows Store apps.

    You have two possible approaches:

    In the first one, you first need a Resources (.resw) file in your project (I often create a folder called "strings" to put them in), you can create it with the "Add new > File" dialog. The file name can be anything (most common scenario is Resources.resw). If you want to support several languages, you can create several files with the same name in a folder structure where the folder name is the culture code, for example, strings/en-US/Resources.resw for your base language, strings/es/Resources.resw for spanish and so on (list of supported cultures is here).

    This Resource file will be presented as a two-column table, the first one for the Name of the resource (how do you want to access it programatically), the second for the string in the language (the third column is optional).

    You then use the "Uid" property of a control to bind it to the resource, for example:

    You declare a resource called MyTitle.Text with the string "My App".

    Then on the XAML you can use it like this:

    <TextBlock x:Uid="MyTitle" />
    

    This will alter the Text property of the control according to the Resource file.

    You can then localize any control property by using the Uid.

    You can use the ResourceManager to access these strings on the C# code (not the XAML) as it was suggested on previous posts, but this is the way on the XAML.

    The second one, uses a separate DLL project for the Resources, you can see the official Windows 8 Application Resources and Localization sample. This approach works when you have several projects (maybe a Universal App solution) that shares the resources. When you use any Template for a Universal App in VS2013, it creates the Resources in the Shared project for you.

    Wednesday, July 30, 2014 2:02 AM
  • @Ealsur thanks for your detailed response. I'll update you in a few days after I have read all of the documentation. 
    Thursday, July 31, 2014 5:07 AM
  • Hi

    Refer this video and you will get your full solution

    Localization in windows 8.1

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpfull


    Er.Rasik Ambaliya

    Thursday, July 31, 2014 5:55 AM
  • Glad it helped :)

    If it does solve your issue, please mark the answer to help others with the same problem.

    Have a good day!

    Friday, August 01, 2014 1:42 AM