-
Notifications
You must be signed in to change notification settings - Fork 5
i18n
Efra Espada edited this page Apr 26, 2021
·
14 revisions
Stringcare can obfuscate your language files. Include any language you need:
en.json
{
"hello_there": "Hello there!",
"hello_format": "Hello $1!"
}es.json
{
"hello_there": "¿Qué tal?",
"hello_format": "Hola $1!"
}root
|
|_ langs
| |_ # obfuscated lang files
|
|_ langs_base
| |_ en.json
| |_ es.json
|
|_ lang_test
|_ # test revealed lang files
stringcare:
lang_path: "lang" # obfuscated langs path
lang_base_path: "lang_base" # original langs path
lang_reveal_test_path: "lang_test". # test reveal langs path (only needed for testing)
flutter:
assets:
- lang/en.json
- lang/es.jsonRun this command to generate the obfuscated lang files:
flutter pub run stringcare:obfuscate Once the obfuscated lang files are generated, you can test the reveal:
flutter pub run stringcare:revealInclude the supported languages:
void main() {
Stringcare.supportedLangs = ["en", "es"];
runApp(MyApp());
}@override
Widget build(BuildContext context) {
return new MaterialApp(
supportedLocales: [
Locale('en', 'US'),
Locale('es', 'ES'),
],
localizationsDelegates: Stringcare.delegates,
localeResolutionCallback: Stringcare.localeResolutionCallback,
home: Scaffold(...)
);
}Retrieve any key with:
Stringcare.translate(context, "hello_there")Retrieve any key with format:
Stringcare.translate(context, "hello_format", values: ["Tom"])