Skip to content

Commit 5608454

Browse files
authored
Update package:intl4x for Dart (#541)
1 parent 14e07e6 commit 5608454

File tree

13 files changed

+435
-339
lines changed

13 files changed

+435
-339
lines changed

executors/dart/bin/executor.dart

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,36 @@ void main() {
4747
} catch (e) {
4848
throw 'ERRORSTART $line ERROREND';
4949
}
50-
51-
final testType = TestTypes.values.firstWhereOrNull(
52-
(type) => type.name == decoded['test_type'],
53-
);
54-
final outputLine = switch (testType) {
55-
TestTypes.collation => testCollation(line),
56-
TestTypes.decimal_fmt => testDecimalFormatWrapped(line),
57-
TestTypes.number_fmt => testDecimalFormatWrapped(line),
58-
TestTypes.datetime_fmt => testDateTimeFmt(line),
59-
TestTypes.display_names => throw UnimplementedError(
60-
'display_names is not supported yet',
61-
),
62-
TestTypes.lang_names => testLangNames(line),
63-
// TestTypes.likely_subtags => testLikelySubtags(line),
64-
TestTypes.likely_subtags => throw UnimplementedError(
65-
'likely_subtags is not supported yet, as the Locale object is not yet migrated to ICU4X',
66-
),
67-
TestTypes.list_fmt => testListFmt(line),
68-
TestTypes.plural_rules => testPluralRules(line),
69-
null => throw ArgumentError.value(
70-
decoded['test_type'],
71-
'Unknown test type',
72-
),
73-
};
74-
75-
print(outputLine);
50+
try {
51+
final testType = TestTypes.values.firstWhereOrNull(
52+
(type) => type.name == decoded['test_type'],
53+
);
54+
final outputLine = switch (testType) {
55+
TestTypes.collation => testCollation(line),
56+
TestTypes.decimal_fmt => testDecimalFormatWrapped(line),
57+
TestTypes.number_fmt => testDecimalFormatWrapped(line),
58+
TestTypes.datetime_fmt => testDateTimeFmt(line),
59+
TestTypes.display_names => throw UnimplementedError(
60+
'display_names is not supported yet',
61+
),
62+
TestTypes.lang_names => testLangNames(line),
63+
// TestTypes.likely_subtags => testLikelySubtags(line),
64+
TestTypes.likely_subtags => throw UnimplementedError(
65+
'likely_subtags is not supported yet, as the Locale object is not yet migrated to ICU4X',
66+
),
67+
TestTypes.list_fmt => testListFmt(line),
68+
TestTypes.plural_rules => testPluralRules(line),
69+
null => throw ArgumentError.value(
70+
decoded['test_type'],
71+
'Unknown test type',
72+
),
73+
};
74+
print(outputLine);
75+
} catch (e, s) {
76+
throw ArgumentError(
77+
'Error while executing on $line. Error was:\n $e \n $s',
78+
);
79+
}
7680
}
7781
}
7882
}

executors/dart/lib/collator.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import 'dart:convert';
44

55
import 'package:intl4x/collation.dart';
6-
import 'package:intl4x/intl4x.dart';
76

87
String testCollation(String jsonEncoded) {
98
final json = jsonDecode(jsonEncoded) as Map<String, dynamic>;
@@ -52,16 +51,13 @@ String testCollation(String jsonEncoded) {
5251
});
5352
} else {
5453
try {
55-
final coll = Intl(locale: Locale.parse(localeString));
56-
57-
final collationOptions = CollationOptions(
54+
final compared = Collation(
55+
locale: Locale.parse(localeString),
5856
ignorePunctuation: ignorePunctuation,
5957
sensitivity: sensitivity,
6058
numeric: numeric,
6159
caseFirst: caseFirst,
62-
);
63-
64-
final compared = coll.collation(collationOptions).compare(s1, s2);
60+
).compare(s1, s2);
6561

6662
bool result;
6763
if (compareType == '=') {
@@ -91,3 +87,14 @@ String testCollation(String jsonEncoded) {
9187
}
9288
return jsonEncode(outputLine);
9389
}
90+
91+
// Copied from intl4x/lib/src/collation/collation_ecma.dart
92+
extension on CaseFirst {
93+
/// The JavaScript-compatible string representation of the case first option.
94+
String get jsName => switch (this) {
95+
// Map the custom name 'localeDependent' to 'false'.
96+
CaseFirst.localeDependent => 'false',
97+
// All other cases implicitly use the enum's name (e.g., 'upper', 'lower').
98+
_ => name,
99+
};
100+
}

0 commit comments

Comments
 (0)