-
Notifications
You must be signed in to change notification settings - Fork 3
Localization
Lable
< GUIContent
< RAM: Loaded ".lang." dictionaries
< File system: Localization files
-
Label -a control that implements
WpfHandler.UI.Controls.ILabel
interface. -
GUIContent - an instance of the
WpfHandler.UI.GUIContent
class that contains localization code forwarding to resource with localized lable content. - RAM: Loaded ".lang." dictionaries - loaded localization files for a certain culture.
- File system: Localization files - collection of dictionaries for different cultures that contain some localized content.
A xaml dictionaries stored into the \plugins\
directory that contains pairs localization key
-> localized string
.
File's name format: GROUP_NAME.lang.CULTURE_CODE.xaml
-
GROUP_NAME - sequence of any symbols till the
.lang
keyword. The files with the same group name will be overloaded during language changing to the files with the same group's name but the different CULTURE_CODE. -
.lang - the keyword that mark the dictionary as a part of the localization system.
-
CULTURE_CODE - the name of the culture localized into that dictionary. Examples:
en-US
,ru-RU
, etc.
\appFolder | A folder where stored the application.
\plugins | The folder where must be plased all plugins resources.
\vanila | The folder that will contain default dictionaries.
- app.vanila.lang.en-US.xaml | An english localization for the UI element used on the clear app.
\plugin1 | A folder that will contain the files relative to the first plugin.
- plugin1.dll |
- devidQ.plugin1.lang.en-US.xaml | The localiztion of the plugin's UI elements for russian.
- devidQ.plugin1.lang.ru-RU.xaml | The localiztion of the plugin's UI elements for english.
- devidQ.plugin1.lang.zh-CN.xaml | The localiztion of the plugin's UI elements for chinese.
\plugin2 | Folder with resource of the second plugin.
- plugin2.dll | A compiled plugin's dll.
- plugin2.lang.en-US.xaml | The localiztion of the plugin's UI elements for english.
- plugin2.lang.zh-CN.xaml | The localiztion of the plugin's UI elements for chinese.
In that example we will create the button and add a two languages localization for it.
- Adding namspace to get access to WPFH controls.
xmlns:wpfh="clr-namespace:WpfHandler.UI.Controls;assembly=WpfHandler"
- Adding a control with implemented
ILable
interface to aPlane
. Define the name to get access to the control from the code behind. In that example we will use theFlatButton
control.
<wpfh:FlatButton Name="localizedButton"/>
- Creating the GUI content.
- Adding the title that will displayed in case if localization key not found among the loaded.
- Adding the key that will be looking into the loaded dictionaries.
var content = new GUIContent(){
DefaultTitle = "Native title",
TitleLocalizationResourseKey = "localizedLableCustomKey" };
- Binding the content to the button's lable.
content.BindToLable(localizedButton);
- Requesting english
"en-US"
localization as prior and russian"ru-RU"
localization as secondary in case if english one not found. (You can use any culture code available for theCultureInfo
)
LocalizationHandler.LoadDictionaries(
new CultureInfo("en-US"),
new CultureInfo("ru-RU"));
The files stored by dyrecory: APP_FOLDER/plugins/
The full file's name: example.lang.en-US.xaml
.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:System;assembly=mscorlib">
<v:String x:Key="localizedLableCustomKey">Loaded title</v:String>
</ResourceDictionary>
The full file's name: example.lang.ru-RU.xaml
.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:System;assembly=mscorlib">
<v:String x:Key="localizedLableCustomKey">Заголовок</v:String>
</ResourceDictionary>
- Donate: Why support the initiative? | Patreon
- Contacts: LinkedIn
- See also: Doloro Networking Framework | Uniform Data Operator | Datum Point