flutter_l10n Free
A Mason brick for generating a Flutter localization package using Slang v4, with type-safe translations, per-feature l10n support, and Indonesian pluralization.
Version: 2.0.0
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | MyApp | Application name for package naming |
| prefix | string | App | Prefix for generated locale enum (e.g. AppLocale) |
| isForMonorepo | boolean | true | Whether this package will be part of a monorepo structure |
Usage
Interactive
bash
archipelago generate flutter_l10nNon-interactive (CI)
bash
archipelago generate flutter_l10n --config my_config.jsonConfig Template
json
{
"@appName": "Application name for package naming",
"appName": "MyApp",
"@prefix": "Prefix for generated locale enum",
"prefix": "App",
"@isForMonorepo": "Whether this package will be part of a monorepo structure",
"isForMonorepo": true
}Generated Structure
shared/
└── locale_core/
├── l10n/ # Translation source files
│ ├── general/
│ │ ├── general_en.i18n.json # English translations
│ │ └── general_id.i18n.json # Indonesian translations
│ └── feedback/
│ ├── dialog_en.i18n.json
│ ├── error_en.i18n.json
│ └── success_en.i18n.json
├── lib/
│ ├── locale_core.dart # Barrel (re-exports slang_flutter + translations)
│ └── src/
│ ├── translations/
│ │ └── translations.g.dart # Generated by slang
│ └── utils/
│ ├── extensions.dart # Locale-aware formatting
│ ├── resolver.dart # Indonesian pluralization rules
│ └── utils.dart # Barrel export
├── slang.yaml # Slang configuration
├── build.yaml # build_runner config (sources: l10n/**)
├── pubspec.yaml
└── README.mdKey Features
- Slang v4 — Type-safe, compile-time checked translations with namespace support
- Dual generation —
dart run slang(standalone) or viaslang_build_runnerwithbuild_runner - Namespaces — Organize translations by domain (general, feedback, etc.)
- Indonesian support — Custom pluralization resolver for Bahasa Indonesia
- Per-feature l10n — Feature modules (auth, home) can have their own
slang.yamlwith scoped translations (e.g.context.authL10n)
Slang Configuration
The slang.yaml configures how translations are generated:
yaml
base_locale: en
enum_name: AppLocale # Generated from prefix variable
class_name: Translations
translate_var: l10n # Access via context.l10n
input_directory: l10n
output_directory: lib/src/translations
namespaces: true
flutter_integration: truePer-Feature Translations
Feature modules can have their own translations. Each feature gets its own slang.yaml:
yaml
# features/auth/auth_impl/slang.yaml
translate_var: authL10n # context.authL10n
enum_name: AuthLocale
class_name: AuthTranslationsShell pages sync the global locale to feature-scoped translations:
dart
final authLocale = AuthLocale.values.firstWhere(
(l) => l.languageTag == locale.languageTag,
orElse: () => AuthLocale.en,
);
await LocaleSettings.setLocale(authLocale);Dependencies
slang^4.14.0 — Core translation engineslang_flutter^4.14.0 — Flutter integration (TranslationProvider,LocaleSettings)slang_build_runner^4.14.0 (dev) — build_runner integration
Build Configuration
The build.yaml must include sources: ["l10n/**"] so build_runner can find translation files outside lib/:
yaml
targets:
$default:
sources:
- "l10n/**"
- "lib/**"
builders:
slang_build_runner:
options:
input_directory: l10n
output_directory: lib/src/translations