JSON translations package for Flutter applications.
- Use JSON file to translate your application
flutter pub add json_translation
See example.
Add a JSON file per language you support in the locales path
and describe it in your pubspec.yaml
flutter:
assets:
- locales/
Use one JSON file/object per language to represent the key:String
/value:String
pairs for the localization of your application.
The JSON file name must match exactly with a language code described in supportedLocales
.
lib/
locales/
en.json
fr.json
// en.json
{
"hello-world": "Hello World."
}
// fr.json
{
"hello-world": "Bonjour à tous."
}
Add JsonTranslation.delegate
in the localizationsDelegates
of your MaterialApp
MaterialApp(
localizationsDelegates: const [
JsonTranslation.delegate,
...GlobalMaterialLocalizations.delegates,
],
supportedLocales: const [
Locale('en'),
Locale('fr'),
],
);
Use the $()
function translate keywords
import 'package:json_translation/json_translation.dart';
Container(
child: Text($("hello-world"))
)
You have a lot of options to contribute to this project ! You can :