Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter flutter logo i18n made easy

i18n made easy, for flutter! otherwise basepath/{languagecode}.json

i18n made easy for flutter i18n made easy for flutter

of course, you must declare the subtree in your pubspec.yaml as assets:

flutter:
  assets:
    - {basepath}

the next step consists in the configuration of the localizationsdelegates; to use flutter_i18n, you should configure as follows:

localizationsdelegates: [
        flutteri18ndelegate(usecountrycode, [fallbackfile, basepath]),
        globalmateriallocalizations.delegate,
        globalwidgetslocalizations.delegate
],

the usecountrycode parameter depends on the json configuration:

  • if you used the pattern {languagecode}_{countrycode}, usecountrycode must be true
  • if you used the pattern {languagecode}, usecountrycode must be false

the fallbackfile parameter was introduced with the version 0.1.0 and provide a default language, used when the translation for the current running system is not provided. this should contain the name of a valid json file in assets folder.

the basepath parameter is optionally used to set the base path for translations. if this option is not set, the default path will be assets/flutter_i18n. this path must be the same path as the one defined in your pubspec.yaml.

if there isn’t any translation available for the required key, the same key is returned.

flutter i18n made easy in action

after the configuration steps, the only thing to do is invoke the following method:

flutteri18n.translate(buildcontext, "your.key")

where:

  • buildcontext is the buildcontext instance of the widget
  • your.key is the key to translate

other examples of use:

await flutteri18n.refresh(buildcontext, languagecode, {countrycode});
flutteri18n.plural(buildcontext, "your.key", pluralvalue);

download the full project for this post from the following button

this source is fully free for all time

download as zip


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top