提交 77082177 编写于 作者: D Dirk Baeumer

Fixes #48404: Perfer language packs over built in languages even for core languages

上级 118c3bf4
......@@ -280,111 +280,112 @@ function getNLSConfiguration(locale) {
return undefined;
}
let isCoreLanguage = true;
if (locale) {
isCoreLanguage = ['de', 'es', 'fr', 'it', 'ja', 'ko', 'ru', 'zh-cn', 'zh-tw'].some((language) => {
return locale === language || locale.startsWith(language + '-');
});
}
if (isCoreLanguage) {
return Promise.resolve(resolveLocale(locale));
} else {
perf.mark('nlsGeneration:start');
let defaultResult = function() {
perf.mark('nlsGeneration:start');
let defaultResult = function(locale) {
let isCoreLanguage = true;
if (locale) {
isCoreLanguage = ['de', 'es', 'fr', 'it', 'ja', 'ko', 'ru', 'zh-cn', 'zh-tw'].some((language) => {
return locale === language || locale.startsWith(language + '-');
});
}
if (isCoreLanguage) {
let result = resolveLocale(locale);
perf.mark('nlsGeneration:end');
return Promise.resolve(result);
} else {
perf.mark('nlsGeneration:end');
return Promise.resolve({ locale: locale, availableLanguages: {} });
};
try {
let commit = getCommit();
if (!commit) {
return defaultResult();
}
let configs = getLanguagePackConfigurations();
if (!configs) {
return defaultResult();
}
let initialLocale = locale;
locale = resolveLanguagePackLocale(configs, locale);
if (!locale) {
return defaultResult();
}
let packConfig = configs[locale];
let mainPack;
if (!packConfig || typeof packConfig.hash !== 'string' || !packConfig.translations || typeof (mainPack = packConfig.translations['vscode']) !== 'string') {
return defaultResult();
}
};
try {
let commit = getCommit();
if (!commit) {
return defaultResult(locale);
}
let configs = getLanguagePackConfigurations();
if (!configs) {
return defaultResult(locale);
}
let initialLocale = locale;
locale = resolveLanguagePackLocale(configs, locale);
if (!locale) {
return defaultResult(initialLocale);
}
let packConfig = configs[locale];
let mainPack;
if (!packConfig || typeof packConfig.hash !== 'string' || !packConfig.translations || typeof (mainPack = packConfig.translations['vscode']) !== 'string') {
return defaultResult(locale);
}
return exists(mainPack).then((fileExists) => {
if (!fileExists) {
return defaultResult(locale);
}
return exists(mainPack).then((fileExists) => {
if (!fileExists) {
return defaultResult();
let packId = packConfig.hash + '.' + locale;
let cacheRoot = path.join(userData, 'clp', packId);
let coreLocation = path.join(cacheRoot, commit);
let translationsConfigFile = path.join(cacheRoot, 'tcf.json');
let result = {
locale: initialLocale,
availableLanguages: { '*': locale },
_languagePackId: packId,
_translationsConfigFile: translationsConfigFile,
_cacheRoot: cacheRoot,
_resolvedLanguagePackCoreLocation: coreLocation
};
return exists(coreLocation).then((fileExists) => {
if (fileExists) {
// We don't wait for this. No big harm if we can't touch
touch(coreLocation).catch(() => {});
perf.mark('nlsGeneration:end');
return result;
}
let packId = packConfig.hash + '.' + locale;
let cacheRoot = path.join(userData, 'clp', packId);
let coreLocation = path.join(cacheRoot, commit);
let translationsConfigFile = path.join(cacheRoot, 'tcf.json');
let result = {
locale: initialLocale,
availableLanguages: { '*': locale },
_languagePackId: packId,
_translationsConfigFile: translationsConfigFile,
_cacheRoot: cacheRoot,
_resolvedLanguagePackCoreLocation: coreLocation
};
return exists(coreLocation).then((fileExists) => {
if (fileExists) {
// We don't wait for this. No big harm if we can't touch
touch(coreLocation).catch(() => {});
perf.mark('nlsGeneration:end');
return result;
}
return mkdirp(coreLocation).then(() => {
return Promise.all([readFile(path.join(__dirname, 'nls.metadata.json')), readFile(mainPack)]);
}).then((values) => {
let metadata = JSON.parse(values[0]);
let packData = JSON.parse(values[1]).contents;
let bundles = Object.keys(metadata.bundles);
let writes = [];
for (let bundle of bundles) {
let modules = metadata.bundles[bundle];
let target = Object.create(null);
for (let module of modules) {
let keys = metadata.keys[module];
let defaultMessages = metadata.messages[module];
let translations = packData[module];
let targetStrings;
if (translations) {
targetStrings = [];
for (let i = 0; i < keys.length; i++) {
let elem = keys[i];
let key = typeof elem === 'string' ? elem : elem.key;
let translatedMessage = translations[key];
if (translatedMessage === undefined) {
translatedMessage = defaultMessages[i];
}
targetStrings.push(translatedMessage);
return mkdirp(coreLocation).then(() => {
return Promise.all([readFile(path.join(__dirname, 'nls.metadata.json')), readFile(mainPack)]);
}).then((values) => {
let metadata = JSON.parse(values[0]);
let packData = JSON.parse(values[1]).contents;
let bundles = Object.keys(metadata.bundles);
let writes = [];
for (let bundle of bundles) {
let modules = metadata.bundles[bundle];
let target = Object.create(null);
for (let module of modules) {
let keys = metadata.keys[module];
let defaultMessages = metadata.messages[module];
let translations = packData[module];
let targetStrings;
if (translations) {
targetStrings = [];
for (let i = 0; i < keys.length; i++) {
let elem = keys[i];
let key = typeof elem === 'string' ? elem : elem.key;
let translatedMessage = translations[key];
if (translatedMessage === undefined) {
translatedMessage = defaultMessages[i];
}
} else {
targetStrings = defaultMessages;
targetStrings.push(translatedMessage);
}
target[module] = targetStrings;
} else {
targetStrings = defaultMessages;
}
writes.push(writeFile(path.join(coreLocation, bundle.replace(/\//g, '!') + '.nls.json'), JSON.stringify(target)));
target[module] = targetStrings;
}
writes.push(writeFile(translationsConfigFile, JSON.stringify(packConfig.translations)));
return Promise.all(writes);
}).then(() => {
perf.mark('nlsGeneration:end');
return result;
}).catch((err) => {
console.error('Generating translation files failed.', err);
return defaultResult();
});
writes.push(writeFile(path.join(coreLocation, bundle.replace(/\//g, '!') + '.nls.json'), JSON.stringify(target)));
}
writes.push(writeFile(translationsConfigFile, JSON.stringify(packConfig.translations)));
return Promise.all(writes);
}).then(() => {
perf.mark('nlsGeneration:end');
return result;
}).catch((err) => {
console.error('Generating translation files failed.', err);
return defaultResult(locale);
});
});
} catch (err) {
console.error('Generating translation files failed.', err);
return defaultResult();
}
});
} catch (err) {
console.error('Generating translation files failed.', err);
return defaultResult(locale);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册