Skip to content

Commit

Permalink
Node and PluralRules: use supported locales in place of obsolete loca…
Browse files Browse the repository at this point in the history
…les (#380)
  • Loading branch information
sven-oly authored Jan 8, 2025
1 parent 88f347d commit 46539fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
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.
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

0 comments on commit 46539fc

Please sign in to comment.