Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 26 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 (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-13T04:22:28.000Z (5 months ago)
- Last Synced: 2024-06-23T16:10:38.646Z (5 months ago)
- Topics: avalonia, dotnet, extension, i18n, languages, localization, markup, mvvm, source-generator, wpf
- Language: C#
- Homepage:
- Size: 503 KB
- Stars: 60
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
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
if you already have
```xmlLanguage
```
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.