Localization
Internationalization and translations for E-Core
Localization
The Localization package provides multi-language support with easy translation management.
Overview
e_core_localization includes:
- Translation Files - ARB-based translations
- Locale Switching - Runtime locale changes
- Pluralization - Plural and gender forms
- Date/Number Formatting - Locale-aware formatting
Installation
dependencies:
e_core_localization: ^1.0.0Key Features
Setup
MaterialApp(
localizationsDelegates: ELocalizations.delegates,
supportedLocales: ELocalizations.supportedLocales,
locale: ref.watch(localeProvider),
// ...
)Using Translations
// Access translations
final l10n = context.l10n;
// Use translations
Text(l10n.welcomeMessage);
Text(l10n.itemCount(5)); // PluralizedLocale Switching
// Provider for locale
final localeProvider = StateProvider<Locale>((ref) {
return const Locale('en');
});
// Change locale
ref.read(localeProvider.notifier).state = const Locale('es');Adding Translations
Create ARB files in lib/l10n/:
{
"@@locale": "en",
"welcomeMessage": "Welcome!",
"itemCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}"
}