fast_i18n 1.2.0+1 copy "fast_i18n: ^1.2.0+1" to clipboard
fast_i18n: ^1.2.0+1 copied to clipboard

discontinuedreplaced by: slang
outdated

Lightweight i18n solution. Use JSON files to create typesafe translations.

example/README.md

Example #

Step 1: Add dependencies #

dependencies:
  fast_i18n: ^1.2.0

dev_dependencies:
  build_runner: any

Step 2: Create JSON files #

Create these files inside your lib directory. Preferably in one common package like lib/i18n.

strings.i18n.json

{
  "hello": "Hello $name",
  "save": "Save",
  "login": {
    "success": "Logged in successfully",
    "fail": "Logged in failed"
  }
}

strings_de.i18n.json

{
  "hello": "Hallo $name",
  "save": "Speichern",
  "login": {
    "success": "Login erfolgreich",
    "fail": "Login fehlgeschlagen"
  }
}

Step 3: Generate the dart code #

flutter packages pub run build_runner build

Step 4: Initialize #

@override
void initState() {
  super.initState();

  // a: use device locale
  LocaleSettings.useDeviceLocale().whenComplete(() {
    setState((){});
  });

  // b: use specific locale
  LocaleSettings.setLocale('de');

  // c: use default locale (default json locale)
  // *do nothing*
}

Step 4b: iOS-only #

File: ios/Runner/Info.plist

<key>CFBundleLocalizations</key>
<array>
   <string>en</string>
   <string>de</string>
</array>

Step 5: Use your translations #

// raw string
String translated = t.hello(name: 'Tom');

// inside component
Text(t.login.success)

Useful functions #

When the dart code has been generated, you will see some useful classes and functions

t - the most important translate variable

LocaleSettings.useDeviceLocale() - use the locale of the device

LocaleSettings.setLocale('de') - change the locale

LocaleSettings.currentLocale - get the current locale

132
likes
0
points
2.86k
downloads

Publisher

verified publishertienisto.com

Weekly Downloads

Lightweight i18n solution. Use JSON files to create typesafe translations.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

build, devicelocale, flutter, glob

More

Packages that depend on fast_i18n