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
8 changes: 4 additions & 4 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ on:
branches: [main]
paths:
- ".github/workflows/dart.yaml"
- "executors/dart**"
- "executors/dart/**"
push:
branches: [main]
paths:
- ".github/workflows/dart.yaml"
- "executors/dart**"
- "executors/dart/**"
schedule:
- cron: "0 0 * * 0" # weekly

Expand All @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
steps:
- name: Install prerequisites
run: |
apt-get update && apt-get install -y sudo python3 wget unzip logrotate curl jq python3-requests python3-jsonschema build-essential clang maven
apt-get update && apt-get install -y sudo python3 wget unzip logrotate curl jq python3-requests python3-jsonschema build-essential clang maven git
- name: Free up some disk space
run: |
echo "Available storage before:"
Expand All @@ -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
10 changes: 3 additions & 7 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 @@ -56,14 +57,9 @@ void main() {
TestTypes.decimal_fmt => testDecimalFormatWrapped(line),
TestTypes.number_fmt => testDecimalFormatWrapped(line),
TestTypes.datetime_fmt => testDateTimeFmt(line),
TestTypes.display_names => throw UnimplementedError(
'display_names is not supported yet',
),
TestTypes.display_names => testLangNames(line),
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);
}
32 changes: 21 additions & 11 deletions executors/dart/lib/datetime_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,26 @@ String testDateTimeFmt(String jsonEncoded) {
locale,
timePrecision,
);
final offset = offsetSeconds != null
? Duration(seconds: offsetSeconds)
: Duration.zero;
final dateToFormat = testDate!.add(offset);

final isZoned =
formatter is DateTimeFormatter &&
timeZoneName != null &&
((semanticSkeleton ?? '').contains('Z') ||
timeStyle == 'full' ||
testOptionsJson.containsKey('zoneStyle') ||
(skeleton != null && RegExp(r'[zvOV]').hasMatch(skeleton)));

String formattedDt;
if (formatter is DateTimeFormatter &&
(semanticSkeleton ?? '').contains('Z')) {
final offset = Duration(seconds: offsetSeconds!);
if (isZoned) {
final zoneStyle = testOptionsJson['zoneStyle'] as String?;
final zonedFormatter = getZonedFormatter(zoneStyle, formatter, skeleton);
formattedDt = zonedFormatter.format(testDate!.add(offset), timeZoneName!);
formattedDt = zonedFormatter.format(dateToFormat, timeZoneName);
} else {
formattedDt = formatter.format(testDate!);
formattedDt = formatter.format(dateToFormat);
}
returnJson['result'] = formattedDt;
} on Exception catch (e) {
Expand All @@ -137,8 +148,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 Expand Up @@ -234,11 +245,11 @@ ZonedDateTimeFormatter getZonedFormatter(
return switch (timeZoneStyle) {
'short' => formatter.withTimeZoneShort(),
'specific' => formatter.withTimeZoneShort(),
'full' => formatter.withTimeZoneLongGeneric(),
'full' => formatter.withTimeZoneLong(),
'generic' => formatter.withTimeZoneLongGeneric(),
'location' => formatter.withTimeZoneShort(),
'offset' => formatter.withTimeZoneLongGeneric(),
null => formatter.withTimeZoneLongGeneric(),
'offset' => formatter.withTimeZoneLongOffset(),
null => formatter.withTimeZoneLong(),
String() => throw Exception('Unknown time zone style `$timeZoneStyle`'),
};
}
Expand All @@ -250,7 +261,6 @@ DateTimeFormatter getFormatterForStyle(
Locale locale,
TimePrecision? timePrecision,
) {
print((dateStyle, timeStyle, yearStyle));
return switch ((dateStyle, timeStyle, yearStyle)) {
('medium', null, null) => DateTimeFormat.yearMonthDay(
locale: locale,
Expand Down
29 changes: 29 additions & 0 deletions executors/dart/lib/likely_subtags.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:convert';

import 'package:intl4x/locale.dart';

String testLikelySubtags(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 = Locale.parse(localeStr);
if (option == 'maximize') {
returnJson['result'] = locale.maximize().toLanguageTag();
} else if (option == 'minimize' || option == 'minimizeFavorRegion') {
returnJson['result'] = locale.minimize().toLanguageTag();
} else {
returnJson['error_type'] = 'unsupported';
returnJson['unsupported'] = 'Option $option not supported';
return jsonEncode(returnJson);
}
} catch (e) {
returnJson['error'] = e.toString();
}

return jsonEncode(returnJson);
}
12 changes: 10 additions & 2 deletions executors/dart/lib/plural_rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@ String testPluralRules(String jsonEncoded) {
: PluralRules(locale: locale);

try {
final result = pluralRules.select(sample);
returnJson['result'] = result.name;
final result = pluralRules.select(
sample,
zero: 'zero',
one: 'one',
two: 'two',
few: 'few',
many: 'many',
other: 'other',
);
returnJson['result'] = result;
} catch (error) {
returnJson['error'] = 'PLURAL RULES UNKNOWN ERROR: ${error.toString()}';
}
Expand Down
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.3-wip';
6 changes: 5 additions & 1 deletion 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 @@ -136,14 +138,16 @@ rl.on('line', function (line) {
outputLine = collator.testCollation(parsedJson);
} else if (test_type == "decimal_fmt" || test_type == "number_fmt") {
outputLine = numberformatter.testDecimalFormat(parsedJson, doLogInput > 0, process.version);
} else if (test_type == "language_display_name" || test_type == "lang_names") {
} else if (test_type == "language_display_name" || test_type == "lang_names" || test_type == "display_names") {
outputLine = lang_names.testLangNames(parsedJson);
} else if (test_type == "plural_rules") {
outputLine = plural_rules.testPluralRules(parsedJson);
} else if (test_type == "datetime_fmt") {
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.3-wip";
module.exports = { dartVersion };
Loading
Loading