easy-localization
The easy-localization preset supports easy_localization for Flutter.
Detection
The preset applies when pubspec.yaml has the dependency easy_localization.
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: ['easy-localization'],
})Locale files
If your config has no resources, the preset uses assets/translations/{locale}.{ext}. The locale can have a country, such as en-US.json. New files use nested keys.
Supported syntax
In Dart files, the preset reads the string and Text extensions, the tr and plural functions, and context.tr and context.plural:
Text('title').tr();
'msg'.tr(namedArgs: {'lang': 'Dart'});
tr('menu.open');
plural('day', 2);
context.tr('gender', gender: 'male');These usages are title, msg, menu.open, day and gender. The generated LocaleKeys constants are not read.
easy_localization keeps plural and gender forms as nested keys. The preset adds the derived keys {key}.zero, {key}.one, {key}.two, {key}.few, {key}.many, {key}.other, {key}.male and {key}.female. For this file, plural('day', 2) uses day.one and day.other, so the unused-key check reports neither:
{
"day": {
"one": "{} day",
"other": "{} days"
}
}Placeholders
Positional braces: {}. Braces: {name}. Linked messages: @:key and @.upper:key.
Extraction templates
| Kinds | Template |
|---|---|
| any | '{key}'.tr() |