diff --git a/pkgs/intl4x/CHANGELOG.md b/pkgs/intl4x/CHANGELOG.md index 594384b6..e711ad10 100644 --- a/pkgs/intl4x/CHANGELOG.md +++ b/pkgs/intl4x/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.2-wip + +- Remove Dart parser of locale strings. + ## 0.10.1 - Upgrade to new artifacts. diff --git a/pkgs/intl4x/lib/src/locale/locale_4x.dart b/pkgs/intl4x/lib/src/locale/locale_4x.dart index f496b2a2..ed7928ec 100644 --- a/pkgs/intl4x/lib/src/locale/locale_4x.dart +++ b/pkgs/intl4x/lib/src/locale/locale_4x.dart @@ -5,12 +5,17 @@ import '../bindings/lib.g.dart' as icu; import 'locale.dart'; +import 'locale_native.dart'; -extension Locale4X on Locale { +extension Locale4XTransformer on Locale { icu.Locale to4X() { - final icu4xLocale = icu.Locale.und()..language = language; - if (region != null) icu4xLocale.region = region!; - if (script != null) icu4xLocale.script = script!; - return icu4xLocale; + if (this is IcuLocale) { + return (this as IcuLocale).locale; + } else { + final icu4xLocale = icu.Locale.und()..language = language; + if (region != null) icu4xLocale.region = region!; + if (script != null) icu4xLocale.script = script!; + return icu4xLocale; + } } } diff --git a/pkgs/intl4x/lib/src/locale/locale_native.dart b/pkgs/intl4x/lib/src/locale/locale_native.dart index 377b67e7..a332217c 100644 --- a/pkgs/intl4x/lib/src/locale/locale_native.dart +++ b/pkgs/intl4x/lib/src/locale/locale_native.dart @@ -2,41 +2,26 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import '../bindings/lib.g.dart' as icu; import 'locale.dart'; /// This file should be replaced by references to ICU4X when ready. -Locale parseLocaleWithSeparatorPlaceholder(String s, [String separator = '-']) { - final parsed = s.split(separator); - // ignore: unused_local_variable - final subtags = parsed.skipWhile((value) => value != 'u').toList(); - final tags = parsed.takeWhile((value) => value != 'u').toList(); - final language = tags.first; - final String? script; - final String? region; - if (tags.length == 2) { - if (tags[1].length == 2 && tags[1] == tags[1].toUpperCase()) { - region = tags[1]; - script = null; - } else { - region = null; - script = tags[1]; - } - } else if (tags.length == 3) { - script = tags[1]; - region = tags[2]; - } else { - script = null; - region = null; - } +class IcuLocale extends Locale { + final icu.Locale locale; - return Locale( - language: language, - region: region, - script: script, - ); + IcuLocale(this.locale) + : super( + language: locale.language, + region: locale.region, + script: locale.script, + ); } +Locale parseLocaleWithSeparatorPlaceholder(String s, + [String separator = '-']) => + IcuLocale(icu.Locale.fromString(s)); + //TODO: Switch to ICU4X! Locale parseLocale(String s, [String separator = '-']) { if (s.contains('_')) { diff --git a/pkgs/intl4x/pubspec.yaml b/pkgs/intl4x/pubspec.yaml index e6db3305..b5a35d32 100644 --- a/pkgs/intl4x/pubspec.yaml +++ b/pkgs/intl4x/pubspec.yaml @@ -1,7 +1,7 @@ name: intl4x description: >- A lightweight modular library for internationalization (i18n) functionality. -version: 0.10.1 +version: 0.10.2-wip repository: https://github.com/dart-lang/i18n/tree/main/pkgs/intl4x platforms: web: