WPF globalization and localization, and WPF globalization Localization
When an App needs to launch a multi-language version, it needs to use the [Globalization and localization] service.
PrincipleAndProcess
The resource file contains all the control information. By exporting the control information, you can modify the string of its corresponding attributes (such as the Text attribute of TextBlock) to implement a multi-language version. In the resource file, the control is marked by x: uid.
To internationalize WPF, follow these steps:
1. in *. add the language/localization information to the csproj. After the project is regenerated, the en-US directory is displayed under the bin directory, which contains the en-US localized resource information *. resources. dll.
Add <UICulture> en-US </UICulture> under <PropertyGroup> in the * p. csproj file.
Enable [assembly: NeutralResourcesLanguage ("en-US", UltimateResourceFallbackLocation. Satellite)] In AssemblyInfo. cs.
Regenerate the project.
2. Add and check the uid.
Automatically add UID msbuild/t: updateuid HelloApp. csproj to XAML
To verify that you do not have a missing or duplicate UID, runCheckuid: Msbuild/t: checkuid HelloApp. csproj
3. Extract, modify, and re-generate the source file (dll)
Tool: You can use Microsoft's non-production tool LocBaml.exe or other visualization tools. For example, Visual LocBaml.
Extraction: LocBaml.exe/parse en-US/HelloApp. resources. dll/out: Hello.csv
Generate: LocBaml.exe/generate en-US/HelloApp. resources. dll/trans: Hello.csv/out:. \/cul: zh-CN
4. Change the program run to cultrue.
Modify the Operating System Language/region.
You can also set parameters in the dynamic setting area of the App. (You need to restart the App)
Var lan = HelloApp. Properties. Settings. Default ["Language"] as string;
Var cultrue = new CultureInfo (lan );
CurrentThread. CurrentCulture = cultrue;
CurrentThread. CurrentUICulture = cultrue;
There are several other ways to dynamically change the language environment, but the above methods have the following advantages:
- The source program does not need to care about multiple languages. For example, the dynamic binding Based on. xaml, the dynamic binding of XMAL or the resource (k, v) all restrict the language types that can be translated at the development level.
- Translation can be performed after the program is developed.
- After the UI is determined, it can be outsourced to the translation team for parallel operations.
And ....
This is just a simple text translation. It also includes usage habits, formatting features, and many other interesting content.
Refer:
How to: localize applications, https://msdn.microsoft.com/zh-cn/library/ms746621.aspx