MCPcopy Create free account
hub / github.com/facebook/Rapid / languageName

Method languageName

modules/core/LocalizationSystem.js:532–564  ·  view source on GitHub ↗

* languageName * Returns a display-ready string for a given language code * @param {string} code the language code (e.g. 'de') * @param {Object?} options see below * @return {string} the language string to display (e.g. "Deutsch (de)")

(code, options)

Source from the content-addressed store, hash-verified

530 * @return {string} the language string to display (e.g. "Deutsch (de)")
531 */
532 languageName(code, options) {
533 if (this._currLanguageNames[code]) { // name in locale language
534 // e.g. "German"
535 return this._currLanguageNames[code];
536 }
537
538 // sometimes we only want the local name
539 if (options && options.localOnly) return null;
540
541 const langInfo = this._languages[code];
542 if (langInfo) {
543 if (langInfo.nativeName) { // name in native language
544 // e.g. "Deutsch (de)"
545 return this.t('translate.language_and_code', { language: langInfo.nativeName, code: code });
546
547 } else if (langInfo.base && langInfo.script) {
548 const base = langInfo.base; // the code of the language this is based on
549
550 if (this._currLanguageNames[base]) { // base language name in locale language
551 const scriptCode = langInfo.script;
552 const script = this._currScriptNames[scriptCode] || scriptCode;
553 // e.g. "Serbian (Cyrillic)"
554 return this.t('translate.language_and_code', { language: this._currLanguageNames[base], code: script });
555
556 } else if (this._languages[base] && this._languages[base].nativeName) {
557 // e.g. "српски (sr-Cyrl)"
558 return this.t('translate.language_and_code', { language: this._languages[base].nativeName, code: code });
559 }
560 }
561 }
562
563 return code; // if not found, use the code
564 }
565
566
567 /**

Callers 4

makeGenericNameIssueFunction · 0.45
makeIncorrectNameIssueFunction · 0.45
showMoreFunction · 0.45
loadLanguagesArrayFunction · 0.45

Calls 1

tMethod · 0.95

Tested by

no test coverage detected