Skip to content
Merged
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
39 changes: 26 additions & 13 deletions executors/node/plural_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,38 @@ module.exports = {
test_options['type'] = plural_type;
}

let actual_locale;
try {
const supported_locales =
Intl.PluralRules.supportedLocalesOf(locale, test_options);

if (!supported_locales.includes(locale)) {

return {"label": label,
"error" : "unusupported",
"unsupported": "unsupported_locale",
"error_detail": {'unsupported_locale': locale,
'supported_locals': supported_locales,
'test_options': test_options
}
};
if (supported_locales.includes(locale)) {
actual_locale = locale;
} else {
if (supported_locales) {
actual_locale = supported_locales[0];
}
if (actual_locale == undefined) {
// No, there's no good substitute.
Comment on lines 48 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is more complex than it needs to be, but I believe it is technically correct.

return {"label": label,
"error" : "unusupported",
"unsupported": "unsupported_locale",
"error_detail": {'unsupported_locale': locale,
'supported_locals': supported_locales,
'test_options': test_options
}
};
}
}
} catch (error) {
// Ignore for now.
/* Something is wrong with supporteLocalesOf */
return_json['error'] = 'supporteLocalesOf: ' + error.message;
return_json['options'] = test_options;
return return_json;
}

let list_formatter;
try {
p_rules = new Intl.PluralRules(locale, test_options);
p_rules = new Intl.PluralRules(actual_locale, test_options);
} catch (error) {
/* Something is wrong with the constructor */
return_json['error'] = 'CONSTRUCTOR: ' + error.message;
Expand All @@ -80,6 +90,9 @@ module.exports = {
return_json['error'] =
'PLURAL RULES UNKNOWN ERROR: ' + error.message;
}
if (actual_locale != locale) {
return_json['actual_locale'] = actual_locale;
}
return return_json;
}
}
4 changes: 4 additions & 0 deletions schema/plural_rules/result_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"input_data": {
"type": "string",
"description": "Information provided to the executor"
},
"actual_locale": {
"type": "string",
"description": "If present, the substitute locale actually used in the test"
}
}
},
Expand Down
Loading