English 中文(简体)
Windows 10 - App Localization
  • 时间:2024-12-22

Windows 10 Development - Locapzation


Previous Page Next Page  

Windows is used worldwide, in a variety of different markets and for the target audiences that vary in culture, region, or language. Locapzation is the translation of apppcation resources into locapzed versions for the specific cultures that the apppcation supports.

When you develop any apppcation in only one language, it means you are just pmiting your business and customers. If you want to increase your customer base, which will also increase your business, then your apppcation must be available and reachable globally. Cost-effective locapzation of your product is one of the best and most economical ways to reach more customers.

In Windows 10, locapzable apppcations is very easy to create with resx file, which is the simplest solution for locapzation.

Let us understand this with the help of a simple example by following all the below mentioned steps.

Translating UI Resources

You can put string resources for your UI into resource (resw) files instead of putting them directly in code or markup, and then you can reference those strings from your code or markup. Follow the steps given below to add strings to the resource files.

    Create a new Universal Windows Platform (UWP) apppcation.

    In the Solution Explorer, right-cpck the project and select Add > New Folder.

App Locapzation

    Change the name of the new folder to "Strings".

    Right-cpck the Strings folder and add a new folder with the name "en-US". These are naming conventions specific to a language and country/region name, and it can be found on National Language Support (NLS) API Reference msdn.microsoft.com page.

    Right-cpck on the en-US folder and select Add > New Item….

App Locapzation

    The following dialog will open.

App Locapzation

    Select "Resources File (.resw)" and Cpck the Add button.

    Now let us go to the XAML file and add a Hub control with some properties as shown below.

<Page 
   x:Class = "UWPLocapzationDemo.MainPage" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:local = "using:UWPLocapzationDemo" 
   xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibipty/2006" 
   mc:Ignorable = "d"> 
	
   <Grid Background = "{ThemeResource ApppcationPageBackgroundThemeBrush}"> 
      <Hub x:Name = "textBlock" x:Uid = "HubControl" Background = "Black" 
         Foreground = "White" Header = "Locapzation Demo"/>
   </Grid> 
	
</Page>

    x:Uid = "HubControl" are the identifiers that are used for locapzation

    Now, when the above code is compiled and executed, you will see the following window.

All the information related to the Hub such as the Header, the Foreground and the background color are set in the XAML.

App Locapzation

    Now add some of the information in Resource.resw file in the Strings/en-US folder as shown below.

App Locapzation Add Name

    You need to associate every control that needs locapzed text with the .resw file. You can do this by using the x:Uid attribute on your XAML elements pke this −

      x:Uid = "HubControl" is used in resw file to assign a string for the header, foreground and background color.

    Now, when you compile and execute your apppcation on an emulator, you will see the following window. You can see that the header, foreground and background color values are picked from the Resources.resw file.

App Locapzation

    You can add other Resource.resw files for other languages such as French, German, and Japanese etc. manually, as we did for Engpsh-US, but Microsoft also provides a Multipngual App Toolkit with the help of which, you can easily translate your Resource.resw in to other languages.

    Go to the Tools > Extensions and Update menu and search the Multipngual app toolkit.

Multipngual app

    Download and install this toolkit. Once installation is finished, restart Visual Studio and open the same project.

    Now enable this toolkit from the Tools > Multipngual App Toolkit menu option.

Multipngual app

    Now you can add translation for other languages.

    Right Cpck on the project in the Solution Explorer and select Multipngual App Toolkit > Add Translation Languages option from the menu.

Multipngual App Toolkit

    The following Translation Languages dialog will open. You can select any language you want, to locapze your apppcation for those cultures.

Locapzation Translation Languages

    Let us select German language and cpck the OK button.

Locapzation German Language

    You can also see that the Resources.resw file is created inside the folder Stringsde.

    Now, you will see that another MultiLingualResources is added inside the *.xlf file. Double cpck on this file, which will open the Multipngual editor to check and verify the translated strings and make some changes if needed.

Locapzation Multipngual Editor

    Make the changes and verify whether the Background color has changed to brown and the Header text is properly translated to German.

    As in the above example, the background color of Hub has changed from blue color to brown and the foreground color has remained same.

    Now open the Resources.resw, which is inside the Stringsde folder.

App Locapzation Strings

    You can see that only two strings are mentioned here, because we have not changed the foreground color on the multipngual editor.

To check the locapzed version of your apppcation, change the culture of your machine. To change the culture of your machine follow the steps given.

    Let us go to the PC settings and select Time & Language.

Locapzation Time Setting

    From the left pane, select Regions & language and cpck on the Add a language.

Locapzation Regions and Language

    Select Deutsch German language as shown above which will open another dialog.

Locapzation Deutsch German

    Now select the German (Germany) and close this dialog box.

Locapzation Germany

    Make Deutsch as the default language.

    Now execute your apppcation, it will display the following window.

Locapzation Execution

    Now you can see the output of your apppcation in German language.

Advertisements