-
Notifications
You must be signed in to change notification settings - Fork 11
How to Add a language
A language implementation involves two files in the following folder structure:
Path | Description |
---|---|
Globalization | Top level folder |
Globalization<lang> | Folder for the language using the five character language name |
Globalization\en-US<lang>-style.xaml | Style changes associated with a language |
Globalization\en-US<lang>.xaml | The language resource file |
In the example, there are three languages:
Path | Description |
---|---|
Globalization | Top level folder |
Globalization\en-US | Five character language name for english |
Globalization\en-US\en-US-style.xaml | Style changes associated with a language |
Globalization\en-US\en-US.xaml | The language resource file |
Globalization\es-ES | Five character language name for spanish |
Globalization\es-ES\es-ES-style.xaml | |
Globalization\es-ES\es-ES.xaml | |
Globalization\he-IL | Five character language name for Hebrew |
Globalization\he-IL\he-IL-style.xaml | Notice that the flowdirection changes as Hebrew is left to right. |
Globalization\he-IL\he-IL.xaml |
To add an additional language file, follow these steps.
Easy way:
- Copy one of the existing language folders.
- Change the folder name to the 5 character ISO name. This means it is the two letter language code followed by a dash then the two letter country code. You can read RFC5646 (http://tools.ietf.org/html/rfc5646) if you want.
Hard way:
-
Add a folder names using the 5 character ISO name as the to the Globalization folder.
-
Manually create the .xaml file.
-
Make the root of the Xaml file GlobalizationResourceDictionary.
-
The Name property must be the 5 character lang, same as the folder.
-
The LinkedStyle attribute is optional. IF you use it, you must be the name of style file minus the .xaml extension.
-
Add a few strings. The x:Key is the localization key. The inner text is what is displayed when the language is selected.
<Globalization:GlobalizationResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:Globalization="clr-namespace:WPFSharp.Globalizer;assembly=WPFSharp.Globalizer" Name="en-US" LinkedStyle="en-US-style" > <sys:String x:Key="MainWindow_Title">WPF Globalization Example (English)</sys:String> <sys:String x:Key="Menu_File">_File</sys:String> <sys:String x:Key="Menu_File_Exit">_Exit</sys:String> </Globalization:GlobalizationResourceDictionary>
-
(Optional) Create a language style file. For this example, create en-us-style.xaml. Whatever you name it, it must be the same name as the LinkedStyle attribute in the .xaml file.
-
Make the root object StyleResourceDictionary.
-
Set the Name attribute. Notces the name is the same as the filename without the extension.
-
Add some styles. This file shouldn't be too big. It should only hold styles changes specific to a language.
<Globalization:StyleResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Globalization="clr-namespace:WPFSharp.Globalizer;assembly=WPFSharp.Globalizer" Name="en-US-style" > <FlowDirection x:Key="FlowDirection_Default">LeftToRight</FlowDirection> <FlowDirection x:Key="FlowDirection_Reverse">RightToLeft</FlowDirection> <Style TargetType="{x:Type Label}"> <Setter Property="Foreground" Value="DarkBlue" /> <Setter Property="Height" Value="Auto" /> <Setter Property="Width" Value="Auto" /> <Setter Property="FontSize" Value="{DynamicResource ResourceKey=CommonFontSize}" /> <Setter Property="Margin" Value="2" /> </Style> </Globalization:StyleResourceDictionary>