Chapter 4. Application globalization

Source: Internet
Author: User

If you want to publish your applicationProgramYou may need to prepare different versions for user interfaces in different regions around the world. At least, this should solve the problem of translating text into appropriate languages.UIThe problem of change. You may need a specific appearance to adapt to local cultural customs. Alternatively, you may find that the original appearance does not work properly after translation, because the word length is different. (AlthoughWPFThe appearance system avoids this problem and makes it easier to create a more elastic appearance .)

It is possible to create different versions of your software in different markets. Even so, a more general approach is to create a separate version to adapt to different places by selecting an appropriate resource file at runtime.WPFUnderlying architectureResourceManagerYou can directly use this method.

Microsoft distinguishes localization from globalization. Localization is a process that allows an application to focus on the use of a specific place, by creating resources such as text translation for a specific culture. Globalization is a process that ensures that an application can be localized without compilation. ResourceManager helps us to make our applications global, because the Resources selected by this class at runtime support a separate application version by providing appropriate resources for localization. For more information, see the Microsoft international site http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/vbcon/html/vboriinternationalization. ASP ( http://shrinkster.com/6m9 ).

WhenResourceManagerWhen it is required to obtain the resource stream by name, it must first decide which culture to use. The combination of language and region in culture is typically expressed as a short string. For example,En-USEnglish used in the United States. WhileEn-GBEnglish is used in the UK. The first two letters indicate the language, and the last two letters indicate the region. At the same time, it indicates the language and region because even if the two cultures share one language, there are differences in dialects and idioms. For example, one of the authors of this book comes fromEn-GB, So I like to useColorInsteadColor.

ResourceManagerOfGetstreamMethod to useCultureinfoObject as a parameter. If you want to use the user's final configuration culture, you canThread. currentthreadOfCurrentuicultureObtain a new propertyCultureinfoObject.

Although the executable body often compiles resources into it,ResourceManagerWe will still look for the resources of the specified culture before the embedded resources. Search by cultural name in the subdirectory that contains the application directory. Therefore, if your application runs onFrench-CanadianInFr-caFind a sub-directory namedMyApp. Resources. dllFile, hereMyAppIs the name of an application or component. If it does not existFR. This means that once your translation budget is not extended to generate different versions for all regions around the world using French, you can replace it with a separate set of French resources, it is specially used in French-speaking areas. If these subdirectories do not exist, it will resort to using embedded resources.

TheseResourceManagerSearchedDLLResources are called global compilation resources. The reason for naming is that these resources are all very small resources and are aggregated into a large compilation set.

Note that once you provide a global compilation set, you do not need to provide localized versions of all resources. In this way, the resources embedded in your edited translation set are very good for all resources. For example6-6The application in has an embeddedBMPFileSunset.jpg. Most of the world will have sunset, so you may still need to do special work for the Antarctic and Arctic versions. BasicSunset.jpgIt can be used in most cultures. This will waste space for obtaining copies of the same image for every global resource. Fortunately, this is not a must. If a specific naming resource does not exist in global compilation resources,ResourceManagerWill return to the embedded resources.

You can think of global compilation resources as the difference between only embedded resources and the resources required for the target culture. All common resources are independently stored in the editor-in-chief translation set. The subdirectory of a compilation set in a specific language but not limited to regions (for exampleFRSub-Directories) that contain resources different from those required for a specific language. In addition, sub-directories (suchFr-ca,Fr-fr,Fr-beAnd so on.ResourceManagerInstead of passing throughResourcedictionaryObjects retrieved again)

6.4.1UseXAMLCreate a localized application

BecauseXAMLIs compiled inBamlResource, you can useResourceManagerObtained, localization is an internal feature.WPFApplication UsageXAMLCreate. HoweverVisual Studio 2005And noWPFApplication localization provides internal support, so some manual steps are required.

If you wantXAMLCreateUI, Effective localization generatesXAMLFile.ResourceManagerIt cannot be equal to a singleBamlResources get more detailed resources, therefore, eachBamlResources are neither localized nor non-localized. BecauseXAMLFile and its backgroundCodeEven so, LocalizationBamlResources have the same basic structure as the original version, which is very important. Basically, you can writeXAMLFile to obtain resources, and try to keep the same structure. However, this is a more robust way to ensure consistency.

Instead of creating a group for each cultureXAMLFile, you can write a group of mainXAMLFile. Each form or page has a file like this. You may want to support every kind of deterioration. You can use a tool to generate global compilation resources for a specific culture, including localization resources. You provide a configuration file tool to show how resources should be modified to create a localized version. Figure6-7Explains the entire process.

This is a slightly lengthy process. InWPFIn the latest release version, it is not better improved and integratedVisual Studio 2005. Now, we welcome the prerelease software to this wonderful world.

Figure6-7


First, you must ensure that the projectUITo create a localized application. When writing code, there is no wayVisual Studio 2005So you must use the text editor to edit. CsprojFile. InPropertygroupAddUicultureElement (UicultureIt doesn't matter if the element appears in that part.) set it to the default culture. This culture is the main resource to be created. This will causeVisual Studio 2005For this default culture, all binary resources are put into global compilation resources. Example6-28ShowsXAML.

Example6-28

< Project Defaulttargets = "Build"
Xmlns = "Http://schemas.microsoft.com/developer/msbuild/2003" >
< Propertygroup >

< Uiculture > En-US </ Uiculture >

</ Propertygroup >

Next, you mustAdd tagsXAML.UIDLabel isXAMLA special attribute of the element to display the content to be localized. The local configuration file that contains the local command, useUIDThe attribute displays the modified elements. Example6-29DemonstrateUIDOfTextblock.

Example6-29

< Textblock X: uid = "Textblock_1" > Hello, world </ Textblock >

You can manually add what you want. Or you can use msbuildAutomatically generate them (MsbuildIs a command line tool used to generate a project.Visual Studio 2005The same creation technology is used,MsbuildProvides more control. For example, it allows youUIDGenerateWPFCreate system features ). To automatically addUIDsTo yourXAMLRun the following command:

Msbuild/T: updateuid myproject. csproj

If you have done this, edit yourXAML, You may want to check whether it is repeatedUIDTo terminate a tag, run the following command:

Msbuild/T: checkuid myproject. csproj

Now you can generate this project, or useVisual Studio 2005Command Line executionMsbuildTo pass the project name as a parameter. You will find thatEXEOrDLLAt the same time, your project also adds a global resource in the subdirectory. (This subdirectory will be added to the project.UicultureThe element name must be unique .)

The next step is to create a configuration file to guide the localization process. This file contains all local resources, such as translated strings. You can useLocbamlThe command line tool creates the skeleton of this file. This tool has checkedBamlStream compilation resources. A file is created, and each row of the file is a localized information. You can put translation strings and any required resources into this file.

InWPFIn the current preview version,LocbamlOnlySource codeSo it must be completed before execution. You canWinfx SDKThe code is found in the document. InAveon-Globalization and Localization-How-to topic Section, Find"Localize an application"Title. Here we will provide youLocbaml.

Example6-30Demonstrate how to executeLocbamlGenerate the skeleton of the configuration file.

Example6-30

Locbaml bin \ debug \ en-US \ MyApp. Resources. dll/out: myappresources.csv

This will create a CSVFile. Table6-1DescriptionCSVEach column in the file (in the order of appearance ). To localize a resource, EditValueThis column. (Pay attention to thisCSVThe file does not contain the header row and only depends on the column position .)

Table6-1

column name

description

baml name

Unique Identifier baml stream. This value is displayed as assemblymanifeststreamname: substraemname Format

Resource Key

uniquely identifies localized resources, this value is represented as uid. elementtype. $ property Format

localization Category

an entry from localizationcategory enumeration, indicates the type of content

readable

indicates whether resources are visible during conversion

modifiable

indicates whether the value value can be changed during conversion

comments

localized annotations

Value

Resource Value

Example6-31Shows a row in the configuration file. (Due to the page width, this line is split3).

Example6-31

Helloapp. G. fr-FR.resources: window1.baml,
Textblock_1: system. Windows. Controls. textblock. $ content,
None, true, true, bonjour monde

Once you have converted all the values, you can execute locxaml again.Generate new resourceDLL. You must pass the original resourceDLLPath,CSVFile (including translation) path, a target address, and a target culture, as shown in the following example:6-32.. (Due to the page width, this line is split3).

Example6-32

Locbaml/generate bin \ debug \ en-US \ MyApp. Resources. dll/Trans: myappresource.csv
/Out: bin \ debug \ en-GB/cul: En-GB

This will generate a new global compilation resource in the specified directory, with the selected culture as the goal. (If You Want To generate multiple compilation resources, create a CSV file for each cultureFile, which is executed only once for each fileLocbaml.) If you place the resource compilation result in a subdirectory of the application directory named by culture, this will be automatically obtained at runtime, and the application will execute the selected culture.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.