Provides ability to translate Json files to localized texts in a variety of languages. Run time localization for Flutter|Dart applications.
How to use:
- import the package
import 'package:localaze/localaze.dart';
- Create a map of localized texts, or use json you fetched from the server.
final targetMap1 = <String, Map<String, String>>{
'en': {
'info_message': 'My name is {name} and I am {age} years old',
},
'az': {
'info_message': 'Mənim adım {name} və mən {age} yaşındayam',
},
};
- Set configuration and initialize the Localaze instance.
Translator.config = Translator.config.copyWith(
translations: targetMap1,
supportedLanguages: {'en', 'az'},
translationsStructure: TranslationsStructureEnum.languageCodeFirst,
);
- Set params for dynamic translations.
ParamModel name(String value) => ParamModel(key: 'name', value: value);
ParamModel age(int value) => ParamModel(key: 'age', value: "$value");
- Use the
tr
extension method to get the localized text.
print(Translator.translate('welcome_message', 'az', name('John'), age(23)));