From 5d8b8150cf1d5fd76e515693189c987d1afc0727 Mon Sep 17 00:00:00 2001 From: Christian Chikwado Onwe <47870274+kwado-tech@users.noreply.github.com> Date: Thu, 18 Apr 2024 05:54:40 +0300 Subject: [PATCH] [FEATURE] Change generated mapper extension to `.mapper.dart` (#23) ## Description PS. This fix is aimed to resolve this [feature-request](https://github.com/kwado-tech/l10n_mapper/issues/22) ## Please check the following boxes - [x] Pull Request title is consistent with the implemented feature, fix etc. - [x] I have followed proper descriptive code style and conventions - [x] The code is self-documenting and has no unnecessary comments. I named the functions and variables to clearly describe their purpose. - [ ] I have added Unit Tests and coverage is 70%+ - [x] I have tested and verified this implementation and it works as expected --- .github/workflows/git_package_release.yml | 2 +- README.md | 64 +++++-------------- ...s.g.dart => app_localizations.mapper.dart} | 0 example/lib/main.dart | 2 +- example/pubspec.lock | 2 +- l10n_mapper_generator/CHANGELOG.md | 5 ++ l10n_mapper_generator/README.md | 64 +++++-------------- l10n_mapper_generator/build.yaml | 2 +- .../lib/l10n_mapper_builder.dart | 2 +- l10n_mapper_generator/pubspec.yaml | 2 +- 10 files changed, 43 insertions(+), 102 deletions(-) rename example/lib/localization/gen-l10n/{app_localizations.g.dart => app_localizations.mapper.dart} (100%) diff --git a/.github/workflows/git_package_release.yml b/.github/workflows/git_package_release.yml index 78a1bc3..00da2b9 100644 --- a/.github/workflows/git_package_release.yml +++ b/.github/workflows/git_package_release.yml @@ -9,7 +9,7 @@ env: java_version: 17 flutter_channel: 'stable' ruby_version: '2.7.5' - release_version: '2.0.1' + release_version: '2.1.0' jobs: git_package_release: diff --git a/README.md b/README.md index f6254a6..9a628bf 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ A dart package to support parsing dynamic translation keys (as flutter-localizat **Note: Setup localization using `flutter_localizations` package before proceeding with this and also ensure localization setup is not a synthetic package.** #### Getting started +*`l10n_mapper_generator: >=2.0.0` deprecates the use of [l10n_mapper_annotation](https://pub.dev/packages/l10n_mapper_annotation) as annotation is no longer required to work with `>=2.0.0`* + +#### Install dependencies ```yaml dependencies: @@ -26,6 +29,19 @@ To run `l10n_mapper_generator` in terminal, you should activate/install it as a dart pub global activate l10n_mapper_generator ``` +#### +**Example usage** + +Note: parameters, are parsed as a list of positional arguments which should be in the same order as specified in the translation key-value pair. + +```dart + final applicationName = context.parseL10n('application_name'); // Localization mapper + final depositTimeFrame = context.parseL10n('deposit_timeframe'); // Instant + + // parsing placeholder parameters + final convertBeforeWithdraw = context.parseL10n('convert_before_withdraw', arguments: ['CAD', 'EUR']); // * For withdrawing your CAD you first need to convert it back to EUR +``` + #### Mapper This generates a `app_localizations.g.dart` file provided your project already setup localization. With generated `app_localizations.dart`, utility methods are generated for dynamic localization-keys access by the generator. @@ -150,41 +166,6 @@ NOTE: Given the above configuration setup of `l10n_mapper.json`, the generated t }, ``` #### -Here is a complete structure of the `l10n_mapper.json` file - -```json -{ - "formatterOptions": { - "prefix": "app", - "inputPath": "lib/localization/translations/remote", - "outputPath": "lib/localization/translations/local", - "translations": [ - { - "locale": "ar", - "input": "ar-Arabic.arb", - "output": "ar.arb" - }, - { - "locale": "de", - "input": "de-German.arb", - "output": "de.arb" - }, - { - "locale": "en", - "input": "en-English.arb", - "output": "en.arb" - } - ], - "keyPredicateMatch": { - "-": "_", - ".": "_", - "^": "_", - "(": "_", - ")": "_" - } - } -} -``` Note: For convenience and a cleaner reuseable approach, you can create a shell script (in the projects root directory) to collectively run the above scripts in succession. @@ -262,19 +243,6 @@ class AppLocalizationsMapper { } ``` -#### -**Example usage** - -Note: parameters, are parsed as a list of positional arguments which should be in the same order as specified in the translation key-value pair. - -```dart - final applicationName = context.l10nParser('application_name'); // Localization mapper - final depositTimeFrame = context.l10nParser('deposit_timeframe'); // Instant - - // parsing placeholder parameters - final convertBeforeWithdraw = context.l10nParser('convert_before_withdraw', arguments: ['CAD', 'EUR']); // * For withdrawing your CAD you first need to convert it back to EUR -``` - #### Resources Here is a proposal this package is aimed to resolve - [[Proposal] Access l18n Translations with Dynamic Keys #105672](https://github.com/flutter/flutter/issues/105672) diff --git a/example/lib/localization/gen-l10n/app_localizations.g.dart b/example/lib/localization/gen-l10n/app_localizations.mapper.dart similarity index 100% rename from example/lib/localization/gen-l10n/app_localizations.g.dart rename to example/lib/localization/gen-l10n/app_localizations.mapper.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 6df71a1..054cd83 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,5 @@ import 'package:example/localization/gen-l10n/app_localizations.dart'; -import 'package:example/localization/gen-l10n/app_localizations.g.dart'; +import 'package:example/localization/gen-l10n/app_localizations.mapper.dart'; import 'package:flutter/material.dart'; void main() { diff --git a/example/pubspec.lock b/example/pubspec.lock index 4874176..72f8285 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -302,7 +302,7 @@ packages: path: "../l10n_mapper_generator" relative: true source: path - version: "2.0.1" + version: "2.1.0" leak_tracker: dependency: transitive description: diff --git a/l10n_mapper_generator/CHANGELOG.md b/l10n_mapper_generator/CHANGELOG.md index 71186f1..7c88058 100644 --- a/l10n_mapper_generator/CHANGELOG.md +++ b/l10n_mapper_generator/CHANGELOG.md @@ -37,3 +37,8 @@ * Fixes analysis issues +## 2.1.0 [BREAKING CHANGE] + +* Fixes readme issues +* Changed generated file extension to `.mapper.dart`. + diff --git a/l10n_mapper_generator/README.md b/l10n_mapper_generator/README.md index f6254a6..9a628bf 100644 --- a/l10n_mapper_generator/README.md +++ b/l10n_mapper_generator/README.md @@ -5,6 +5,9 @@ A dart package to support parsing dynamic translation keys (as flutter-localizat **Note: Setup localization using `flutter_localizations` package before proceeding with this and also ensure localization setup is not a synthetic package.** #### Getting started +*`l10n_mapper_generator: >=2.0.0` deprecates the use of [l10n_mapper_annotation](https://pub.dev/packages/l10n_mapper_annotation) as annotation is no longer required to work with `>=2.0.0`* + +#### Install dependencies ```yaml dependencies: @@ -26,6 +29,19 @@ To run `l10n_mapper_generator` in terminal, you should activate/install it as a dart pub global activate l10n_mapper_generator ``` +#### +**Example usage** + +Note: parameters, are parsed as a list of positional arguments which should be in the same order as specified in the translation key-value pair. + +```dart + final applicationName = context.parseL10n('application_name'); // Localization mapper + final depositTimeFrame = context.parseL10n('deposit_timeframe'); // Instant + + // parsing placeholder parameters + final convertBeforeWithdraw = context.parseL10n('convert_before_withdraw', arguments: ['CAD', 'EUR']); // * For withdrawing your CAD you first need to convert it back to EUR +``` + #### Mapper This generates a `app_localizations.g.dart` file provided your project already setup localization. With generated `app_localizations.dart`, utility methods are generated for dynamic localization-keys access by the generator. @@ -150,41 +166,6 @@ NOTE: Given the above configuration setup of `l10n_mapper.json`, the generated t }, ``` #### -Here is a complete structure of the `l10n_mapper.json` file - -```json -{ - "formatterOptions": { - "prefix": "app", - "inputPath": "lib/localization/translations/remote", - "outputPath": "lib/localization/translations/local", - "translations": [ - { - "locale": "ar", - "input": "ar-Arabic.arb", - "output": "ar.arb" - }, - { - "locale": "de", - "input": "de-German.arb", - "output": "de.arb" - }, - { - "locale": "en", - "input": "en-English.arb", - "output": "en.arb" - } - ], - "keyPredicateMatch": { - "-": "_", - ".": "_", - "^": "_", - "(": "_", - ")": "_" - } - } -} -``` Note: For convenience and a cleaner reuseable approach, you can create a shell script (in the projects root directory) to collectively run the above scripts in succession. @@ -262,19 +243,6 @@ class AppLocalizationsMapper { } ``` -#### -**Example usage** - -Note: parameters, are parsed as a list of positional arguments which should be in the same order as specified in the translation key-value pair. - -```dart - final applicationName = context.l10nParser('application_name'); // Localization mapper - final depositTimeFrame = context.l10nParser('deposit_timeframe'); // Instant - - // parsing placeholder parameters - final convertBeforeWithdraw = context.l10nParser('convert_before_withdraw', arguments: ['CAD', 'EUR']); // * For withdrawing your CAD you first need to convert it back to EUR -``` - #### Resources Here is a proposal this package is aimed to resolve - [[Proposal] Access l18n Translations with Dynamic Keys #105672](https://github.com/flutter/flutter/issues/105672) diff --git a/l10n_mapper_generator/build.yaml b/l10n_mapper_generator/build.yaml index adb2bc4..34d817b 100644 --- a/l10n_mapper_generator/build.yaml +++ b/l10n_mapper_generator/build.yaml @@ -2,7 +2,7 @@ builders: l10n_mapper_builder: import: "package:l10n_mapper_generator/l10n_mapper_builder.dart" builder_factories: ["l10nMapperBuilder"] - build_extensions: { ".dart": [".g.dart"] } + build_extensions: { ".dart": [".mapper.dart"] } auto_apply: dependents build_to: source defaults: diff --git a/l10n_mapper_generator/lib/l10n_mapper_builder.dart b/l10n_mapper_generator/lib/l10n_mapper_builder.dart index 7e3c061..a702f8d 100644 --- a/l10n_mapper_generator/lib/l10n_mapper_builder.dart +++ b/l10n_mapper_generator/lib/l10n_mapper_builder.dart @@ -22,6 +22,6 @@ Builder l10nMapperBuilder(BuilderOptions options) { parseL10n: parseL10n, message: message, ), - generatedExtension: '.g.dart', + generatedExtension: '.mapper.dart', ); } diff --git a/l10n_mapper_generator/pubspec.yaml b/l10n_mapper_generator/pubspec.yaml index 42dbacb..24c1917 100644 --- a/l10n_mapper_generator/pubspec.yaml +++ b/l10n_mapper_generator/pubspec.yaml @@ -2,7 +2,7 @@ name: l10n_mapper_generator description: A dart package to generate localization-mapper to support parsing dynamic translation keys (as flutter-localizations package does not yet support this). -version: 2.0.1 +version: 2.1.0 homepage: https://github.com/kwado-tech/l10n_mapper/tree/main/l10n_mapper_generator repository: https://github.com/kwado-tech/l10n_mapper/tree/main/l10n_mapper_generator