yaml_localizations 0.1.0 copy "yaml_localizations: ^0.1.0" to clipboard
yaml_localizations: ^0.1.0 copied to clipboard

outdated

A minimal YAML localization package for Flutter built on LocalizationsDelegate.

yaml_localizations #

A minimal YAML localization package for Flutter.

Usage #

See example.

Install #

Add to your pubspec.yaml

dependencies:
  yaml_localizations:

Add YAML asset file per language #

Add a YAML file per language you support in an asset path and describe it in your pubspec.yaml

flutter:
  assets:
    - {path}/{languageCode}.yaml

MaterialApp #

Add YamlLocalizationsDelegate to MaterialApp and set supportedLocales using language codes.

MaterialApp(
  localizationsDelegates: [
    ... // global delegates
    YamlLocalizationsDelegate(
      YamlLocalizations(
        assetPath: 'yaml_translations',
        supportedLanguageCodes: [ 'en', 'nb', ],
      ),
    ),
  ],
  supportedLocales: [ Locale('en'), Locale('nb'), ],
}

API #

Translate strings using

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

We keep the API simple, but you can easily add an extension method tr to String like this:

extension LocalizedString on String {
  String tr(BuildContext context) => YamlLocalizations.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</string>
</array>
2
likes
0
pub points
45%
popularity

Publisher

verified publisherapptakk.com

A minimal YAML localization package for Flutter built on LocalizationsDelegate.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, yaml

More

Packages that depend on yaml_localizations