Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

Antelcat.`{I18N}`

Reactive language support for .NET applications.


dotnet-version
dotnet-version
csharp-version
nuget

---

πŸ‡¨πŸ‡³ [δΈ­ζ–‡η‰ˆ](./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
```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.