Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Dart locale parser #885

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading