Simple type safe translations for Avalonia
- Change language at runtime (obviously - but hard with ResX)
- Translation keys are generated at compile time. Missing keys (from the invariant) will show up as compiler errors.
- Markup extension for simple usage
- Simple translation file format based on TOML
- Multiple translation files, so you can split translations by feature, ..
It's best to take a look at the Sample Project
Add references to the following packages:
<PackageReference Include="Echoes" Version=".."/>
<PackageReference Include="Echoes.Generator" Version=".."/>
Specify translations files (Embedded Resources, Source Generator)
<ItemGroup>
<!-- Include all .toml files as embedded resources (so we can dynamically load them at runtime) -->
<EmbeddedResource Include="**\*.toml" />
<!-- Specify invariant files that are fed into the generator (Echoes.Generator) -->
<AdditionalFiles Include="Translations\Strings.toml" />
</ItemGroup>
Caution
You currently have to place your translation (.toml) files and the generated code in a separate project. This is because Avalonia also generates code using their XAML compiler. In order for the xaml compiler to see your translations you need to put them in a different project. Otherwise you'll get a compiler error.
Translations are loaded from .toml
files. The invariant file is special as it's structure included configuration data.
Language files are identified by _{lang}.toml
postfix.
Strings.toml
Strings_de.toml
Strings_es.toml
You can split translations in multiple toml files.
FeatureA.toml
FeatureA_de.toml
FeatureA_es.toml
FeatureB.toml
FeatureB_de.toml
FeatureB_es.toml
[echoes_config]
generated_class_name = "Strings"
generated_namespace = "Echoes.SampleApp.Translations"
[translations]
hello_world = 'Hello World'
greeting = 'Hello {0}, how are you?'
hello_world = 'Hallo Welt'
greeting = 'Hallo {0}, wie geht es dir?'
No, it's currently in preview. See the version number.
The library is named after the Pink Floyd song Echoes.