Skip to content

Commit

Permalink
Node errors for locale display names to 'unsupported' (unicode-org#319)
Browse files Browse the repository at this point in the history
* Node errors for locale display names to 'unsupported'

* Set node locale names errors to unsupported

* NodeJS: set unsupported locales for locale display names

* Adding info to error messages

* Set display language problem to unsupported
  • Loading branch information
sven-oly authored Jan 6, 2025
1 parent 9f2e051 commit 61b4b84
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions executors/node/localedisplaynames.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,68 @@ module.exports = {

testLocaleDisplayNames: function (json) {
let locale = 'en'; // Default
let options = {};
if (json['locale_label']) {
// Fix to use dash, not underscore.
locale = json['locale_label'].replace(/_/g, '-');
}

// options = json['options'];
options = {type: 'language', languageDisplay: 'standard'};
// Standard for this type of testing.
let options = {type: 'language',
languageDisplay: 'standard',
style: 'long'};

let label = json['label'];
let input = json['language_label'].replace(/_/g, '-');
let outputLine = {
"label": json['label'],
"locale_label": locale,
"language_label": input,
};

try {
const supported_locales =
Intl.DisplayNames.supportedLocalesOf([locale]);
} catch (error) {
// Something wrong with the locale for this
outputLine["error_detail"] = locale
outputLine["error_type"] = 'unsupported locale';
outputLine["unsupported"] = error.toString();
return outputLine;
}

// Check the language to be formatted
try {
let language_label_locale = new Intl.Locale(input);
} catch (error) {
// Something wrong with the locale for this
outputLine["error_detail"] = input;
outputLine["error_type"] = 'Problem with language label';
outputLine["unsupported"] = error.toString();
outputLine["actual_options"] = JSON.stringify(options);
return outputLine;
}

if (json['languageDisplay']) {
// Fix to use dash, not underscore.
options['languageDisplay'] = json['languageDisplay'];
}

let outputLine;

let dn;
try {
dn = new Intl.DisplayNames([locale], options);
} catch (error) {
outputLine = {
"error": error.toString(),
"label": json['label'],
"locale_label": locale,
"language_label": input,
"test_type": "display_names",
"error_type": "unsupported",
"error_detail": "Bad constructor for locale: " + locale + ' ' + options,
"error_retry": false // Do not repeat
};
if (error instanceof RangeError) {
// The locale can't be handled for some reason!
outputLine["error_type"] = 'unsupported';
outputLine["unsupported"] = error.toString();
outputLine["error_detail"] = locale;
outputLine["actual_options"] = JSON.stringify(options);
}
return outputLine;
}

Expand All @@ -45,12 +76,15 @@ module.exports = {
"result": resultString
};
} catch (error) {
const error_string = error.toString();
outputLine = {"label": json['label'],
"locale_label": locale,
"language_label": input,
"result": resultString,
"error": error.toString(),
"actual_options": options.toString()
"error_type": 'unsupported',
"unsupported": error.toString(),
"error_detail": input,
"actual_options": JSON.stringify(options)
};
}
return outputLine;
Expand Down

0 comments on commit 61b4b84

Please sign in to comment.