Translate plugin to generate translate json file
Detect translate function end with .tr or .trf
ex.
"hello".tr
"hello {}".trf(args: ["Jhon"])- Generate Json file
flutter pub run translate_plugin-
Option
- --t call translate after generate json
- --api-key={KEY} google translate api-key if you not define in yml
-
Config add to pubspec.yml
translate_plugin:
path: assets/translations // output path
api-key: // for auto translate from google translate
skip-translate: // for skip some language when auto translate
plugin:
path: lib/localization // generate plugin output path
name:
file: translate_plugin // file name
class: TranslatePlugin // class name
langs: // support locale
- en-US
- th-TH
- ms-MS
- zh-ZH
default: en-US
onlyLanguageCode: true // use only language code
extension: false // use generate extension ex "hello".tr- Generate Utilclass
abstract class TranslatePlugin {
static const supportLocales = [
Locale("en", "US"),
Locale("th", "TH"),
Locale("ms", "MS"),
Locale("zh", "ZH"),
];
static const defaultLocales = Locale("en", "US");
static const path = "assets/translations";
}- Basic Use with EasyLocalization
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: TranslatePlugin.supportLocales,
path: TranslatePlugin.path,
fallbackLocale: TranslatePlugin.defaultLocales,
useFallbackTranslations: true,
child: const MyApp(),
),
);
}