Skip to content

Commit

Permalink
Fix some problems with dart_web lang_names (unicode-org#179)
Browse files Browse the repository at this point in the history
* Fix some problems with dart_web lang_names

* Update Dart versions and change locale string format slightly

* Some code in lang_names.dart

* Following PR#177

* Remove errant commas

* Revert data generator fix

---------

Co-authored-by: Elango Cheran <[email protected]>
  • Loading branch information
sven-oly and echeran authored Feb 21, 2024
1 parent 1802965 commit 2e78ad0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
46 changes: 31 additions & 15 deletions executors/dart_web/bin/lang_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ import 'package:intl4x/intl4x.dart';
String testLangNames(String jsonEncoded) {
final json = jsonDecode(jsonEncoded) as Map<String, dynamic>;

final outputLine = <String, dynamic>{};

final Locale locale;
if (json['locale_label'] != null) {
// Fix to use dash, not underscore.
final localeJson = json['locale_label'] as String;
locale = Locale.parse(localeJson.replaceAll('/_/g', '-'));
} else {
locale = Locale(language: 'en');
try {
if (json['locale_label'] != null) {
// Fix to use dash, not underscore.
final localeJson = json['locale_label'] as String;
locale = Locale.parse(localeJson.replaceAll('_', '-'));
} else {
locale = Locale(language: 'en');
}
} catch(error) {
outputLine.addAll({
'error': 'locale_label: ' + error.toString(),
'label': json['label'],
'test_type': 'display_names',
'error_type': 'unsupported',
'error_detail': 'locale_label',
'error_retry': false // Do not repeat
});
return jsonEncode(outputLine);
}

final languageLabel =
(json['language_label'] as String).replaceAll('/_/g', '-');
(json['language_label'] as String).replaceAll('_', '-');

final outputLine = <String, dynamic>{};
try {
final options = DisplayNamesOptions(
languageDisplay: LanguageDisplay.standard,
Expand All @@ -29,13 +43,15 @@ String testLangNames(String jsonEncoded) {
outputLine['result'] = resultLocale;
} catch (error) {
outputLine.addAll({
'error': error.toString(),
'label': json['label'],
'locale_label': locale.toLanguageTag(),
'language_label': languageLabel,
'test_type': 'display_names',
'error_type': 'unsupported',
'error_retry': false // Do not repeat
// 'error': error.toString() + " language_label:" + languageLabel,
'error': 'something went wrong: ' + error.toString(),
'label': json['label'],
'locale_label': locale.toLanguageTag(),
'language_label': languageLabel,
'test_type': 'display_names',
'error_type': 'unsupported',
'error_detail': languageLabel,
'error_retry': false // Do not repeat
});
}
return jsonEncode(outputLine);
Expand Down
10 changes: 7 additions & 3 deletions executors/dart_web/bin/make_runnable_by_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ Future<void> main(List<String> args) async {
name: 'testLikelySubtags',
argNames: ['encoded'],
),
};
for (var name in names.entries) {
await prepare(name.key, name.value);
'lang_names': ExportFunction(
name: 'testLangNames',
argNames: ['encoded'],
),
};
for (final MapEntry(key: name, value: function) in names.entries) {
await prepare(name, function);
}

setVersionFile();
Expand Down
2 changes: 1 addition & 1 deletion executors/dart_web/out/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const dartVersion = "0.7.0";
const dartVersion = "0.7.1";
module.exports = { dartVersion };
4 changes: 2 additions & 2 deletions executors/dart_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ environment:

# Add regular dependencies here.
dependencies:
intl4x: ^0.7.0
intl4x: ^0.7.1
pubspec_lock_parse: ^2.2.0

dev_dependencies:
lints: ^3.0.0
test: ^1.21.0
test: ^1.25.2
6 changes: 5 additions & 1 deletion schema/language_names/result_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"label": {
"description": "A numeric ID, unique for the set of tests",
Expand Down Expand Up @@ -99,6 +99,10 @@
"type": "string",
"description": "additional error info"
},
"error_retry": {
"type": "boolean",
"description": "additional error info"
},
"test_type": {
"description": "the type of this test",
"type": "string",
Expand Down

0 comments on commit 2e78ad0

Please sign in to comment.