Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 31 additions & 8 deletions bin/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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';
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -141,8 +155,12 @@ Future<List<FileSystemEntity>> dirContents(Directory dir) {
return completer.future;
}

void generateFile(List<FileSystemEntity> files, Directory outputPath,
GenerateOptions options) async {
void generateFile(
List<FileSystemEntity> files,
Directory outputPath,
GenerateOptions options,
) async {
final className = options.className ?? 'LocaleKeys';
var generatedFile = File(outputPath.path);
if (!generatedFile.existsSync()) {
generatedFile.createSync(recursive: true);
Expand All @@ -155,7 +173,8 @@ void generateFile(List<FileSystemEntity> 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);
Expand All @@ -170,14 +189,18 @@ void generateFile(List<FileSystemEntity> files, Directory outputPath,
stdout.writeln('All done! File generated in ${outputPath.path}');
}

Future _writeKeys(StringBuffer classBuilder, List<FileSystemEntity> files,
bool? skipUnnecessaryKeys) async {
Future _writeKeys(
StringBuffer classBuilder,
List<FileSystemEntity> 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);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down