Skip to content

Commit

Permalink
Remove Dart locale parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Sep 6, 2024
1 parent 863dc69 commit 720bcc4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
4 changes: 4 additions & 0 deletions pkgs/intl4x/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.2-wip

- Remove Dart parser of locale strings.

## 0.10.1

- Upgrade to new artifacts.
Expand Down
15 changes: 10 additions & 5 deletions pkgs/intl4x/lib/src/locale/locale_4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
41 changes: 13 additions & 28 deletions pkgs/intl4x/lib/src/locale/locale_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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('_')) {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 720bcc4

Please sign in to comment.