mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)
This commit is contained in:
@@ -20,19 +20,12 @@ function update(options) {
|
||||
if (!idOrPath) {
|
||||
throw new Error('Argument must be the location of the localization extension.');
|
||||
}
|
||||
let transifex = options.transifex;
|
||||
let location = options.location;
|
||||
if (transifex === true && location !== undefined) {
|
||||
throw new Error('Either --transifex or --location can be specified, but not both.');
|
||||
}
|
||||
if (!transifex && !location) {
|
||||
transifex = true;
|
||||
}
|
||||
if (location !== undefined && !fs.existsSync(location)) {
|
||||
throw new Error(`${location} doesn't exist.`);
|
||||
}
|
||||
let locExtFolder = idOrPath;
|
||||
if (/^\w{2}(-\w+)?$/.test(idOrPath)) {
|
||||
if (/^\w{2,3}(-\w+)?$/.test(idOrPath)) {
|
||||
locExtFolder = path.join('..', 'vscode-loc', 'i18n', `vscode-language-pack-${idOrPath}`);
|
||||
}
|
||||
let locExtStat = fs.statSync(locExtFolder);
|
||||
@@ -53,79 +46,55 @@ function update(options) {
|
||||
if (!localization.languageId || !localization.languageName || !localization.localizedLanguageName) {
|
||||
throw new Error('Each localization contribution must define "languageId", "languageName" and "localizedLanguageName" properties.');
|
||||
}
|
||||
let server = localization.server || 'www.transifex.com';
|
||||
let userName = localization.userName || 'api';
|
||||
let apiToken = process.env.TRANSIFEX_API_TOKEN;
|
||||
let languageId = localization.transifexId || localization.languageId;
|
||||
let languageId = localization.languageId;
|
||||
let translationDataFolder = path.join(locExtFolder, 'translations');
|
||||
if (languageId === "zh-cn") {
|
||||
languageId = "zh-hans";
|
||||
}
|
||||
if (languageId === "zh-tw") {
|
||||
languageId = "zh-hant";
|
||||
|
||||
switch (languageId) {
|
||||
case 'zh-cn':
|
||||
languageId = 'zh-Hans';
|
||||
break;
|
||||
case 'zh-tw':
|
||||
languageId = 'zh-Hant';
|
||||
break;
|
||||
case 'pt-br':
|
||||
languageId = 'pt-BR';
|
||||
break;
|
||||
}
|
||||
|
||||
if (fs.existsSync(translationDataFolder) && fs.existsSync(path.join(translationDataFolder, 'main.i18n.json'))) {
|
||||
console.log('Clearing \'' + translationDataFolder + '\'...');
|
||||
rimraf.sync(translationDataFolder);
|
||||
}
|
||||
|
||||
if (transifex) {
|
||||
console.log(`Downloading translations for ${languageId} to '${translationDataFolder}' ...`);
|
||||
let translationPaths = [];
|
||||
i18n.pullI18nPackFiles(server, userName, apiToken, { id: languageId }, translationPaths)
|
||||
.on('error', (error) => {
|
||||
console.log(`Error occurred while importing translations:`);
|
||||
translationPaths = undefined;
|
||||
if (Array.isArray(error)) {
|
||||
error.forEach(console.log);
|
||||
} else if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Unknown error');
|
||||
console.log(`Importing translations for ${languageId} form '${location}' to '${translationDataFolder}' ...`);
|
||||
let translationPaths = [];
|
||||
gulp.src(path.join(location, '**', languageId, '*.xlf'), { silent: false })
|
||||
.pipe(i18n.prepareI18nPackFiles(i18n.externalExtensionsWithTranslations, translationPaths, languageId === 'ps'))
|
||||
.on('error', (error) => {
|
||||
console.log(`Error occurred while importing translations:`);
|
||||
translationPaths = undefined;
|
||||
if (Array.isArray(error)) {
|
||||
error.forEach(console.log);
|
||||
} else if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Unknown error');
|
||||
}
|
||||
})
|
||||
.pipe(vfs.dest(translationDataFolder))
|
||||
.on('end', function () {
|
||||
if (translationPaths !== undefined) {
|
||||
localization.translations = [];
|
||||
for (let tp of translationPaths) {
|
||||
localization.translations.push({ id: tp.id, path: `./translations/${tp.resourceName}` });
|
||||
}
|
||||
})
|
||||
.pipe(vfs.dest(translationDataFolder))
|
||||
.on('end', function () {
|
||||
if (translationPaths !== undefined) {
|
||||
localization.translations = [];
|
||||
for (let tp of translationPaths) {
|
||||
localization.translations.push({ id: tp.id, path: `./translations/${tp.resourceName}`});
|
||||
}
|
||||
fs.writeFileSync(path.join(locExtFolder, 'package.json'), JSON.stringify(packageJSON, null, '\t'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(`Importing translations for ${languageId} form '${location}' to '${translationDataFolder}' ...`);
|
||||
let translationPaths = [];
|
||||
gulp.src(path.join(location, languageId, '**', '*.xlf'))
|
||||
.pipe(i18n.prepareI18nPackFiles(i18n.externalExtensionsWithTranslations, translationPaths, languageId === 'ps'))
|
||||
.on('error', (error) => {
|
||||
console.log(`Error occurred while importing translations:`);
|
||||
translationPaths = undefined;
|
||||
if (Array.isArray(error)) {
|
||||
error.forEach(console.log);
|
||||
} else if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Unknown error');
|
||||
}
|
||||
})
|
||||
.pipe(vfs.dest(translationDataFolder))
|
||||
.on('end', function () {
|
||||
if (translationPaths !== undefined) {
|
||||
localization.translations = [];
|
||||
for (let tp of translationPaths) {
|
||||
localization.translations.push({ id: tp.id, path: `./translations/${tp.resourceName}`});
|
||||
}
|
||||
fs.writeFileSync(path.join(locExtFolder, 'package.json'), JSON.stringify(packageJSON, null, '\t'));
|
||||
}
|
||||
});
|
||||
}
|
||||
fs.writeFileSync(path.join(locExtFolder, 'package.json'), JSON.stringify(packageJSON, null, '\t') + '\n');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (path.basename(process.argv[1]) === 'update-localization-extension.js') {
|
||||
var options = minimist(process.argv.slice(2), {
|
||||
boolean: 'transifex',
|
||||
string: 'location'
|
||||
});
|
||||
update(options);
|
||||
|
||||
Reference in New Issue
Block a user