json_translation 0.1.1 copy "json_translation: ^0.1.1" to clipboard
json_translation: ^0.1.1 copied to clipboard

JSON translations package for Flutter applications.

JSON translations package for Flutter applications.

Features #

  • Use JSON file to translate your application

Getting started #

flutter pub add json_translation

Usage #

See example.

Add a JSON file per language #

Add a JSON file per language you support in the locales path and describe it in your pubspec.yaml

The locale path must be ./locales
flutter:
  assets:
    - locales/

Use one JSON file/object per language to represent the key:String/value:String pairs for the localization of your application.

Exemple project tree

The JSON file name must match exactly with a language code described in supportedLocales.

lib/
locales/
    en.json
    fr.json
Example JSON file
// en.json
{
	"hello-world": "Hello World."
}

// fr.json
{
	"hello-world": "Bonjour à tous."
}
Exemple MaterialApp

Add JsonTranslation.delegate in the localizationsDelegates of your MaterialApp

MaterialApp(
    localizationsDelegates: const [
        JsonTranslation.delegate,
        ...GlobalMaterialLocalizations.delegates,
    ],
    supportedLocales: const [
        Locale('en'),
        Locale('fr'),
    ],
);
Exemple

Use the $() function translate keywords

import 'package:json_translation/json_translation.dart';

Container(
    child: Text($("hello-world"))
)

Contributing #

You have a lot of options to contribute to this project ! You can :

2
likes
130
pub points
0%
popularity

Publisher

verified publisherlouismidson.me

JSON translations package for Flutter applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, intl, plugin_platform_interface

More

Packages that depend on json_translation