Skip to content

Commit

Permalink
Merge branch 'main' into addConformanceTesting
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem authored Aug 22, 2023
2 parents 58341fc + beca88a commit 5d1e836
Show file tree
Hide file tree
Showing 36 changed files with 335 additions and 155 deletions.
10 changes: 9 additions & 1 deletion pkgs/intl4x/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
## 0.6.1-wip

- Add conformance testing workflow.

## 0.6.0

- Add full ECMA locale.

## 0.5.1

- Add `copyWith` constructors.
- Add `copyWith` methods.

## 0.5.0

Expand Down
4 changes: 2 additions & 2 deletions pkgs/intl4x/lib/intl4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import 'src/find_locale.dart';
import 'src/list_format/list_format.dart';
import 'src/list_format/list_format_impl.dart';
import 'src/list_format/list_format_options.dart';
import 'src/locale.dart';
import 'src/locale/locale.dart';
import 'src/number_format/number_format_impl.dart';

export 'src/locale.dart';
export 'src/locale/locale.dart';

typedef Icu4xKey = String;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/collation/collation_4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import 'collation_impl.dart';
import 'collation_options.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/collation/collation_ecma.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:js/js.dart';
import 'package:js/js_util.dart';

import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'collation_impl.dart';
import 'collation_options.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/collation/collation_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import '../ecma/ecma_policy.dart';
import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import '../utils.dart';
import 'collation_4x.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/collation/collation_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'collation_impl.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import 'datetime_format_impl.dart';
import 'datetime_format_options.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:js/js.dart';
import 'package:js/js_util.dart';

import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'datetime_format_impl.dart';
import 'datetime_format_options.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import '../ecma/ecma_policy.dart';
import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import '../utils.dart';
import 'datetime_format_4x.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'datetime_format_impl.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/display_names/display_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import '../../display_names.dart';
import '../locale.dart';
import '../locale/locale.dart';
import '../test_checker.dart';
import 'display_names_impl.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/display_names/display_names_4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'display_names_impl.dart';
import 'display_names_options.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/display_names/display_names_ecma.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:js/js.dart';
import 'package:js/js_util.dart';

import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'display_names_impl.dart';
import 'display_names_options.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/display_names/display_names_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import '../ecma/ecma_policy.dart';
import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import '../utils.dart';
import 'display_names_4x.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/display_names/display_names_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'display_names_impl.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/ecma/ecma_policy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';

/// A strategy to decide ICU4X for i18n functionality or delegate to the
/// built-in browser support. See also
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/intl_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import 'dart:html';

import 'locale.dart';
import 'locale/locale.dart';

Locale findSystemLocale() => Locale.parse(window.navigator.language);
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/intl_standalone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:io';

import 'locale.dart';
import 'locale/locale.dart';

Locale findSystemLocale() {
try {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/list_format/list_format_4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import 'list_format_impl.dart';
import 'list_format_options.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/list_format/list_format_ecma.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:js/js.dart';
import 'package:js/js_util.dart';

import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'list_format_impl.dart';
import 'list_format_options.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/list_format/list_format_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import '../../ecma_policy.dart';
import '../ecma/ecma_policy.dart';
import '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import '../utils.dart';
import 'list_format_4x.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/lib/src/list_format/list_format_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 '../locale.dart';
import '../locale/locale.dart';
import '../options.dart';
import 'list_format_impl.dart';

Expand Down
59 changes: 0 additions & 59 deletions pkgs/intl4x/lib/src/locale.dart

This file was deleted.

92 changes: 92 additions & 0 deletions pkgs/intl4x/lib/src/locale/locale.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// 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 '../../collation.dart';
import '../datetime_format/datetime_format_options.dart';
import 'locale_native.dart' if (dart.library.js) 'locale_ecma.dart';

/// Representing a Unicode locale identifier. It is composed of the primary
/// `language` subtag for the locale, the `region` (also referred to as
/// 'country') subtag, and the script subtag.
///
/// Examples are `de-DE`, `es-419`, or `zh-Hant-TW`.
class Locale {
/// The language subtag, such as `en` for English.
final String language;

/// The script subtag, such as `Hant` for traditional chinese.
final String? script;

/// The region subtag, such as `US` for the United Status of America or `419`
/// for Latin America.
final String? region;

final Calendar? calendar;
final CaseFirst? caseFirst;
final String? collation;
final HourCycle? hourCycle;
final String? numberingSystem;
final bool? numeric;

const Locale({
required this.language,
this.region,
this.script,
this.calendar,
this.caseFirst,
this.collation,
this.hourCycle,
this.numberingSystem,
this.numeric,
});

/// Generate a language tag by joining the subtags with the [separator].
String toLanguageTag([String separator = '-']) =>
toLanguageTagImpl(this, separator);

/// Try to remove tags which would be added by [maximize].
Locale minimize() => minimizeImpl(this);

/// Try to add the most likely language, script, and region tags.
Locale maximize() => maximizeImpl(this);

/// Parse a language tag by calling to web/ICU4X functionalities.
static Locale parse(String s) => parseLocale(s);

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is Locale &&
other.language == language &&
other.script == script &&
other.region == region &&
other.calendar == calendar &&
other.caseFirst == caseFirst &&
other.collation == collation &&
other.hourCycle == hourCycle &&
other.numberingSystem == numberingSystem &&
other.numeric == numeric;
}

@override
int get hashCode {
return language.hashCode ^
script.hashCode ^
region.hashCode ^
calendar.hashCode ^
caseFirst.hashCode ^
collation.hashCode ^
hourCycle.hashCode ^
numberingSystem.hashCode ^
numeric.hashCode;
}
}

// TODO: add all locales which are supported by ICU4X / Browsers
const List<Locale> allLocales = [
Locale(language: 'de', region: 'DE'),
Locale(language: 'en', region: 'US'),
Locale(language: 'zh', script: 'Hant'),
];
Loading

0 comments on commit 5d1e836

Please sign in to comment.