diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4db49..d0ee1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to the "flutter-intl" extension will be documented in this f The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.8.13 - Unreleased + +- Fix language overrides ([#19](https://github.com/localizely/intl_utils/issues/19)) + ## 2.8.12 - 2025-09-10 - Update `analyzer` dependency @@ -70,7 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 2.8.0 - 2022-11-15 -- Update `analyzer` and `lints` dependencies +- Update `analyzer` and `lints` dependencies ([#91](https://github.com/localizely/intl_utils/issues/91)) ## 2.7.0 - 2022-07-07 diff --git a/bin/generate.dart b/bin/generate.dart index 53a2c84..aac467b 100644 --- a/bin/generate.dart +++ b/bin/generate.dart @@ -1,4 +1,4 @@ -library intl_utils; +library; import 'package:intl_utils/intl_utils.dart'; import 'package:intl_utils/src/generator/generator_exception.dart'; diff --git a/bin/localizely_download.dart b/bin/localizely_download.dart index 4b6dcbb..0a36d29 100644 --- a/bin/localizely_download.dart +++ b/bin/localizely_download.dart @@ -1,4 +1,4 @@ -library intl_utils; +library; import 'dart:io'; diff --git a/bin/localizely_upload_main.dart b/bin/localizely_upload_main.dart index f0055b2..289695a 100644 --- a/bin/localizely_upload_main.dart +++ b/bin/localizely_upload_main.dart @@ -1,4 +1,4 @@ -library intl_utils; +library; import 'dart:io'; diff --git a/lib/intl_utils.dart b/lib/intl_utils.dart index d77fba8..0e6909d 100644 --- a/lib/intl_utils.dart +++ b/lib/intl_utils.dart @@ -1,3 +1,3 @@ -library intl_utils; +library; export 'src/generator/generator.dart'; diff --git a/lib/src/generator/label.dart b/lib/src/generator/label.dart index 628c6cc..7b46604 100644 --- a/lib/src/generator/label.dart +++ b/lib/src/generator/label.dart @@ -336,6 +336,7 @@ class Label { ' name: \'$name\',', ' desc: \'$description\',', ' args: [],', + ' locale: localeName,', ' );', ' }', ].join('\n'); @@ -352,6 +353,7 @@ class Label { ' name: \'$name\',', ' desc: \'$description\',', ' args: [${_generateDartMethodArgs(args)}],', + ' locale: localeName,', ' );', ' }', ].join('\n'); @@ -370,6 +372,7 @@ class Label { ' name: \'$name\',', ' desc: \'$description\',', ' args: [${_generateDartMethodArgs(args)}],', + ' locale: localeName,', ' );', ' }', ].join('\n'); @@ -388,6 +391,7 @@ class Label { ' name: \'$name\',', ' desc: \'$description\',', ' args: [${_generateDartMethodArgs(args)}],', + ' locale: localeName,', ' );', ' }', ].join('\n'); @@ -409,6 +413,7 @@ class Label { ' name: \'$name\',', ' desc: \'$description\',', ' args: [${_generateDartMethodArgs(args)}],', + ' locale: localeName,', ' );', ' }', ].join('\n'); diff --git a/lib/src/generator/templates.dart b/lib/src/generator/templates.dart index b18e944..5f274b0 100644 --- a/lib/src/generator/templates.dart +++ b/lib/src/generator/templates.dart @@ -9,6 +9,7 @@ String generateL10nDartFileContent( ]) { return """ // GENERATED CODE - DO NOT MODIFY BY HAND +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart';${otaEnabled ? '\n${_generateLocalizelySdkImport()}' : ''} import 'intl/messages_all.dart'; @@ -23,10 +24,12 @@ import 'intl/messages_all.dart'; // ignore_for_file: avoid_redundant_argument_values, avoid_escaping_inner_quotes class $className { - $className(); + $className(this.localeName); static $className? _current; + /// It is strongly discouraged to use this instance since it can easily + /// lead to non-determinism. Use [of] or [maybeOf] instead. static $className get current { assert(_current != null, 'No instance of $className was loaded. Try to initialize the $className delegate before accessing $className.current.'); return _current!; @@ -39,11 +42,9 @@ class $className { final name = (locale.countryCode?.isEmpty ?? false) ? locale.languageCode : locale.toString(); final localeName = Intl.canonicalizedLocale(name);${otaEnabled ? '\n${_generateMetadataSetter()}' : ''} return initializeMessages(localeName).then((_) { - Intl.defaultLocale = localeName; - final instance = $className(); + final instance = $className(localeName); $className._current = instance; - - return instance; + return SynchronousFuture<$className>(instance); }); } @@ -56,6 +57,8 @@ class $className { static $className? maybeOf(BuildContext context) { return Localizations.of<$className>(context, $className); } + + final String localeName; ${otaEnabled ? '\n${_generateMetadata(labels)}\n' : ''} ${labels.map((label) => label.generateDartGetter()).join("\n\n")} } diff --git a/lib/src/intl_translation/extract_messages.dart b/lib/src/intl_translation/extract_messages.dart index 6ee5105..2ac1780 100644 --- a/lib/src/intl_translation/extract_messages.dart +++ b/lib/src/intl_translation/extract_messages.dart @@ -51,7 +51,7 @@ /// Note that this does not understand how to follow part directives, so it /// has to explicitly be given all the files that it needs. A typical use case /// is to run it on all .dart files in a directory. -library extract_messages; +library; // ignore_for_file: implementation_imports diff --git a/lib/src/intl_translation/generate_localized.dart b/lib/src/intl_translation/generate_localized.dart index ed62d6e..ac17d32 100644 --- a/lib/src/intl_translation/generate_localized.dart +++ b/lib/src/intl_translation/generate_localized.dart @@ -43,7 +43,7 @@ /// /// An example of usage can be found /// in test/message_extract/generate_from_json.dart -library generate_localized; +library; import 'package:intl/intl.dart'; import 'dart:convert'; diff --git a/lib/src/intl_translation/src/icu_parser.dart b/lib/src/intl_translation/src/icu_parser.dart index 0493dc1..e2bb519 100644 --- a/lib/src/intl_translation/src/icu_parser.dart +++ b/lib/src/intl_translation/src/icu_parser.dart @@ -38,7 +38,7 @@ /// Contains a parser for ICU format plural/gender/select format for localized /// messages. See extract_to_arb.dart and make_hardcoded_translation.dart. -library icu_parser; +library; import 'package:petitparser/petitparser.dart'; diff --git a/lib/src/intl_translation/src/intl_message.dart b/lib/src/intl_translation/src/intl_message.dart index 8d79400..e4138e9 100644 --- a/lib/src/intl_translation/src/intl_message.dart +++ b/lib/src/intl_translation/src/intl_message.dart @@ -63,7 +63,7 @@ /// This representation isn't used at runtime. Rather, we read some format /// from a translation file, parse it into these objects, and they are then /// used to generate the code representation above. -library intl_message; +library; // ignore_for_file: implementation_imports diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index e8b6fac..3a631f2 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -11,7 +11,7 @@ bool isValidLocale(String value) => RegExp( ).hasMatch(value); bool isValidPath(String value) => - RegExp(r'^(?:[A-Za-z]:)?([\/\\]{0,2}\w*)+$').hasMatch(value); + RegExp(r'^(?:[A-Za-z]:)?([/\\]{0,2}\w*)+$').hasMatch(value); bool isValidDownloadEmptyAsParam(String value) => RegExp(r'^(empty|main|skip)$').hasMatch(value); diff --git a/pubspec.yaml b/pubspec.yaml index 83d004b..28234dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: intl_utils description: intl_utils is a dart library that generates Dart localization code from ARB file. Generated code relies on Intl library. -version: 2.8.12 +version: 2.8.13 homepage: https://github.com/localizely/intl_utils environment: @@ -19,6 +19,6 @@ dependencies: dev_dependencies: build_runner: ^2.0.6 - lints: ^4.0.0 + lints: ^5.0.0 mockito: ^5.5.1 test: ^1.16.0