flutter-translate

The preset for flutter_translate. It reads translate() and translatePlural() calls in Dart and nested plural keys.

The flutter-translate preset supports flutter_translate.

Detection

The preset applies when pubspec.yaml has the dependency flutter_translate.

x18n.config.ts
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:

lib/main.dart
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

KindsTemplate
anytranslate('{key}')