Last updated:
0 purchases
getx multilang generator
getx_multilang_generator is used to facilitate the automatic generation/modification of code in developing multilanguage features that utilize the getX framework.
Features #
There are two features in this package, namely generating translation files from .csv and modifying the code to replace all occurrences of the 'string'.tr format with MultiLangKeys.string.tr.
Getting started #
Add Get to your pubspec.yaml file:
dev_dependencies:
getx_multilang_generator:
copied to clipboard
Usage #
Generate translation from .csv
Run command:
flutter pub run getx_multilang_generator import-csv
copied to clipboard
or
flutter pub run getx_multilang_generator import-csv folder/file.csv
copied to clipboard
The command will generate translation files in the form of multilang.dart and multilang_keys.dart in lib/core/translation. The import-csv argument is the name of the command, and the second argument is the location of the .csv file (relative to the project path). The default path for the .csv file is multilang/multilang.csv. Here is an example of multilang.csv:
key,en,id,
add,add,tambah,
warningMessage,there is unexpected error,terjadi kesalahan,
copied to clipboard
Generated multilang.dart:
import 'multilang_keys.dart';
import 'package:peppermint_sdk/peppermint_sdk.dart';
class Multilang extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en': {
MultiLangKeys.add: 'add',
MultiLangKeys.warningMessage: 'there is unexpected error',
},
'id': {
MultiLangKeys.add: 'tambah',
MultiLangKeys.warningMessage: 'terjadi kesalahan',
},
};
}
copied to clipboard
Generated multilang_keys.dart:
class MultiLangKeys {
MultiLangKeys._();
static const String add = 'add';
static const String warningMessage = 'warningMessage';
}
copied to clipboard
Change 'string'.tr format to MultiLangKeys.string.tr
Run command:
flutter pub run getx_multilang_generator convert-tr
copied to clipboard
or
flutter pub run getx_multilang_generator convert-tr my_project/core/translation/multilang_keys.dart
copied to clipboard
This command will replace all occurrences of the 'string'.tr format with MultiLangKeys.string.tr. The convert-tr argument is the name of the command, and the second argument is the path of the multilang_keys.dart file. Here is example of changing:
'add'.tr -> MultiLangKeys.add.tr
'warning'.tr -> MultiLangKeys.warning.tr
Additional information #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.