Skip to content

Commit

Permalink
[FEATURE] Change generated mapper extension to .mapper.dart (#23)
Browse files Browse the repository at this point in the history
## Description

PS. This fix is aimed to resolve this
[feature-request](#22)

## Please check the following boxes

<!--- Put an `X` in all the boxes that apply: -->

- [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
  • Loading branch information
kwado-tech authored Apr 18, 2024
1 parent 4d401f7 commit 5d8b815
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/git_package_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
64 changes: 16 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions l10n_mapper_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@

* Fixes analysis issues

## 2.1.0 [BREAKING CHANGE]

* Fixes readme issues
* Changed generated file extension to `.mapper.dart`.

64 changes: 16 additions & 48 deletions l10n_mapper_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion l10n_mapper_generator/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion l10n_mapper_generator/lib/l10n_mapper_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Builder l10nMapperBuilder(BuilderOptions options) {
parseL10n: parseL10n,
message: message,
),
generatedExtension: '.g.dart',
generatedExtension: '.mapper.dart',
);
}
2 changes: 1 addition & 1 deletion l10n_mapper_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5d8b815

Please sign in to comment.