Last updated:
0 purchases
minimal localizations
minimal_localizations #
Localize your Flutter app given a Map of translations per language.
It's based on the minimal localization example, but lets you pass a map of translations in the constructor.
We've also added methods to get a value, a string or a list of supportedLocales.
Features #
Ideal for small projects
Easy to use without code generation
No need for assets, just pure code
Fast performance without asset parsing
Supports both String and dynamic types
Automatically generates supported locales
No external dependencies
Install #
Add minimal_localizations and flutter_localizations as dependencies to your pubspec.yaml.
dependencies:
flutter_localizations:
sdk: flutter
minimal_localizations:
copied to clipboard
Add translations-per-language Map to MaterialApp #
Declare a MinimalLocalizationsDelegate variable given a map of translations per language tag.
The language tag must be a valid Unicode BCP47. See https://www.unicode.org/reports/tr35/ for details.
final minimalLocalizationsDelegate = MinimalLocalizationsDelegate({
'en': {
'title': 'Localizations',
'hello': 'Hello',
},
'nb-NO': {
'title': 'Lokaliseringer',
'hello': 'Hei',
},
});
copied to clipboard
Add it to MaterialApp and call supportedLocales.
MaterialApp(
localizationsDelegates: [
...GlobalMaterialLocalizations.delegates,
minimalLocalizationsDelegate,
],
supportedLocales: minimalLocalizationsDelegate.supportedLocales(),
}
copied to clipboard
Note on iOS #
Add supported languages to ios/Runner/Info.plist as described
here.
Example:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb-NO</string>
</array>
copied to clipboard
API #
Translate dynamic values using
MinimalLocalizations.of(context).value('some_value')
copied to clipboard
Translate strings using
MinimalLocalizations.of(context).string('Hi')
copied to clipboard
We keep the API simple, 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);
}
copied to clipboard
So you can translate strings like this:
'Hi'.tr(context)
copied to clipboard
Example #
See example
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.