minimal_localizations
言語ごとの翻訳マップを指定して最小限のローカライズを実現。
言語ごとの翻訳マップをもとに、Flutterアプリをローカライズします。
{"sdk":"flutter"}{"sdk":"flutter"}{"sdk":"flutter"}^6.0.0以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
Localize your Flutter app by providing a map of translations per language, along with methods to retrieve values, strings, and supported locales.
Based on the minimal localization example.
Add minimal_localizations and flutter_localizations as dependencies to your pubspec.yaml.
dependencies:
flutter_localizations:
sdk: flutter
minimal_localizations:
Declare MinimalLocalizationsDelegate given a map of translations per language tag.
Language tags must be valid Unicode BCP47
final minimalLocalizationsDelegate = MinimalLocalizationsDelegate({
'en': {
'title': 'Localizations',
'hello': 'Hello',
},
'nb-NO': {
'title': 'Lokaliseringer',
'hello': 'Hei',
},
});
Add localizationDelegates and set supportedLocales.
MaterialApp(
localizationsDelegates: [
// global delegates
...GlobalMaterialLocalizations.delegates,
// minimal localizations delegate
minimalLocalizationsDelegate,
],
supportedLocales: minimalLocalizationsDelegate.supportedLocales,
}
Add supported languages to ios/Runner/Info.plist as described
here
Example:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb-NO</string>
</array>
Translate dynamic values using
MinimalLocalizations.of(context).value('some_value')
Translate String values using
MinimalLocalizations.of(context).string('Hi')
We keep the API minimal, but you can easily add an extension method to String like this:
extension LocalizedString on String {
String tr(BuildContext context) => MinimalLocalizations.of(context).string(this);
}
So you can translate String values like this:
'Hi'.tr(context)
See example