You want to write your application for more then one language ?
This post will help you understand how to do it.
Localized application
Localized application is one that is translated into few languages.
There are few things you can localized in your application :
- App Text - buttons, menus, help, ..
- App Description - seen in the marketplace
- App Title - appears in the application list and application title
- Appllication Bar Text - in case you have application bar
It is possible to publish an English application to all markets but localization will attract also non English users.
Localize the App title
The application title appears in the application list :
And in case it is pinned to the application tile :
A. Create a language resource dll project
- On the File menu, point to New and then click Project.
The New Project dialog appears. - In the left pane, click Installed Templates, expand Visual C++ and then click Win32.
- In the list of project types, click Win32 Project.
- In the Name box, type AppResLib.
- In the Location box, enter a location for your project.
For the purposes of this procedure, you can create the AppResLib project anywhere. - Click OK.
The Win32 Application Wizard appears. - In the left pane, click Application Settings.
- Under Application type, select DLL.
- Under Additional options, select Empty project.
- Click Finish.
The new DLL project is created and opens in Visual Studio. - In Solution Explorer, select the new DLL project.
- On the Project menu, click Properties.
The Property Pages dialog appears. - In the left pane, expand Configuration Properties, expand Linker, and then click Advanced.
- Select the No Entry Point property, click the drop-down arrow to the right of the property value, and then click Yes (/NOENTRY).
/NOENTRY prevents the linker from linking a reference to _main into the DLL;this option is required to create a resource-only DLL. - Click OK.
- Save and build the project.
B. Create a language neutral resource string for your application
- In Solution Explorer, select the new DLL project.
- On the Project menu, click Add Resource.
The Add Resource dialog appears. - In the Resource type list, select String Table and then click New.
The resource string table opens. - Create two resource strings with the following properties.
- Save and build the DLL project.
- In Windows Explorer, locate the file AppResLib.dll that you just built.
- Copy the file AppResLib.dll to the directory that contains your Windows Phone application project file.
C. Create the first specific language resource string for your application
- Edit the resource strings, setting the properties as follows.
- Save and build the DLL project.
- In Windows Explorer, locate the file AppResLib.dll that you just built.
- Rename the DLL file to AppResLib.dll.0409.mui.
- Copy the file AppResLib.dll.0409.mui to the directory that contains your Windows Phone application project file.
Repeat the previous procedure, renaming the DLL files using the information in the following table. Each DLL file name has the formatAppResLib.dll.[locale ID].mui.
For a full list of which display languages are supported on which version ofWindows Phone, see Culture and Language Support for Windows Phone. and also
E. Using the localized strings in your app
- In Solution Explorer, select your Windows Phone application project.
- On the Project menu, click Add Existing Item.
The Add Existing Item dialog appears. - Select the AppResLib.dll file and all the AppResLib.dll.*.mui files, and then click Add.
The files are added to your Windows Phone application project. - In Solution Explorer, select the imported DLL files, and in the Properties window, set the Build Action properties to Content.
- In Solution Explorer, expand Properties and then double-click WMAppManifest.xml.
- Modify the WMAppManifest.xml file to use the AppTitle resource string from the satellite DLLs for the application title used in the application list. The code is highlighted in the following (you need to change only "Title") :
<App xmlns="" ProductID="{product id}" Title="@AppResLib.dll,-100" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="author" Description="description" Publisher="publisher">
- Modify the WMAppManifest.xml file to use the AppTileString resource string from the satellite DLLs for the application title used in the application Tile. The code is highlighted in the following (you need to change only "Title") :
<PrimaryToken TokenID="WindowsPhoneApplicationToken" TaskName="_default"> <TemplateType5> <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI> <Count>0</Count> <Title>@AppResLib.dll,-200</Title> </TemplateType5> </PrimaryToken>
- Save and build the Windows Phone application.
F. Test the localized title
- On the Debug menu, click Start debugging.
The application opens in the emulator. - Click the Start button, and then click the arrow icon.
The application list appears. - Click and hold your application title until the context menu appears, and then click pin to start.
- Click the Start button, and then click the arrow icon.
The application list appears. - Click Settings, and then click region & language.
The settings appear. - Click Display language and then click one of the languages.
You automatically return to the region & language settings page. - Click Tap here to accept changes and restart your phone.
The emulator changes the setting, and returns to the Start screen.Verify that the language of the title that appears on the application Tile matches the language setting that you selected. - Click the arrow icon.
The application list appears.Verify that the language of the title that appears on the application Tile matches the language setting that you selected. - Repeat the above steps to test the other language resource strings that you created.
The placement of each UI element on the screen remains the same regardless of thedisplay language. Note the placement of UI items in your primary language so thatyou can easily change between display languages.
Source Sample
Localization_NK.zip
This sample support three languages : English , Spanish and Frances.
Each language has a matching file :
English - change AppTitle\AppTileString to Localization in AppResLib.dll.0409.mui
Spanish - change AppTitle\AppTileString to localización in AppResLib.dll.0c0a.mui
Frances - change AppTitle\AppTileString to localisation in AppResLib.dll.040c.mui
Do not forget to add these files to the project and changes their "Build Action" property to Content
Under Setting -> region + language ->Display Language change to Espanol
The application list has changed to :
Same goes for application tile :
Localize the App text
Specify the Natural Language
The natural language is set according to the language you have chosen downloading the SDK:
Now every new Windows Phone application default language will be the same.
You can change the default language via the Project_>Properties->Assembly Information->Neutral Language
Create Resource File for Each Language
A. Adding resource files to a project and enabling localization support
All localizable resources should be moved to a resource file.
- Add a resource file for the default language of your application.
- Open the project in Visual Studio.
- Add a resource file. In Solution Explorer, right-click on the project name, click Add and click New Item.
- In the Add New Item dialog box, choose Resources File and re-name the file if desired. For example, you could re-name the file as AppResources.resx. This file will contain the resources for the default language for the application.
- Identify strings in your application and add them to the resource file. You can input a name, a value, and an optional comment for each string.
- The name must be unique. Make it as descriptive as possible.
- The value is the string that will be displayed to the user in the application.
- The comment is optional, but it is helpful for translators, especially in large resource files with many strings.
- Add a resource file for each additional language that the application will support. Each resource file must contain the correct culture/language name, as described in Culture and Language Support for Windows Phone.
For example:- For the culture Spanish (Spain), use AppResources.es-ES.resx.
- For the culture German (Germany), use AppResources.de-DE.resx.
You need to complete this step only for additional languages. For example,if your default language is English (United States) and you have added thestrings for that language into the default language resource file,you should not create an additional resource file for "en-US." - Define the default culture that the application will support:
By default, the Neutral Language is set to the default culture in Visual Studio.If your application targets a different culture than the default culture inVisual Studio, you will need to complete the following steps.If you are not targeting a different culture, verify withthe following steps that the correct Neutral Language is set.- In Solution Explorer, right-click the project name, and click Properties.
- Under the Application tab, click the Assembly Information button.
- In the Neutral Language list, select the default culture. This identifies the language of the strings in the default resources file. For example, if the default resources file is named AppResources.resx, and the strings in that file are English (United States) language strings, you would select English (United States) as the Neutral Language for the project.
- Close the project and open the project file (<project name>.csproj) in a text editor. Locate the <SupportedCultures> tag and add the names of each additional culture (language) your application needs to support. You should have an entry for each .resx file added to the project).
Separate the language names using a semicolon, and only add the additional culture names. For example, if an application uses English (United States) for its default culture, but the application also supports German (Germany) and Spanish (Spain), you would update this tag as follows:<SupportedCultures>de-DE;es-ES;</SupportedCultures>
B. Replacing hard-coded strings with strings in a resource file
Re-open the project to replace the hard-coded strings with strings in a resource file.
- In Solution Explorer, open a resource file and select Public from the AccessModifier list box at the top of the pane. Repeat this step for each resource file in your project.
- Define a class with a property that points to the resources
- Open your App.xaml file and update <Application.Resources> section
- Perform binding from code to the resource
- Build your application – it will now build as a multilingual application and display a user interface according to the language settings of the phone.
Source Sample
Localization_NK.zip
This sample support three languages : English , Spanish and Frances.
It has one button with Click text which is supported in these 3 languages
Following step A - Adding resource files to a project and enabling localization support and B.1 we end up with three files :
AppResources.resx - the default English language
AppResources.fr-FR.resx - the French language file
AppResources.es-ES.resx - the Spanish language file
Notice the update to the project to reflect supported languages
Now we continues with B - Replacing hard-coded strings with strings in a resource file
Define a class LocalizedStrings.cs
This class actually provide access to class AppResources which was created when AppResources.resx was created. It should not come as surprise that class AppResources has the following property :
Add a resource type LocalizedStrings to App.xaml as follows :
Add a Click Button and bind it to the strClick
Run the application to produce :
Now change the display language to Espaniol , after complete boot and running the application :
The text matches espaniol
Localize the Application Bar
This is done using the same resource file used for localizing Text, however binding is not possible sience Application Bar is not Silverlight control.
Source Sample
Localization_NK.zip
The sample add application bar with one button and one menu item.
Add ApplicarionBarButtonText and ApplicarionBarMenuItemText strings to :
- AppResources.resx
- AppResources.fr-FR.resx
- AppResources.es-ES.resx
MainPage.xaml.cs
MainPage.xaml
Change IsVisible to True
Run the application to produce :
Now change the display language to Espaniol , after complete boot and running the application produces :
Localize the App description
Once you have finish creating your application you submit it to App Hub. App hub detect which languages you support (via the SupportedCultures tag which you have updated) and will prompt you to enter a description for every languages which you support :
Make sure the description language match the supported language
Globalized application
A globalized application displays e.g. dates and money in a way that is familiar to the user. E.g. some countries uses $ other uses Euro.
Globalization of your application can be done via the class CultureInfo.
Source sample
Globalization_NK.zip
The application displays :
- Culture
- Date
- Currency
MainPage.xaml
MainPage.xaml.cs
Run the application to produce :
Now change the display language to Espaniol , after complete boot and running the application produces :
Notice the change in all fields.
Note that once the user has changed the display language the date format is changed automatically. The currency on the other hand should be taken from CultureInfo
Nathan
No comments:
Post a Comment