To improve performance and avoid runtime file loading, you can use code generation to create a CodegenLoader. This supports only .json files.
- Run the generation command in your project root:
flutter pub run easy_localization:generate - Import the generated file and use
CodegenLoader() in your EasyLocalization widget configuration.
CLI Arguments for generation:
| Argument | Short | Default | Description |
|---|
--help | -h | | Help info |
--source-dir | -S | resources/langs | Folder containing localization files |
--source-file | -s | First file | File to use for localization |
--output-dir | -O | lib/generated | Output folder for the generated file |
--output-file | -o | codegen_loader.g.dart | Output file name |
--format | -f | json | Support json or keys formats |
--[no-]skip-unnecessary-keys | -u | false | Ignores keys defining nested objects except for plural() and gender() keywords |
import 'generated/codegen_loader.g.dart';
void main() {
runApp(EasyLocalization(
child: MyApp(),
supportedLocales: [Locale('en', 'US'), Locale('ar', 'DZ')],
path: 'resources/langs',
assetLoader: CodegenLoader(),
));
}