Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into nested_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Feb 8, 2024
2 parents 34be477 + 17a1239 commit e00e425
Show file tree
Hide file tree
Showing 41 changed files with 1,181 additions and 582 deletions.
5 changes: 2 additions & 3 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# github: [aissat]
# liberapay: aissat
custom: ['https://www.buymeacoffee.com/aissat','https://www.paypal.me/aissatabdo']
custom: ['https://www.buymeacoffee.com/aissat']
ko_fi: aissat
open_collective: flutter_easy_localization
80 changes: 0 additions & 80 deletions .github/workflows/main.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PR Check

on:
workflow_dispatch:
pull_request:

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
secrets: inherit
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release to pub.dev

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
secrets: inherit

publish:
needs: [test]
name: Publish
permissions:
id-token: write # This is required for authentication using OIDC
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- uses: dart-lang/setup-dart@v1

- uses: subosito/flutter-action@v2
with:
flutter-version: "3.7.12"

- name: Install dependencies
run: dart pub get

- name: code format
run: dart format lib/*/*.dart lib/*.dart

- name: Publish
run: dart pub publish --force
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
workflow_call:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'

- uses: subosito/flutter-action@v2
with:
flutter-version: "3.7.12"

- name: Install packages dependencies
run: flutter pub get

- name: Analyze the project's Dart code
run: flutter analyze

- name: Run tests
run: flutter test

- name: Run tests coverage
run: flutter test --coverage
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

### [3.0.3]

- replace log() with stdout.writeln()

### [3.0.2]

- support intl 18
- support dart 3
- added trExists extension
- fix: handle invalid saved local
- handle null returned by assetLoader
- improve parsing scriptCode from local string
- add tr-extension on build context

### [3.0.1]

- added option allowing skip keys of nested object
Expand Down
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contributing

## Release process

1. Make sure that the changelog is updated

2. Make sure that the version in pubspec.yaml is correct

3. Create a release in the github UI. Name the release like the version, but with a v (3.7.5 -> v3.7.5). Name the tag like the release

4. A pipeline will run and deploy the new version to pub.dev
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Stand With Palestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/banner-no-action.svg)](https://thebsd.github.io/StandWithPalestine)

<p align="center"><img src="https://raw.githubusercontent.com/aissat/easy_localization/develop/logo/logo.svg?sanitize=true" width="600"/></p>
<h1 align="center">
Easy and Fast internationalization for your Flutter Apps
Expand All @@ -19,6 +21,7 @@ Easy and Fast internationalization for your Flutter Apps
![GitHub license](https://img.shields.io/github/license/aissat/easy_localization?style=flat-square)
![Sponsors](https://img.shields.io/opencollective/all/flutter_easy_localization?style=flat-square)
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
[![StandWithPalestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/badges/StandWithPalestine.svg)](https://github.com/TheBSD/StandWithPalestine/blob/main/docs/README.md)

## Why easy_localization?

Expand Down Expand Up @@ -192,6 +195,8 @@ Text('title').tr() //Text widget
print('title'.tr()); //String
var title = tr('title') //Static function
Text(context.tr('title')) //Extension on BuildContext
```

#### Arguments:
Expand Down Expand Up @@ -241,11 +246,13 @@ You can use extension methods of [String] or [Text] widget, you can also use `pl

#### Arguments:

| Name | Type | Description |
| ------ | -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| value | `num` | Number value for pluralization |
| args | `List<String>` | List of localized strings. Replaces `{}` left to right |
| format | `NumberFormat` | Formats a numeric value using a [NumberFormat](https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html) class |
| Name | Type | Description |
| --------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| value | `num` | Number value for pluralization |
| args | `List<String>` | List of localized strings. Replaces `{}` left to right |
| namedArgs | `Map<String, String>` | Map of localized strings. Replaces the name keys `{key_name}` according to its name |
| name | `String` | Name of number value. Replaces `{$name}` to value |
| format | `NumberFormat` | Formats a numeric value using a [NumberFormat](https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html) class |

Example:

Expand All @@ -270,6 +277,12 @@ Example:
"one": "{} has {} dollar",
"many": "{} has {} dollars",
"other": "{} has {} dollars"
},
"money_named_args": {
"zero": "{name} has no money",
"one": "{name} has {money} dollar",
"many": "{name} has {money} dollars",
"other": "{name} has {money} dollars"
}
}
```
Expand All @@ -285,8 +298,15 @@ print('day'.plural(21)); // output: 21 день
//Static function
var money = plural('money', 10.23) // output: You have 10.23 dollars
//Text widget with plural BuildContext extension
Text(context.plural('money', 10.23))
//Static function with arguments
var money = plural('money_args', 10.23, args: ['John', '10.23']) // output: John has 10.23 dollars
//Static function with named arguments
var money = plural('money_named_args', 10.23, namedArgs: {'name': 'Jane', 'money': '10.23'}) // output: Jane has 10.23 dollars
var money = plural('money_named_args', 10.23, namedArgs: {'name': 'Jane'}, name: 'money') // output: Jane has 10.23 dollars
```

### 🔥 Linked translations:
Expand Down Expand Up @@ -378,7 +398,7 @@ Get device locale
Example:

```dart
print(${context.deviceLocale.toString()}) // OUTPUT: en_US
print(context.deviceLocale.toString()) // OUTPUT: en_US
```

### 🔥 Delete save locale `deleteSaveLocale()`
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#https://dart.dev/guides/language/analysis-options
include: package:pedantic/analysis_options.yaml
include: package:flutter_lints/flutter.yaml
28 changes: 10 additions & 18 deletions bin/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool _isHelpCommand(List<String> args) {

void _printHelperDisplay() {
var parser = _generateArgParser(null);
print(parser.usage);
stdout.writeln(parser.usage);
}

GenerateOptions _generateOption(List<String> args) {
Expand Down Expand Up @@ -109,15 +109,15 @@ void handleLangFiles(GenerateOptions options) async {
Directory(path.join(current.path, output.path, options.outputFile));

if (!await sourcePath.exists()) {
printError('Source path does not exist');
stderr.writeln('Source path does not exist');
return;
}

var files = await dirContents(sourcePath);
if (options.sourceFile != null) {
final sourceFile = File(path.join(source.path, options.sourceFile));
if (!await sourceFile.exists()) {
printError('Source file does not exist (${sourceFile.toString()})');
stderr.writeln('Source file does not exist (${sourceFile.toString()})');
return;
}
files = [sourceFile];
Expand All @@ -129,7 +129,7 @@ void handleLangFiles(GenerateOptions options) async {
if (files.isNotEmpty) {
generateFile(files, outputPath, options);
} else {
printError('Source path empty');
stderr.writeln('Source path empty');
}
}

Expand Down Expand Up @@ -162,12 +162,12 @@ void generateFile(List<FileSystemEntity> files, Directory outputPath,
// await _writeCsv(classBuilder, files);
// break;
default:
printError('Format not support');
stderr.writeln('Format not supported');
}

generatedFile.writeAsStringSync(classBuilder.toString());

printInfo('All done! File generated in ${outputPath.path}');
stdout.writeln('All done! File generated in ${outputPath.path}');
}

class _NestedTranslationObject {
Expand Down Expand Up @@ -315,7 +315,7 @@ Future _writeJson(
var gFile = '''
// DO NOT EDIT. This is code generated via package:easy_localization/generate.dart
// ignore_for_file: prefer_single_quotes
// ignore_for_file: prefer_single_quotes, avoid_renaming_method_parameters
import 'dart:ui';
Expand All @@ -325,7 +325,7 @@ class CodegenLoader extends AssetLoader{
const CodegenLoader();
@override
Future<Map<String, dynamic>> load(String fullPath, Locale locale ) {
Future<Map<String, dynamic>?> load(String path, Locale locale) {
return Future.value(mapLocales[locale.toString()]);
}
Expand All @@ -341,12 +341,12 @@ class CodegenLoader extends AssetLoader{

Map<String, dynamic>? data = json.decode(await fileData.readAsString());

final mapString = JsonEncoder.withIndent(' ').convert(data);
final mapString = const JsonEncoder.withIndent(' ').convert(data);
gFile += 'static const Map<String,dynamic> $localeName = $mapString;\n';
}

gFile +=
'static const Map<String, Map<String,dynamic>> mapLocales = \{${listLocales.join(', ')}\};';
'static const Map<String, Map<String,dynamic>> mapLocales = {${listLocales.join(', ')}};';
classBuilder.writeln(gFile);
}

Expand All @@ -369,11 +369,3 @@ class CodegenLoader extends AssetLoader{
// ' static const Map<String, Map<String,dynamic>> mapLocales = \{${listLocales.join(', ')}\};');

// }

void printInfo(String info) {
print('\u001b[32measy localization: $info\u001b[0m');
}

void printError(String error) {
print('\u001b[31m[ERROR] easy localization: $error\u001b[0m');
}
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>11.0</string>
</dict>
</plist>
Loading

0 comments on commit e00e425

Please sign in to comment.