# EasyLocalization
A simple library that makes WPF Localization easier.
{l:Localize Title1}
{l:Localize Key={Binding TitleKey}}
{l:Localize Key=Sentence1, CountSource={Binding Value}}
CultureInfo
class)<Entries>
root and <Entry>
elements, each must have a key attribute (e.g. es-ES.xml)On startup (for example in App.xaml.cs) you'll have to register the cultures you want your applications to have:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
LocalizationManager.Instance.AddCulture(
CultureInfo.GetCultureInfo("en-US"),
new CharSeperatedFileReader("Resources/en-US.txt"),
true);
LocalizationManager.Instance.AddCulture(
CultureInfo.GetCultureInfo("es-ES"),
new XmlFileReader("Resources/es-ES.xml"));
LocalizationManager.Instance.AddCulture(
CultureInfo.GetCultureInfo("fr"),
new JsonFileReader("Resources/fr.json"));
}
The true
in the first AddCulture
call tells the LocalizationManager
to choose this language for now.
<TextBlock Margin="4" Text="{_:Localize Key1}" />
<TextBlock Margin="4" Text="{_:Localize Key=Key1_1}" />
<TextBlock Margin="4" Text="{localization:Localize KeySource={Binding Key} />
<TextBlock Margin="4" Name="LblTitle" Text="{localization:Localize}" />
Since the Key is not provided, the LocalizationManager
will use the alternative key, in this case it's LblTitle_Text.
<TextBlock Margin="4"
Text="{localization:Localize KeySource={Binding Key},
CountSource={Binding Value}}" />
The LocalizationManager will adapt the Text property whenever the Key or Count change:
ZeroValue
is chosen.Value
is chosen.string.Format(PluralValue, Count)
LocalizationManager.Instance.CurrentCulture = CultureInfo.GetCultureInfo("fr");
Whenever the CurrentCulture changes, the whole application is automatically updated without the need to restart it.
For a list of the available/added cultures:
LocalizationManager.Instance.AvailableCultures