mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Added i18n tests.
This commit is contained in:
@@ -9,14 +9,12 @@ var fs = require("fs");
|
|||||||
var event_stream_1 = require("event-stream");
|
var event_stream_1 = require("event-stream");
|
||||||
var File = require("vinyl");
|
var File = require("vinyl");
|
||||||
var Is = require("is");
|
var Is = require("is");
|
||||||
var util = require('gulp-util');
|
|
||||||
var xml2js = require("xml2js");
|
var xml2js = require("xml2js");
|
||||||
var glob = require("glob");
|
var glob = require("glob");
|
||||||
var util = require('gulp-util');
|
var util = require('gulp-util');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var es = require('event-stream');
|
var es = require('event-stream');
|
||||||
var iconv = require('iconv-lite');
|
var iconv = require('iconv-lite');
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
var rest = [];
|
var rest = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _i = 1; _i < arguments.length; _i++) {
|
||||||
@@ -44,7 +42,6 @@ var BundledFormat;
|
|||||||
}
|
}
|
||||||
BundledFormat.is = is;
|
BundledFormat.is = is;
|
||||||
})(BundledFormat || (BundledFormat = {}));
|
})(BundledFormat || (BundledFormat = {}));
|
||||||
|
|
||||||
var PackageJsonFormat;
|
var PackageJsonFormat;
|
||||||
(function (PackageJsonFormat) {
|
(function (PackageJsonFormat) {
|
||||||
function is(value) {
|
function is(value) {
|
||||||
@@ -148,7 +145,7 @@ var XLF = (function () {
|
|||||||
//throw new Error('No item ID or value specified.');
|
//throw new Error('No item ID or value specified.');
|
||||||
}
|
}
|
||||||
this.appendNewLine("<trans-unit id=\"" + item.id + "\">", 4);
|
this.appendNewLine("<trans-unit id=\"" + item.id + "\">", 4);
|
||||||
this.appendNewLine("<source xml:lang=\"en\">" + encodeEntities(item.message) + "</source>", 6);
|
this.appendNewLine("<source xml:lang=\"en\">" + item.message + "</source>", 6);
|
||||||
if (item.comment) {
|
if (item.comment) {
|
||||||
this.appendNewLine("<note>" + item.comment + "</note>", 6);
|
this.appendNewLine("<note>" + item.comment + "</note>", 6);
|
||||||
}
|
}
|
||||||
@@ -211,7 +208,6 @@ XLF.parse = function (xlfString) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
exports.XLF = XLF;
|
exports.XLF = XLF;
|
||||||
|
|
||||||
var vscodeLanguages = [
|
var vscodeLanguages = [
|
||||||
'chs',
|
'chs',
|
||||||
'cht',
|
'cht',
|
||||||
@@ -243,7 +239,6 @@ var iso639_3_to_2 = {
|
|||||||
'sve': 'sv-se',
|
'sve': 'sv-se',
|
||||||
'trk': 'tr'
|
'trk': 'tr'
|
||||||
};
|
};
|
||||||
|
|
||||||
var iso639_2_to_3 = {
|
var iso639_2_to_3 = {
|
||||||
'zh-cn': 'chs',
|
'zh-cn': 'chs',
|
||||||
'zh-tw': 'cht',
|
'zh-tw': 'cht',
|
||||||
@@ -264,7 +259,6 @@ var iso639_2_to_3 = {
|
|||||||
'sv-se': 'sve',
|
'sv-se': 'sve',
|
||||||
'tr': 'trk'
|
'tr': 'trk'
|
||||||
};
|
};
|
||||||
|
|
||||||
function sortLanguages(directoryNames) {
|
function sortLanguages(directoryNames) {
|
||||||
return directoryNames.map(function (dirName) {
|
return directoryNames.map(function (dirName) {
|
||||||
var lower = dirName.toLowerCase();
|
var lower = dirName.toLowerCase();
|
||||||
@@ -316,7 +310,6 @@ function stripComments(content) {
|
|||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
function escapeCharacters(value) {
|
function escapeCharacters(value) {
|
||||||
var result = [];
|
var result = [];
|
||||||
for (var i = 0; i < value.length; i++) {
|
for (var i = 0; i < value.length; i++) {
|
||||||
@@ -485,7 +478,6 @@ function processNlsFiles(opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.processNlsFiles = processNlsFiles;
|
exports.processNlsFiles = processNlsFiles;
|
||||||
|
|
||||||
function prepareXlfFiles(projectName, extensionName) {
|
function prepareXlfFiles(projectName, extensionName) {
|
||||||
return event_stream_1.through(function (file) {
|
return event_stream_1.through(function (file) {
|
||||||
if (!file.isBuffer()) {
|
if (!file.isBuffer()) {
|
||||||
@@ -541,6 +533,7 @@ function getResource(sourceFile) {
|
|||||||
}
|
}
|
||||||
throw new Error("Could not identify the XLF bundle for " + sourceFile);
|
throw new Error("Could not identify the XLF bundle for " + sourceFile);
|
||||||
}
|
}
|
||||||
|
exports.getResource = getResource;
|
||||||
function importBundleJson(file, json, stream) {
|
function importBundleJson(file, json, stream) {
|
||||||
var transifexEditorXlfs = Object.create(null);
|
var transifexEditorXlfs = Object.create(null);
|
||||||
for (var source in json.keys) {
|
for (var source in json.keys) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ interface Item {
|
|||||||
comment: string;
|
comment: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Resource {
|
export interface Resource {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
project: string;
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ export class XLF {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
|
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
|
||||||
this.appendNewLine(`<source xml:lang="en">${encodeEntities(item.message)}</source>`, 6);
|
this.appendNewLine(`<source xml:lang="en">${item.message}</source>`, 6);
|
||||||
|
|
||||||
if (item.comment) {
|
if (item.comment) {
|
||||||
this.appendNewLine(`<note>${item.comment}</note>`, 6);
|
this.appendNewLine(`<note>${item.comment}</note>`, 6);
|
||||||
@@ -570,7 +570,7 @@ export function prepareXlfFiles(projectName?: string, extensionName?: string): T
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResource(sourceFile: string): Resource {
|
export function getResource(sourceFile: string): Resource {
|
||||||
const editorProject: string = 'vscode-editor',
|
const editorProject: string = 'vscode-editor',
|
||||||
workbenchProject: string = 'vscode-workbench';
|
workbenchProject: string = 'vscode-workbench';
|
||||||
let resource: string;
|
let resource: string;
|
||||||
|
|||||||
41
build/lib/test/i18n.test.js
Normal file
41
build/lib/test/i18n.test.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
var assert = require("assert");
|
||||||
|
var i18n = require("../i18n");
|
||||||
|
suite('XLF Parser Tests', function () {
|
||||||
|
var sampleXlf = '<?xml version="1.0" encoding="utf-8"?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"><file original="vs/base/common/keybinding" source-language="en" datatype="plaintext"><body><trans-unit id="key1"><source xml:lang="en">Key #1</source></trans-unit><trans-unit id="key2"><source xml:lang="en">Key #2 &</source></trans-unit></body></file></xliff>';
|
||||||
|
var sampleTranslatedXlf = '<?xml version="1.0" encoding="utf-8"?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"><file original="vs/base/common/keybinding" source-language="en" target-language="ru" datatype="plaintext"><body><trans-unit id="key1"><source xml:lang="en">Key #1</source><target>Кнопка #1</target></trans-unit><trans-unit id="key2"><source xml:lang="en">Key #2 &</source><target>Кнопка #2 &</target></trans-unit></body></file></xliff>';
|
||||||
|
var originalFilePath = 'vs/base/common/keybinding';
|
||||||
|
var keys = ['key1', 'key2'];
|
||||||
|
var messages = ['Key #1', 'Key #2 &'];
|
||||||
|
var translatedMessages = { key1: 'Кнопка #1', key2: 'Кнопка #2 &' };
|
||||||
|
test('Keys & messages to XLF conversion', function () {
|
||||||
|
var xlf = new i18n.XLF('vscode-workbench');
|
||||||
|
xlf.addFile(originalFilePath, keys, messages);
|
||||||
|
var xlfString = xlf.toString();
|
||||||
|
assert.strictEqual(xlfString.replace(/\s{2,}/g, ''), sampleXlf);
|
||||||
|
});
|
||||||
|
test('XLF to keys & messages conversion', function () {
|
||||||
|
i18n.XLF.parse(sampleTranslatedXlf).then(function (resolvedFiles) {
|
||||||
|
assert.deepEqual(resolvedFiles[0].messages, translatedMessages);
|
||||||
|
assert.strictEqual(resolvedFiles[0].originalFilePath, originalFilePath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test('JSON file source path to Transifex resource match', function () {
|
||||||
|
var editorProject = 'vscode-editor', workbenchProject = 'vscode-workbench';
|
||||||
|
var platform = { name: 'vs/platform', project: editorProject }, editorContrib = { name: 'vs/editor/contrib', project: editorProject }, editor = { name: 'vs/editor', project: editorProject }, base = { name: 'vs/base', project: editorProject }, code = { name: 'vs/code', project: workbenchProject }, workbenchParts = { name: 'vs/workbench/parts/html', project: workbenchProject }, workbenchServices = { name: 'vs/workbench/services/files', project: workbenchProject }, workbench = { name: 'vs/workbench', project: workbenchProject };
|
||||||
|
assert.deepEqual(i18n.getResource('vs/platform/actions/browser/menusExtensionPoint'), platform);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/editor/contrib/clipboard/browser/clipboard'), editorContrib);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/editor/common/modes/modesRegistry'), editor);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/base/common/errorMessage'), base);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/code/electron-main/window'), code);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/parts/html/browser/webview'), workbenchParts);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/services/files/node/fileService'), workbenchServices);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/browser/parts/panel/panelActions'), workbench);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=i18n.test.js.map
|
||||||
54
build/lib/test/i18n.test.ts
Normal file
54
build/lib/test/i18n.test.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import assert = require('assert');
|
||||||
|
import i18n = require('../i18n');
|
||||||
|
|
||||||
|
suite('XLF Parser Tests', () => {
|
||||||
|
const sampleXlf = '<?xml version="1.0" encoding="utf-8"?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"><file original="vs/base/common/keybinding" source-language="en" datatype="plaintext"><body><trans-unit id="key1"><source xml:lang="en">Key #1</source></trans-unit><trans-unit id="key2"><source xml:lang="en">Key #2 &</source></trans-unit></body></file></xliff>';
|
||||||
|
const sampleTranslatedXlf = '<?xml version="1.0" encoding="utf-8"?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"><file original="vs/base/common/keybinding" source-language="en" target-language="ru" datatype="plaintext"><body><trans-unit id="key1"><source xml:lang="en">Key #1</source><target>Кнопка #1</target></trans-unit><trans-unit id="key2"><source xml:lang="en">Key #2 &</source><target>Кнопка #2 &</target></trans-unit></body></file></xliff>';
|
||||||
|
const originalFilePath = 'vs/base/common/keybinding';
|
||||||
|
const keys = ['key1', 'key2'];
|
||||||
|
const messages = ['Key #1', 'Key #2 &'];
|
||||||
|
const translatedMessages = { key1: 'Кнопка #1', key2: 'Кнопка #2 &' };
|
||||||
|
|
||||||
|
test('Keys & messages to XLF conversion', () => {
|
||||||
|
let xlf = new i18n.XLF('vscode-workbench');
|
||||||
|
xlf.addFile(originalFilePath, keys, messages);
|
||||||
|
const xlfString = xlf.toString();
|
||||||
|
|
||||||
|
assert.strictEqual(xlfString.replace(/\s{2,}/g, ''), sampleXlf);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('XLF to keys & messages conversion', () => {
|
||||||
|
i18n.XLF.parse(sampleTranslatedXlf).then(function(resolvedFiles) {
|
||||||
|
assert.deepEqual(resolvedFiles[0].messages, translatedMessages);
|
||||||
|
assert.strictEqual(resolvedFiles[0].originalFilePath, originalFilePath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('JSON file source path to Transifex resource match', () => {
|
||||||
|
const editorProject: string = 'vscode-editor',
|
||||||
|
workbenchProject: string = 'vscode-workbench';
|
||||||
|
|
||||||
|
const platform: i18n.Resource = { name: 'vs/platform', project: editorProject },
|
||||||
|
editorContrib = { name: 'vs/editor/contrib', project: editorProject },
|
||||||
|
editor = { name: 'vs/editor', project: editorProject },
|
||||||
|
base = { name: 'vs/base', project: editorProject },
|
||||||
|
code = { name: 'vs/code', project: workbenchProject },
|
||||||
|
workbenchParts = { name: 'vs/workbench/parts/html', project: workbenchProject },
|
||||||
|
workbenchServices = { name: 'vs/workbench/services/files', project: workbenchProject },
|
||||||
|
workbench = { name: 'vs/workbench', project: workbenchProject};
|
||||||
|
|
||||||
|
assert.deepEqual(i18n.getResource('vs/platform/actions/browser/menusExtensionPoint'), platform);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/editor/contrib/clipboard/browser/clipboard'), editorContrib);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/editor/common/modes/modesRegistry'), editor);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/base/common/errorMessage'), base);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/code/electron-main/window'), code);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/parts/html/browser/webview'), workbenchParts);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/services/files/node/fileService'), workbenchServices);
|
||||||
|
assert.deepEqual(i18n.getResource('vs/workbench/browser/parts/panel/panelActions'), workbench);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user