diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bf74e56..c7a0b499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### [3.0.9] + +- Added custom class name option for code generation (`--class-name` or `-c` parameter) + ### [3.0.8] - code audit and maintenance updates @@ -51,9 +55,11 @@ - **BREAKING**: removed context parameter from `plural()` and `tr()` - Added Formatting linked translations [more](https://github.com/aissat/easy_localization#linked-translations) - Updated `plural()` function, with arguments [more](https://github.com/aissat/easy_localization#linked-translations) + ```dart var money = plural('money_args', 10.23, args: ['John', '10.23']) // output: John has 10.23 dollars ``` + - Removed preloader widget ~~`preloaderWidget`~~ - fixed many issues. - customizable logger [EasyLogger] @@ -84,6 +90,7 @@ ```dart context.locale = locale; ``` + :information_source: No breaking changes, you can use old the static method `EasyLocalization.of(context)` ### [2.2.2] diff --git a/README.md b/README.md index 365930a2..ab526341 100644 --- a/README.md +++ b/README.md @@ -475,6 +475,7 @@ Code generation supports only json files, for more information run in terminal ` | --output-dir | -O | lib/generated | Output folder stores for the generated file | | --output-file | -o | codegen_loader.g.dart | Output file name | | --format | -f | json | Support json or keys formats | +| --class-name | -c | LocaleKeys | Custom class name for generated keys class | | --[no-]skip-unnecessary-keys | -u | false | Ignores keys defining nested object except for pluarl(), gender() keywords. | ### 🔌 Localization asset loader class diff --git a/bin/generate.dart b/bin/generate.dart index 7c5cba29..d6a33c7b 100644 --- a/bin/generate.dart +++ b/bin/generate.dart @@ -81,6 +81,14 @@ ArgParser _generateArgParser(GenerateOptions? generateOptions) { help: 'If true - Skip unnecessary keys of nested objects.', ); + parser.addOption( + 'class-name', + abbr: 'c', + defaultsTo: 'LocaleKeys', + callback: (String? x) => generateOptions!.className = x, + help: 'Custom class name for generated keys class (keys format)', + ); + return parser; } @@ -91,11 +99,18 @@ class GenerateOptions { String? outputDir; String? outputFile; String? format; + String? className; bool? skipUnnecessaryKeys; @override String toString() { - return 'format: $format sourceDir: $sourceDir sourceFile: $sourceFile outputDir: $outputDir outputFile: $outputFile skipUnnecessaryKeys: $skipUnnecessaryKeys'; + return 'format: $format ' + 'sourceDir: $sourceDir ' + 'sourceFile: $sourceFile ' + 'outputDir: $outputDir ' + 'outputFile: $outputFile ' + 'skipUnnecessaryKeys: $skipUnnecessaryKeys ' + 'className: $className'; } } @@ -106,7 +121,6 @@ void handleLangFiles(GenerateOptions options) async { final sourcePath = Directory(path.join(current.path, source.path)); final outputPath = Directory(path.join(current.path, output.path, options.outputFile)); - if (!await sourcePath.exists()) { stderr.writeln('Source path does not exist'); return; @@ -141,8 +155,12 @@ Future> dirContents(Directory dir) { return completer.future; } -void generateFile(List files, Directory outputPath, - GenerateOptions options) async { +void generateFile( + List files, + Directory outputPath, + GenerateOptions options, +) async { + final className = options.className ?? 'LocaleKeys'; var generatedFile = File(outputPath.path); if (!generatedFile.existsSync()) { generatedFile.createSync(recursive: true); @@ -155,7 +173,8 @@ void generateFile(List files, Directory outputPath, await _writeJson(classBuilder, files); break; case 'keys': - await _writeKeys(classBuilder, files, options.skipUnnecessaryKeys); + await _writeKeys( + classBuilder, files, options.skipUnnecessaryKeys, className); break; // case 'csv': // await _writeCsv(classBuilder, files); @@ -170,14 +189,18 @@ void generateFile(List files, Directory outputPath, stdout.writeln('All done! File generated in ${outputPath.path}'); } -Future _writeKeys(StringBuffer classBuilder, List files, - bool? skipUnnecessaryKeys) async { +Future _writeKeys( + StringBuffer classBuilder, + List files, + bool? skipUnnecessaryKeys, + String className, +) async { var file = ''' // DO NOT EDIT. This is code generated via package:easy_localization/generate.dart // ignore_for_file: constant_identifier_names -abstract class LocaleKeys { +abstract class $className { '''; final fileData = File(files.first.path); diff --git a/pubspec.yaml b/pubspec.yaml index beed69fe..eaeaa376 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/aissat/easy_localization issue_tracker: https://github.com/aissat/easy_localization/issues # publish_to: none -version: 3.0.8 +version: 3.0.9 environment: sdk: '>=2.12.0 <4.0.0'