The Flutter Localization class handles translation dialogs only and the l10n tool only provides for simple localized messages via the arb files you provide. What you want to do instead is use the intl package to get special messages involving gender, plurals, date-number formatting, and bidirectional text.
In short words the intl package supports both use cases of using latin script to internationalize the app or using their native language script through the systemOS provided fonts.
So it is a good idea to make use of the intl package.
The problem is that it has you write on extra class, specifically this one:
class DemoLocalizations { | |
DemoLocalizations(this.localeName); | |
static Future<DemoLocalizations> load(Locale locale) { | |
final String name = | |
locale.countryCode == null || locale.countryCode!.isEmpty | |
? locale.languageCode | |
: locale.toString(); | |
final String localeName = Intl.canonicalizedLocale(name); | |
return initializeMessages(localeName).then((_) { | |
return DemoLocalizations(localeName); | |
}); | |
} | |
static DemoLocalizations of(BuildContext context) { | |
return Localizations.of<DemoLocalizations>(context, DemoLocalizations)!; | |
} | |
final String localeName; | |
String get title { | |
return Intl.message( | |
'Hello World', | |
name: 'title', | |
desc: 'Title for the Demo application', | |
locale: localeName, | |
); | |
} | |
} |
I am going to show you a way to avoid having to write that class by hand.
Keep reading with a 7-day free trial
Subscribe to Fred’s Flutter Newsletter to keep reading this post and get 7 days of free access to the full post archives.