cargo-i18n
The cargo-i18n preset supports cargo-i18n with the Fluent system: the i18n-embed and i18n-embed-fl crates.
Detection
The preset applies when Cargo.toml has the dependency i18n-embed-fl or i18n-embed. x18n reads [dependencies], [dev-dependencies], [build-dependencies], [workspace.dependencies] and the target dependency tables. For a renamed dependency, such as fl = { package = "i18n-embed-fl", version = "0.10" }, x18n sees the alias fl and does not detect the preset, so list it.
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: ['cargo-i18n'],
})Locale files
The preset reads i18n.toml in the project root:
fallback_language = "en-US"
[fluent]
assets_dir = "i18n"fallback_language is the source locale. If your config has no resources, the preset uses {assets_dir}/{locale}/*.ftl, so i18n/en-US/my_crate.ftl. Without assets_dir, the folder is i18n.
Supported syntax
In Rust files, the preset reads the fl! macro. The first argument can be the loader, or it can be absent when you use a wrapper macro:
fl!(LANGUAGE_LOADER, "hello-arg", name = "Bob");
fl!(loader, "login", "title");
fl!("hello-world");These usages are hello-arg, login and hello-world. A used message also uses its attributes, so login.title is not unused.
Placeholders
Fluent: { $name }.
Extraction templates
| Kinds | Template |
|---|---|
| any | fl!(LANGUAGE_LOADER, "{key}") |
Limitations
- The gettext system of cargo-i18n (the
tr!macro and.pofiles) is not supported. - x18n reads only the
i18n.tomlin the project root. In a workspace with onei18n.tomlper crate, setresourcesyourself.
dotnet-resx
The preset for .NET. It reads .resx resources, IStringLocalizer lookups in C#, Razor and Blazor, and strongly typed Resources.Key access.
angular-localize
The preset for Angular's built-in i18n with @angular/localize. It reads angular.json, i18n attributes and $localize, with custom or generated ids, and the XLIFF, XMB, JSON and ARB translation files.