mirror of https://github.com/node-red/node-red.git
update monaco bootstrap for latest monaco
parent
a99cfaf653
commit
cc6cd0d51f
|
|
@ -1,26 +1,48 @@
|
|||
(function() {
|
||||
var _isIE = /MSIE \d|Trident.*rv:/.test(navigator.userAgent);
|
||||
//dont load monaco if IE
|
||||
if(_isIE === false) {
|
||||
var userLocale = (localStorage.getItem("editor-language") + "")
|
||||
var browserLocale = typeof navigator === "undefined" ? "" : (navigator.language || navigator.userLanguage || "");
|
||||
var cultureDists = {
|
||||
"zh-cn":"zh-hans",
|
||||
"zh-tw":"zh-hant",
|
||||
"ja":"ja",
|
||||
"ko":"ko",
|
||||
"de":"de",
|
||||
"fr":"fr",
|
||||
"it":"it",
|
||||
"es":"es",
|
||||
"ru":"ru",
|
||||
"tr":"tr",
|
||||
"pl":"pl",
|
||||
"pt-br":"pt-br",
|
||||
"cs":"cs"
|
||||
};
|
||||
var uiLanguage = cultureDists[userLocale.toLowerCase()] || cultureDists[browserLocale.toLowerCase()];
|
||||
if(uiLanguage) document.write('<script src="vendor/monaco/dist/locale/' + uiLanguage + '.js"><\/script>');
|
||||
document.write('<script src="vendor/monaco/dist/editor.js"><\/script>');
|
||||
(function () {
|
||||
// Supported/built-in Monaco locales as of v0.55.1
|
||||
// NOTES:
|
||||
// - 'en' is built-in (not a lang pack) so will not actually be loaded.
|
||||
// - 'es-es' is a listed language in the NR Language dropdown, however in the case where a user has set their
|
||||
// locale to 'es-mx' (or other spanish variant) we will default to 'es' in the getCultureDist helper function.
|
||||
// - 'zh-hans' & 'zh-hant' are not listed in the NR Language dropdown, but they are valid BCP 47 Chinese lanuages that
|
||||
// monaco supports. If the users navigator.language is set to one of these, we allow it since it is a monaco supported language.
|
||||
// - 'it', 'pl' and 'tr' are not listed in the NR Language dropdown, however they are supported by monaco, so we allow
|
||||
// that lang pack to be loaded when the user has set their browser locale to one of those languages.
|
||||
const langPacks = {
|
||||
'en': 'BUILT-IN',
|
||||
'cs': 'cs.js',
|
||||
'de': 'de.js',
|
||||
'es-es': 'es.js',
|
||||
'es': 'es.js', // fallback for other spanish variants such as es-mx. See notes above.
|
||||
'fr': 'fr.js',
|
||||
'it': 'it.js',
|
||||
'ja': 'ja.js',
|
||||
'ko': 'ko.js',
|
||||
'pl': 'pl.js',
|
||||
'pt-br': 'pt-br.js',
|
||||
'ru': 'ru.js',
|
||||
'tr': 'tr.js',
|
||||
'zh-cn': 'zh-cn.js',
|
||||
'zh-hans': 'zh-hans.js', // See notes above
|
||||
'zh-hant': 'zh-hant.js', // See notes above
|
||||
'zh-tw': 'zh-tw.js',
|
||||
}
|
||||
})();
|
||||
// Determine the UI language - first try full BCP 47 user setting, then its base language, then browser prefered language(s).
|
||||
const userLocale = (localStorage.getItem('editor-language') || '').toLowerCase()
|
||||
let langPack = langPacks[userLocale] || langPacks[userLocale.split('-')[0]] // try full locale, then base language
|
||||
if (!langPack && window.navigator) {
|
||||
const languages = navigator.languages || [navigator.language]
|
||||
for (let i = 0; i < languages.length; i++) {
|
||||
const lang = (languages[i] || '').toLowerCase()
|
||||
langPack = langPacks[lang] || langPacks[lang.split('-')[0]] // try full locale, then base language
|
||||
if (langPack) { break }
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a suitable language pack, add a script tag to load it (note 'en' is built-in)
|
||||
if (langPack && langPack !== 'BUILT-IN') {
|
||||
document.write('<script src="vendor/monaco/dist/locale/' + langPack + '"><\/script>')
|
||||
}
|
||||
document.write('<script src="vendor/monaco/dist/editor.js"><\/script>')
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in New Issue