Skip to content

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

VariableTypeDefaultDescription
appNamestringMyAppApplication name for package naming
prefixstringAppPrefix for generated locale enum (e.g. AppLocale)
isForMonorepobooleantrueWhether this package will be part of a monorepo structure

Usage

Interactive

bash
archipelago generate flutter_l10n

Non-interactive (CI)

bash
archipelago generate flutter_l10n --config my_config.json

Config 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.md

Key Features

  • Slang v4 — Type-safe, compile-time checked translations with namespace support
  • Dual generationdart run slang (standalone) or via slang_build_runner with build_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.yaml with 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: true

Per-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: AuthTranslations

Shell 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 engine
  • slang_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

Built by Banua Coder