From a46ac59b5aa947995558cac735a29d1fc150de9f Mon Sep 17 00:00:00 2001
From: Marcelo Glasberg <13332110+marcglasberg@users.noreply.github.com>
Date: Thu, 16 Nov 2023 18:24:03 -0300
Subject: [PATCH] Importer library independently available as a standalone
package.
---
CHANGELOG.md | 9 ++
README.md | 38 ++++--
analysis_options.yaml | 3 +-
pubspec.yaml | 10 +-
test/getStrings/getstrings.dart | 37 -----
test/getStrings/i18n_getstrings.dart | 137 -------------------
test/getStrings/io/export.dart | 66 ---------
test/getStrings/io/import.dart | 101 --------------
test/i18n_getstrings_test.dart | 193 ---------------------------
test/import_test.dart | 44 ------
10 files changed, 39 insertions(+), 599 deletions(-)
delete mode 100644 test/getStrings/getstrings.dart
delete mode 100644 test/getStrings/i18n_getstrings.dart
delete mode 100644 test/getStrings/io/export.dart
delete mode 100644 test/getStrings/io/import.dart
delete mode 100644 test/i18n_getstrings_test.dart
delete mode 100644 test/import_test.dart
diff --git a/CHANGELOG.md b/CHANGELOG.md
index deccb06..3cddfff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## [10.0.0] - 2023/11/16
+
+* Up to version 8.0.0, the i18n_extension package contained the importer library developed by Johann
+ Bauer. This importer library has been separated and is now independently available as a standalone
+ package. You can find it at: https://pub.dev/packages/i18n_extension_importer. This new package
+ offers capabilities for importing translations in both `.PO` and `.JSON` formats.
+ It also includes the `GetStrings` exporting utility, which is a useful script designed to
+ automate the export of all translatable strings from your project.
+
## [9.0.2] - 2023/05/12
* Flutter 3.10 e Dart 3.0.0
diff --git a/README.md b/README.md
index 4aa0fb5..ff014d7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
[![pub package](https://img.shields.io/pub/v/i18n_extension.svg)](https://pub.dartlang.org/packages/i18n_extension)
# i18n_extension No boilerplate Translation and Internationalization
+
> IntelliJ plugin that supports this package coming soon:
https://plugins.jetbrains.com/plugin/21898-marcelo-s-flutter-dart-essentials
@@ -669,8 +670,8 @@ I18n.observeLocale =
### Importing and exporting
-This package is optimized so that you can easily create and manage all of your translations
-yourself, by hand.
+The `i18n_extension` package is optimized so that you can easily create and manage all of your
+translations yourself, by hand.
However, for large projects with big teams you probably need to follow a more involved process:
@@ -708,11 +709,18 @@ The following formats may be used with translations:
#### Importing
+Up to version `8.0.0`, the `i18n_extension` package contained the importer library.
+It has now been separated and is now independently available as a standalone package.
+You can find it at: https://pub.dev/packages/i18n_extension_importer.
+
+**Note:** Those importers were contributed by Johann Bauer,
+and were separated into its own package by Xiang Li.
+
Currently, only `.PO` and `.JSON` importers are supported out-of-the-box.
+If you want to help creating importers for any of the other formats above, please PR there.
-**Note:** Those importers were contributed by Johann Bauer.
-If you want to help creating importers for any of the other formats above, please PR
-here: https://github.com/marcglasberg/i18n_extension.
+It also includes the `GetStrings` exporting utility, which is a useful script designed to
+automate the export of all translatable strings from your project.
Add your translation files as assets to your app in a directory structure like this:
@@ -728,7 +736,7 @@ app
Then you can import them using `GettextImporter` or `JSONImporter`:
```
-import 'package:i18n_extension/io/import.dart';
+import 'package:i18n_extension_importer/io/import.dart';
import 'package:i18n_extension/i18n_extension.dart';
class MyI18n {
@@ -757,17 +765,19 @@ codes, you'll get errors like this: `There are no translations in 'en_us' for "H
**Note:** If you need to import any other custom format, remember importing is easy to do because
the Translation constructors use maps as input. If you can generate a map from your file format, you
-can then use the `Translation()`
-or `Translation.byLocale()` constructors to create the translation objects.
+can then use the `Translation()` or `Translation.byLocale()` constructors to create the translation
+objects.
#### The GetStrings exporting utility
-An utility script to automatically export all translatable strings from your project was contributed
-by Johann Bauer. Simply
-run `flutter pub run i18n_extension:getstrings` in your project root directory and you will get a
-list of strings to translate in `strings.json`. This file can then be sent to your translators or be
-imported in translation services like _Crowdin_, _Transifex_ or _Lokalise_. You can use it as part
-of your CI pipeline in order to always have your translation templates up to date.
+A utility script to automatically export all translatable strings from your project was also
+contributed by Johann Bauer.
+
+Simply run `flutter pub run i18n_extension_importer:getstrings` in your project root directory, and
+you will get a list of strings to translate in `strings.json`. This file can then be sent to your
+translators or be imported in translation services like _Crowdin_, _Transifex_ or _Lokalise_. You
+can use it as part of your CI pipeline in order to always have your translation templates up to
+date.
Note the tool simply searches the source code for strings to which getters like `.i18n` are applied.
Since it is not very smart, you should not make it too hard:
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 33231ee..a433af5 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -35,10 +35,9 @@ linter:
- empty_statements
- hash_and_equals
- implementation_imports
- - iterable_contains_unrelated_type
+ - collection_methods_unrelated_type
- library_names
- library_prefixes
- - list_remove_unrelated_type
- no_duplicate_case_values
- overridden_fields
- package_api_docs
diff --git a/pubspec.yaml b/pubspec.yaml
index c1658f5..f514c1a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,23 +1,23 @@
name: i18n_extension
description: Translation and Internationalization (i18n) for Flutter. Easy to use for both large and small projects. Uses Dart extensions to reduce boilerplate.
-version: 9.0.2
+version: 10.0.0
homepage: https://github.com/marcglasberg/i18n_extension
# author: Marcelo Glasberg
environment:
- sdk: '>=2.19.0 <4.0.0'
+ sdk: '>=3.0.0 <4.0.0'
dependencies:
sprintf: ^7.0.0
- args: ^2.3.1
+ args: ^2.4.2
equatable: ^2.0.5
intl: ^0.18.0
flutter:
sdk: flutter
dev_dependencies:
- analyzer: ^5.3.1
- gettext_parser: ^0.2.0
flutter_test:
sdk: flutter
+ test: ^1.24.9
+
diff --git a/test/getStrings/getstrings.dart b/test/getStrings/getstrings.dart
deleted file mode 100644
index c698023..0000000
--- a/test/getStrings/getstrings.dart
+++ /dev/null
@@ -1,37 +0,0 @@
-import 'dart:io';
-
-import 'package:args/args.dart';
-
-import 'i18n_getstrings.dart';
-import 'io/export.dart';
-
-void main(List arguments) async {
- const OUTPUT_FILE = "output-file";
- const SOURCE_DIR = "source-dir";
-
- var parser = ArgParser()
- ..addOption(OUTPUT_FILE,
- abbr: "f",
- defaultsTo: "strings.pot",
- valueHelp: "Supported formats: ${exporters.keys.join(", ")}")
- ..addOption(SOURCE_DIR, abbr: "s", defaultsTo: "./lib");
-
- ArgResults results = parser.parse(arguments);
-
- String outputFilename = results[OUTPUT_FILE];
- var fileFormat = outputFilename.split(".").last;
- if (!exporters.containsKey(fileFormat)) {
- print("Unable to write to $outputFilename.");
- print("Supported formats: ${exporters.keys.join(", ")}");
- exit(1);
- }
-
- String? sourceDir = results[SOURCE_DIR];
- List strings = GetI18nStrings(sourceDir).run();
-
- var outputFile = File(outputFilename);
- await outputFile.create();
- exporters[fileFormat]!(strings).exportTo(outputFile);
-
- print("Wrote ${strings.length} strings to template $outputFilename");
-}
diff --git a/test/getStrings/i18n_getstrings.dart b/test/getStrings/i18n_getstrings.dart
deleted file mode 100644
index 1caed29..0000000
--- a/test/getStrings/i18n_getstrings.dart
+++ /dev/null
@@ -1,137 +0,0 @@
-import 'dart:io';
-
-import 'package:analyzer/dart/analysis/utilities.dart';
-import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/ast/token.dart';
-import 'package:analyzer/dart/ast/visitor.dart';
-import 'package:equatable/equatable.dart';
-
-enum I18nRequiredModifiers { plural }
-
-class I18nSuffixes {
- static const String i18n = 'i18n';
- static const String fill = 'fill';
- static const String plural = 'plural';
- static const String version = 'version';
- static const String allVersions = 'allVersions';
-
- static const List allSuffixes = const [
- i18n,
- fill,
- plural,
- version,
- allVersions,
- ];
-}
-
-class ExtractedString extends Equatable {
- final String string;
- final int lineNumber;
- final String sourceFile;
- final bool pluralRequired;
-
- ExtractedString(this.string, this.lineNumber,
- {this.pluralRequired = false, this.sourceFile = ""});
-
- @override
- List