Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhaytam/easylocalization
A simple library that makes WPF Localization easier
https://github.com/zhaytam/easylocalization
csharp localization wpf
Last synced: 8 days ago
JSON representation
A simple library that makes WPF Localization easier
- Host: GitHub
- URL: https://github.com/zhaytam/easylocalization
- Owner: zHaytam
- License: mit
- Created: 2018-02-11T14:20:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T00:46:30.000Z (about 2 years ago)
- Last Synced: 2023-03-05T22:28:25.214Z (almost 2 years ago)
- Topics: csharp, localization, wpf
- Language: C#
- Homepage:
- Size: 41 KB
- Stars: 20
- Watchers: 4
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EasyLocalization
A simple library that makes WPF Localization easier.
## Features
- An easy extension to use `{l:Localize Title1}`
- Handles bindable Key `{l:Localize Key={Binding TitleKey}}`
- Handles alternative keys when the Key is not provided or not found (ControlName_PropertyName, e.g. Button1_Content)
- Handles singular, zero and plural values `{l:Localize Key=Sentence1, CountSource={Binding Value}}`
- The zero form is automatically used when the Count value is equal to 0
- The plural form is automatically used when the Count value is greater than 0
- Ability to change the current culture without having to restart the application.## Demo
![Demo GIF](https://i.imgur.com/fEO8Fjp.gif)
## How to use
### Things that you should know
- **EasyLocation** doesn't use resources.resx files (at least for now).
- **EasyLocation** works with cultures to identify languages (`CultureInfo` class)
- There are only 3 types of readers for now:
- CharSeperatedFileReader: Each line is considered to have at least a key and a value seperated by a char (e.g. [en-US.txt](https://github.com/zHaytam/EasyLocalization/blob/master/EasyLocalization.Demo/Resources/en-US.txt))
- JsonFileReader: A json file of a key-object format (e.g. [fr.json](https://github.com/zHaytam/EasyLocalization/blob/master/EasyLocalization.Demo/Resources/fr.json))
- XmlFileReader: A xml file with an `` root and `` elements, each must have a key attribute (e.g. [es-ES.xml](https://github.com/zHaytam/EasyLocalization/blob/master/EasyLocalization.Demo/Resources/es-ES.xml))### Adding cultures (languages)
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.
### Simple localization
### Bindable Key
Since the Key is not provided, the `LocalizationManager` will use the alternative key, in this case it's **LblTitle_Text**.
### Handling singular, zero and plural
The LocalizationManager will adapt the Text property whenever the Key or Count change:
- If the Count value is 0, the `ZeroValue` is chosen.
- If the Count value is 1, the `Value` is chosen.
- Otherwise the PluralValue is chosen `string.Format(PluralValue, Count)`### Changing the culture (language)
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