minimal_localizations 0.1.0+4 copy "minimal_localizations: ^0.1.0+4" to clipboard
minimal_localizations: ^0.1.0+4 copied to clipboard

outdated

Minimal localization given a map of translations per language.

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 #

  • Great for smaller projects to get started with localization
  • Simple to use (no code gen)
  • Just code (no assets)
  • Supports both String and dynamic type
  • Create supportedLocales automatically
  • No dependencies

Usage #

See example.

Install #

Add to your pubspec.yaml

dependencies:
  minimal_localizations:

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 http://www.unicode.org/reports/tr35/ for details.

final minimalLocalizationsDelegate = MinimalLocalizationsDelegate(
  {
    'en': {'title': 'Localizations'},
    'nb-NO': {'title': 'Lokaliseringer'},
  },
);

Add it to MaterialApp and call supportedLocales.

MaterialApp(
  localizationsDelegates: [
    ...GlobalMaterialLocalizations.delegates,
    minimalLocalizationsDelegate,
  ],
  supportedLocales: minimalLocalizationsDelegate.supportedLocales(),
}

API #

Translate dynamic values using

MinimalLocalizations.of(context).value('some_value')

Translate strings using

MinimalLocalizations.of(context).string('Hi')

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);
}

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>
1
likes
0
pub points
33%
popularity

Publisher

verified publisherapptakk.com

Minimal localization given a map of translations per language.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on minimal_localizations