Skip to content
Efra Espada edited this page Apr 27, 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!"
}

Project Configuration

root
  |
  |_ langs
  |    |_ # obfuscated lang files
  |    
  |_ langs_base
  |    |_ en.json
  |    |_ es.json
  |
  |_ lang_test
       |_ # test revealed lang files

stringcare:
  lang:
    obfuscated: "lang"        # obfuscated langs files directory
    original: "lang_base"     # original langs files directory
    test: "lang_test"         # test reveal langs files directory (only needed for testing)
  resources:
    class_name: "R"           # R class for accessing resources
    class_dir: "lib"          # R class directory

flutter:
  assets:
    - lang/en.json
    - lang/es.json

Run 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:reveal

Code Configuration

Include 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:

import 'package:stringcare/stringcare.dart';
import 'r.dart';

Stringcare.translate(context, R.strings.hello_there)

Retrieve any key with format:

import 'package:stringcare/stringcare.dart';
import 'r.dart';

Stringcare.translate(context, R.strings.hello_format, values: ["Tom"])

If you are working without BuildContext or you want to get a specific language, you can use:

import 'package:stringcare/stringcare.dart';
import 'r.dart';

var value = await Stringcare.translateWithLang("en", R.strings.hello_there);