localization_generator
A command tool to generate localization from JSON file.
Getting Start
Add to your pubspec.yaml
.
dependencies:
intl: ^0.17.0
dev_dependencies:
localization_generator: <last_version>
Add translation files to a folder.
l10n
+- {languageCode}.json
+- {languageCode}-{countryCode}.json
+- {languageCode}-{scriptCode}.json
Run the following command.
flutter pub run localization_generator --output=./l10n --input=./l10n
Configuration app.
// Import the generated localization file.
import 'l10n/localization.dart';
MaterialApp(
onGenerateTitle: (context) {
return Localized.of(context).hello(name: "my name");
},
theme: ThemeData(
primarySwatch: Colors.blue,
),
localizationsDelegates: [
Localized.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: Localized.delegate.supportedLocales,
home: Builder(builder: (context) {
return Column(
children: [
Text(Localized.of(context).hi),
Text(Localized.of(context).price(currency: "TWD")),
Text(Localized.of(context).gender(gender: "female")),
Text(Localized.of(context).reply(count: 0)),
],
);
}),
);
MessageFormat
The message pattern is follow the ICU MessageFormat.
Unsupport
offset
ofplural
- date
- number
Libraries
- dart/list
- dart/string
- exceptions/generate_exception
- exceptions/invalid_argument_exception
- exceptions/invalid_choice_exception
- exceptions/invalid_option_exception
- exceptions/localization_generator_exception
- exceptions/missing_close_curly_exception
- exceptions/missing_keys_exception
- exceptions/missing_open_curly_exception
- exceptions/parser_exception
- exceptions/reach_end_exception
- generator/app_localized_class_generator
- generator/app_localized_file_generator
- generator/generator
- generator/intl_generator
- generator/localization_class_generator
- loader/json_loader
- loader/loader
- main
- parser/icu_parser
- parser/parser
- parser/token