flutter-translate
The flutter-translate preset supports flutter_translate.
Detection
The preset applies when pubspec.yaml has the dependency flutter_translate.
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: ['flutter-translate'],
})Locale files
If your config has no resources, the preset uses assets/i18n/{locale}.{ext}. New files use nested keys.
Supported syntax
In Dart files, the preset reads translate and translatePlural:
Text(translate('app_bar.title'));
Text(translatePlural('plural.demo', _counter));These usages are app_bar.title and plural.demo.
flutter_translate keeps plural forms as nested keys. From version 4, the forms are the Intl plural names zero, one, two, few, many and other. Before version 4, they were 0, 1, 2 and else. The preset adds a derived key {key}.{form} for each of these forms, so the unused-key check does not report the forms of a used key.
Placeholders
Braces: {name}. Double braces: {{value}}, the count in plural forms.
Extraction templates
| Kinds | Template |
|---|---|
| any | translate('{key}') |
easy-localization
The preset for easy_localization in Flutter. It reads tr() and plural() calls in Dart, nested plural and gender keys, and {} placeholders.
python-gettext
The preset for gettext in Python, as in Django, Flask-Babel and Babel. It reads .po catalogs, gettext calls and Django translate tags.