Skip to content
Open
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: 2 additions & 2 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9

- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
- uses: dart-lang/setup-dart@a73965b3c99b30eb092908ce56c429eff91f9634
with:
sdk: 3.10.0
sdk: 3.12.0

- run: dart pub get

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
path: gh-cache
key: ${{ runner.os }}-icu4c-binaries
- name: Setup version of Dart
uses: dart-lang/setup-dart@v1
uses: dart-lang/setup-dart@a73965b3c99b30eb092908ce56c429eff91f9634
with:
sdk: 3.10.0
sdk: 3.12.0
- name: Set version of Rust
uses: actions-rs/toolchain@v1
with:
Expand Down
6 changes: 2 additions & 4 deletions executors/dart/bin/executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:collection/collection.dart';
import 'package:dart_executor/collator.dart';
import 'package:dart_executor/datetime_format.dart';
import 'package:dart_executor/lang_names.dart';
import 'package:dart_executor/likely_subtags.dart';
import 'package:dart_executor/list_format.dart';
import 'package:dart_executor/numberformat.dart';
import 'package:dart_executor/plural_rules.dart';
Expand Down Expand Up @@ -60,10 +61,7 @@ void main() {
'display_names is not supported yet',
),
TestTypes.lang_names => testLangNames(line),
// TestTypes.likely_subtags => testLikelySubtags(line),
TestTypes.likely_subtags => throw UnimplementedError(
'likely_subtags is not supported yet, as the Locale object is not yet migrated to ICU4X',
),
TestTypes.likely_subtags => testLikelySubtags(line),
TestTypes.list_fmt => testListFmt(line),
TestTypes.plural_rules => testPluralRules(line),
null => throw ArgumentError.value(
Expand Down
4 changes: 4 additions & 0 deletions executors/dart/bin/make_runnable_by_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Future<void> main(List<String> args) async {
name: 'testPluralRules',
argNames: ['encoded'],
),
'likely_subtags': ExportFunction(
name: 'testLikelySubtags',
argNames: ['encoded'],
),
'list_format': ExportFunction(name: 'testListFmt', argNames: ['encoded']),
'datetimeformat': ExportFunction(
name: 'testDateTimeFmt',
Expand Down
5 changes: 5 additions & 0 deletions executors/dart/bin/web_wrappers/likely_subtags_executor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:dart_executor/likely_subtags.dart';

void main(List<String> args) {
testLikelySubtags(args.first);
}
4 changes: 2 additions & 2 deletions executors/dart/lib/datetime_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ String testDateTimeFmt(String jsonEncoded) {
}
returnJson['actual_options'] = {
'locale': locale.toString(),
if (dateStyle != null) 'dateStyle': dateStyle,
if (timeStyle != null) 'timeStyle': timeStyle,
'dateStyle': ?dateStyle,
'timeStyle': ?timeStyle,
Comment thread
mosuem marked this conversation as resolved.
if (yearStyle != null) 'yearStyle': yearStyle.name,
if (calendar != null) 'calendar': calendar.jsName,
};
Expand Down
4 changes: 4 additions & 0 deletions executors/dart/lib/likely_subtags.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'likely_subtags_native.dart'
if (dart.library.js_interop) 'likely_subtags_web.dart';

String testLikelySubtags(String jsonEncoded) => testLikelySubtagsImpl(jsonEncoded);
34 changes: 34 additions & 0 deletions executors/dart/lib/likely_subtags_native.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:convert';
import 'package:icu4x/icu4x.dart' as icu;

String testLikelySubtagsImpl(String jsonEncoded) {
final json = jsonDecode(jsonEncoded) as Map<String, dynamic>;
final label = json['label'];
final localeStr = json['locale'] as String;
final option = json['option'] as String;

final returnJson = <String, dynamic>{'label': label};

try {
final locale = icu.Locale.fromString(localeStr);
final expander = icu.LocaleExpander.extended();

if (option == 'maximize') {
expander.maximize(locale);
} else if (option == 'minimize' || option == 'minimizeFavorRegion') {
expander.minimize(locale);
} else if (option == 'minimizeFavorScript') {
expander.minimizeFavorScript(locale);
} else {
returnJson['error_type'] = 'unsupported';
returnJson['unsupported'] = 'Unknown option: $option';
return jsonEncode(returnJson);
}

returnJson['result'] = locale.toString();
} catch (e) {
returnJson['error'] = e.toString();
}

return jsonEncode(returnJson);
}
36 changes: 36 additions & 0 deletions executors/dart/lib/likely_subtags_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'dart:convert';
import 'dart:js_interop';

@JS('Intl.Locale')
extension type _LocaleJS._(JSObject _) implements JSObject {
external factory _LocaleJS(String s);
external _LocaleJS minimize();
external _LocaleJS maximize();
external String get baseName;
}

String testLikelySubtagsImpl(String jsonEncoded) {
final json = jsonDecode(jsonEncoded) as Map<String, dynamic>;
final label = json['label'];
final localeStr = json['locale'] as String;
final option = json['option'] as String;

final returnJson = <String, dynamic>{'label': label};

try {
final locale = _LocaleJS(localeStr);
if (option == 'maximize') {
returnJson['result'] = locale.maximize().baseName;
} else if (option == 'minimize' || option == 'minimizeFavorRegion') {
returnJson['result'] = locale.minimize().baseName;
} else {
returnJson['error_type'] = 'unsupported';
returnJson['unsupported'] = 'Option $option not supported on web';
return jsonEncode(returnJson);
}
} catch (e) {
returnJson['error'] = e.toString();
}

return jsonEncode(returnJson);
}
2 changes: 1 addition & 1 deletion executors/dart/lib/version.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// This file is autogenerated by bin/set_version.dart, do not modify manually.
const intl4xVersion = '0.17.0';
const intl4xVersion = '1.0.0-alpha.1';
4 changes: 4 additions & 0 deletions executors/dart/out/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ let datetime_fmt = require('./datetimeformat.js');

let list_fmt = require('./list_format.js');

let likely_subtags = require('./likely_subtags.js');

const { dartVersion } = require('./version.js')

/**
Expand Down Expand Up @@ -144,6 +146,8 @@ rl.on('line', function (line) {
outputLine = datetime_fmt.testDateTimeFmt(parsedJson, doLogInput > 0, process.version);
} else if (test_type == "list_fmt") {
outputLine = list_fmt.testListFmt(parsedJson);
} else if (test_type == "likely_subtags") {
outputLine = likely_subtags.testLikelySubtags(parsedJson);
} else {
outputLine = {
'error': 'unknown test type', 'testId': testId,
Expand Down
6 changes: 6 additions & 0 deletions executors/dart/out/likely_subtags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var tools = require('./likely_subtagsDart');
module.exports = {
testLikelySubtags: function (json) {
return JSON.parse(tools.testLikelySubtags(JSON.stringify(json)));
}
};
2 changes: 1 addition & 1 deletion executors/dart/out/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const dartVersion = "0.17.0";
const dartVersion = "1.0.0-alpha.1";
module.exports = { dartVersion };
Loading
Loading