https://github.com/antelcat/i18n
Reactive language support for WPF/Avalonia applications when using .resx file.
https://github.com/antelcat/i18n
avalonia dotnet extension i18n languages localization markup mvvm source-generator wpf
Last synced: 17 days ago
JSON representation
Reactive language support for WPF/Avalonia applications when using .resx file.
- Host: GitHub
- URL: https://github.com/antelcat/i18n
- Owner: Antelcat
- License: mit
- Created: 2023-10-25T15:02:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-01-19T12:15:31.000Z (about 2 months ago)
- Last Synced: 2026-02-24T05:03:23.895Z (23 days ago)
- Topics: avalonia, dotnet, extension, i18n, languages, localization, markup, mvvm, source-generator, wpf
- Language: C#
- Homepage:
- Size: 566 KB
- Stars: 150
- Watchers: 1
- Forks: 16
- Open Issues: 5
-
Metadata Files:
- Readme: README.en.md
- License: LICENSE
Awesome Lists containing this project
README
Antelcat.`{I18N}`
Reactive language support for .NET applications.
---
π¨π³ [δΈζη](./README.md)
## π Supported Platforms
+ [WPF](https://github.com/dotnet/wpf)
+ [Avalonia](https://github.com/AvaloniaUI/Avalonia)
## π Sample
### Static using
When using `.resx` language file in your project, you can
automatically generate resource keys by using `Antelcat.I18N.Attributes.ResourceKeysOfAttribute`:
```csharp
using Antelcat.I18N.Attributes;
namespace MyProject
//Auto generated class should be partial
[ResourceKeysOf(typeof(My.Resource.Designer.Type))]
public partial class LangKeys;
```
Then in your `.xaml` file you can use `x:Static` to provide resource key to your control
+ on `Avalonia` platform and using greater than the version of 2.0.0, you should call in `App.axaml`
```csharp
LangKeys.Your_Provider.Initialize();
```
`WPF` can ignore this procedure
if you already have
```xml
Language
```
in your `.resx` file, you can use it like this:
```xaml
```
Then you can use the key to bind the language source using `I18N`
```xaml
```
When you want to change the language, just call
```csharp
using System.Windows;
I18NExtension.Culture = new CultureInfo("language code");
```
You can see the text is changing among the languages.
---
### Dynamic using
Sometimes your source text is not defined in your application but received from other source like network, you can use `I18N` to bind the text directly.
If you receive a json like this:
```json
{
"message": "This is a message"
}
```
and you have translated it into another language in `.resx` like
```xml
θΏζ―δΈζ‘ζΆζ―
```
then you put the json into a `Message` property in your view model, you can bind it like this:
```xaml
```
Each time when the `Message` property is changed or the language source is changed, the text will be updated automatically.
---
### Combination and StringFormat
Somebody may want to combine several language sources into one text, you can also use `I18N` and `LanguageBinding` to do this
If you have source text in `.resx` file like this:
```xml
ε½εη {0} ζ― {1}
θ―θ¨
δΈζ
```
and in `.xaml`
```xaml
```
`I18N.Key` is the `string` template, content accepts `LanguageBinding` and `Binding` to provide the args.