@cognigy/rest-api-client
Version:
Cognigy REST-Client
33 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLanguageName = void 0;
/**
* Returns the simplified english name for a language given a language code
*
* Example:
* getLanguageName("de-DE") => "German"
* getLanguageName("en-GB") => "English"
* getLanguageName("nl-BE") => "Dutch"
*
* For reference, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#using_type_language_with_languagedisplay
*/
const getLanguageName = (languageCode) => {
// remove the "region" part from language codes (e.g. en-US becomes en, the -US gets stripped)
const languageOnly = languageCode.split("-")[0];
// our runtimes support this, but it's not reflected in every project's typings!
// this flag is used to reset a breaking-change behavior (returning "flamish" instead of "dutch (belgium)") to its former behavior
// @ts-ignore
const languageName = new Intl.DisplayNames(["en-US"], {
// @ts-ignore
type: "language",
// @ts-ignore
languageDisplay: "standard",
// @ts-ignore
fallback: "none",
// @ts-ignore
}).of(languageOnly);
return languageName;
};
exports.getLanguageName = getLanguageName;
//# sourceMappingURL=getLanguageName.helper.js.map