Skip to content

Commit

Permalink
Merge branch 'null-safety.3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aissat committed Feb 20, 2021
2 parents bc8f6da + 05b9e28 commit 33aee74
Show file tree
Hide file tree
Showing 36 changed files with 1,538 additions and 567 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # or: 'dev' or 'beta'
channel: 'dev' # or: 'dev' or 'beta'

- name: Install packages dependencies
run: flutter pub get
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

### [3.0.0]

- **BREAKING**: Added `EasyLocalization.ensureInitialized()`, Needs to be called
- **BREAKING**: Added support null safety
- **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`~~
- Added `EasyLocalization.ensureInitialized()`, Needs to be called
- fixed many issues.
- customizable logger [EasyLogger]
- device locale and reset device locale
- extensions helpers
- support fallback locale keys redirection

### [2.3.3]

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Easy and Fast internationalization for your Flutter Apps
- 🔌 Load translations as JSON, CSV, Yaml, Xml using [Easy Localization Loader](https://github.com/aissat/easy_localization_loader)
- 💾 React and persist to locale changes
- ⚡ Supports plural, gender, nesting, RTL locales and more
- ↩️ Fallback locale keys redirection
- ⁉️ Error widget for missing translations
- ❤️ Extension methods on `Text` and `BuildContext`
- 💻 Code generation for localization files and keys.
- 🛡️ Null safety
- 🖨️ Customizable logger.

## Getting Started
Expand Down Expand Up @@ -196,7 +198,6 @@ var title = tr('title') //Static function

| Name | Type | Description |
| -------- | -------- | -------- |
| context| `BuildContext` | The location in the tree where this widget builds |
| 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 |
| gender | `String` | Gender switcher. Changes the localized string based on gender string |
Expand Down Expand Up @@ -242,7 +243,6 @@ You can use extension methods of [String] or [Text] widget, you can also use `pl

| Name | Type | Description |
| -------- | -------- | -------- |
| context| `BuildContext` | The location in the tree where this widget builds|
| 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 |
Expand Down
34 changes: 17 additions & 17 deletions bin/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,49 @@ GenerateOptions _generateOption(List<String> args) {
return generateOptions;
}

ArgParser _generateArgParser(GenerateOptions generateOptions) {
ArgParser _generateArgParser(GenerateOptions? generateOptions) {
var parser = ArgParser();

parser.addOption('source-dir',
abbr: 'S',
defaultsTo: 'resources/langs',
callback: (String x) => generateOptions.sourceDir = x,
callback: (String? x) => generateOptions!.sourceDir = x,
help: 'Folder containing localization files');

parser.addOption('source-file',
abbr: 's',
callback: (String x) => generateOptions.sourceFile = x,
callback: (String? x) => generateOptions!.sourceFile = x,
help: 'File to use for localization');

parser.addOption('output-dir',
abbr: 'O',
defaultsTo: 'lib/generated',
callback: (String x) => generateOptions.outputDir = x,
callback: (String? x) => generateOptions!.outputDir = x,
help: 'Output folder stores for the generated file');

parser.addOption('output-file',
abbr: 'o',
defaultsTo: 'codegen_loader.g.dart',
callback: (String x) => generateOptions.outputFile = x,
callback: (String? x) => generateOptions!.outputFile = x,
help: 'Output file name');

parser.addOption('format',
abbr: 'f',
defaultsTo: 'json',
callback: (String x) => generateOptions.format = x,
callback: (String? x) => generateOptions!.format = x,
help: 'Support json or keys formats',
allowed: ['json', 'keys']);

return parser;
}

class GenerateOptions {
String sourceDir;
String sourceFile;
String templateLocale;
String outputDir;
String outputFile;
String format;
String? sourceDir;
String? sourceFile;
String? templateLocale;
String? outputDir;
String? outputFile;
String? format;

@override
String toString() {
Expand All @@ -92,8 +92,8 @@ class GenerateOptions {

void handleLangFiles(GenerateOptions options) async {
final current = Directory.current;
final source = Directory.fromUri(Uri.parse(options.sourceDir));
final output = Directory.fromUri(Uri.parse(options.outputDir));
final source = Directory.fromUri(Uri.parse(options.sourceDir!));
final output = Directory.fromUri(Uri.parse(options.outputDir!));
final sourcePath = Directory(path.join(current.path, source.path));
final outputPath =
Directory(path.join(current.path, output.path, options.outputFile));
Expand Down Expand Up @@ -133,7 +133,7 @@ Future<List<FileSystemEntity>> dirContents(Directory dir) {
}

void generateFile(
List<FileSystemEntity> files, Directory outputPath, String format) async {
List<FileSystemEntity> files, Directory outputPath, String? format) async {
var generatedFile = File(outputPath.path);
if (!generatedFile.existsSync()) {
generatedFile.createSync(recursive: true);
Expand Down Expand Up @@ -179,7 +179,7 @@ abstract class LocaleKeys {
classBuilder.writeln(file);
}

String _resolve(Map<String, dynamic> translations, [String accKey]) {
String _resolve(Map<String, dynamic> translations, [String? accKey]) {
var fileContent = '';

final sortedKeys = translations.keys.toList();
Expand Down Expand Up @@ -234,7 +234,7 @@ class CodegenLoader extends AssetLoader{
listLocales.add('"$localeName": $localeName');
final fileData = File(file.path);

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

final mapString = JsonEncoder.withIndent(' ').convert(data);
gFile += 'static const Map<String,dynamic> $localeName = $mapString;\n';
Expand Down
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
10 changes: 5 additions & 5 deletions example/lib/lang_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LanguageView extends StatelessWidget {
}

class _Divider extends StatelessWidget {
const _Divider({Key key}) : super(key: key);
const _Divider({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -83,10 +83,10 @@ class _Divider extends StatelessWidget {

class _SwitchListTileMenuItem extends StatelessWidget {
const _SwitchListTileMenuItem({
Key key,
this.title,
this.subtitle,
this.locale,
Key? key,
required this.title,
required this.subtitle,
required this.locale,
}) : super(key: key);

final String title;
Expand Down
72 changes: 37 additions & 35 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:ui';

import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization_loader/easy_localization_loader.dart';
//import 'package:easy_localization_loader/easy_localization_loader.dart'; // import custom loaders
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'generated/locale_keys.g.dart';
import 'lang_view.dart';
Expand All @@ -13,31 +13,31 @@ void main() async {
await EasyLocalization.ensureInitialized();

runApp(EasyLocalization(
child: MyApp(),
supportedLocales: [
Locale('en', 'US'),
Locale('ar', 'DZ'),
Locale('de', 'DE'),
Locale('ru', 'RU')
],
path: 'resources/langs/langs.csv', //'resources/langs',
// fallbackLocale: Locale('en', 'US'),
// startLocale: Locale('de', 'DE'),
// saveLocale: false,
// useOnlyLangCode: true,
child: MyApp(),
supportedLocales: [
Locale('en', 'US'),
Locale('ar', 'DZ'),
Locale('de', 'DE'),
Locale('ru', 'RU')
],
path: 'resources/langs',
// fallbackLocale: Locale('en', 'US'),
// startLocale: Locale('de', 'DE'),
// saveLocale: false,
// useOnlyLangCode: true,

// optional assetLoader default used is RootBundleAssetLoader which uses flutter's assetloader
// install easy_localization_loader for enable custom loaders
// assetLoader: RootBundleAssetLoader()
// assetLoader: HttpAssetLoader()
// assetLoader: FileAssetLoader()
assetLoader: CsvAssetLoader()
// assetLoader: YamlAssetLoader() //multiple files
// assetLoader: YamlSingleAssetLoader() //single file
// assetLoader: XmlAssetLoader() //multiple files
// assetLoader: XmlSingleAssetLoader() //single file
// assetLoader: CodegenLoader()
));
// optional assetLoader default used is RootBundleAssetLoader which uses flutter's assetloader
// install easy_localization_loader for enable custom loaders
// assetLoader: RootBundleAssetLoader()
// assetLoader: HttpAssetLoader()
// assetLoader: FileAssetLoader()
// assetLoader: CsvAssetLoader()
// assetLoader: YamlAssetLoader() //multiple files
// assetLoader: YamlSingleAssetLoader() //single file
// assetLoader: XmlAssetLoader() //multiple files
// assetLoader: XmlSingleAssetLoader() //single file
// assetLoader: CodegenLoader()
));
}

class MyApp extends StatelessWidget {
Expand All @@ -56,7 +56,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand Down Expand Up @@ -84,11 +84,13 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(LocaleKeys.title).tr(context: context),
//Text(AppLocalizations.of(context).tr('title')),
title: Text(LocaleKeys.title).tr(),
actions: <Widget>[
FlatButton(
child: Icon(Icons.language),
TextButton(
child: Icon(
Icons.language,
color: Colors.white,
),
onPressed: () {
Navigator.push(
context,
Expand Down Expand Up @@ -123,9 +125,9 @@ class _MyHomePageState extends State<MyHomePage> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(FontAwesome.male),
FaIcon(FontAwesomeIcons.male),
Switch(value: _gender, onChanged: switchGender),
Icon(FontAwesome.female),
FaIcon(FontAwesomeIcons.female),
],
),
Spacer(
Expand All @@ -135,7 +137,7 @@ class _MyHomePageState extends State<MyHomePage> {
Text(LocaleKeys.msg_named)
.tr(namedArgs: {'lang': 'Dart'}, args: ['Easy localization']),
Text(LocaleKeys.clicked).plural(counter),
FlatButton(
TextButton(
onPressed: () {
incrementCounter();
},
Expand All @@ -155,7 +157,7 @@ class _MyHomePageState extends State<MyHomePage> {
SizedBox(
height: 20,
),
RaisedButton(
ElevatedButton(
onPressed: () {
context.resetLocale();
},
Expand Down
1 change: 1 addition & 0 deletions example/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter/ephemeral
Loading

0 comments on commit 33aee74

Please sign in to comment.