arb-convert
Version:
Convert Application Resource Bundle (ARB) translation files to other translation formats and back
130 lines (129 loc) • 5.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../index");
var now = mockDateNow().now;
var arb = JSON.stringify({
'@@locale': 'en_US',
'@@last_modified': new Date(now).toISOString(),
simple: 'Super simple',
'@simple': {
description: '',
type: 'text',
placeholders: {},
},
}, null, 2);
var xliff1 = ''
+ '<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">\n'
+ ' <file original="some ns" datatype="plaintext" xml:space="preserve" source-language="en-US" date="2019-12-31T16:00:00.000Z">\n'
+ ' <body>\n'
+ ' <trans-unit id="simple">\n'
+ ' <source>Super simple</source>\n'
+ ' </trans-unit>\n'
+ ' </body>\n'
+ ' </file>\n'
+ '</xliff>';
var xliff2 = ''
+ '<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:2.0 http://docs.oasis-open.org/xliff/xliff-core/v2.1/cos02/schemas/xliff_core_2.0.xsd" xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US">\n'
+ ' <file id="arb" original="some ns" xml:space="preserve">\n'
+ ' <unit id="simple">\n'
+ ' <segment>\n'
+ ' <source>Super simple</source>\n'
+ ' </segment>\n'
+ ' </unit>\n'
+ ' </file>\n'
+ '</xliff>';
var gettext = ''
+ '# Translation converted from ARB\n'
+ '# original: some ns\n'
+ '# srcLang: en-US\n'
+ '# trgLang: \n'
+ 'msgid ""\n'
+ 'msgstr ""\n'
+ '"PO-Revision-Date: 2019-12-31 16:00+0000"\n'
+ '"MIME-Version: 1.0"\n'
+ '"Content-Type: text/plain; charset=UTF-8"\n'
+ '"Content-Transfer-Encoding: 8bit"\n'
+ '\n'
+ 'msgctxt "simple"\n'
+ 'msgid "Super simple"\n'
+ 'msgstr ""\n';
describe('converting from ARB', function () {
var options = {
original: 'some ns',
source: arb,
sourceLanguage: 'en-US',
};
test('converting to XLIFF 1.2', function () {
var result = {
content: xliff1,
};
expect(index_1.convertFromArb('xliff', options)).toEqual(result);
expect(index_1.convertFromArb('xliff-1.x', options)).toEqual(result);
expect(index_1.convertFromArb('xliff-1.2', options)).toEqual(result);
});
test('converting to XLIFF 2.1', function () {
var result = {
content: xliff2,
};
expect(index_1.convertFromArb('xliff-2.x', options)).toEqual(result);
expect(index_1.convertFromArb('xliff-2.0', options)).toEqual(result);
expect(index_1.convertFromArb('xliff-2.1', options)).toEqual(result);
});
test('converting to gettext PO', function () {
var result = {
content: gettext,
};
expect(index_1.convertFromArb('gettext', options)).toEqual(result);
});
test('converting to invalid format', function () {
expect(function () { return index_1.convertFromArb('invalid', options); }).toThrow('Format invalid is not supported');
});
});
describe('parsing to ARB', function () {
var result = {
original: 'some ns',
source: arb,
target: '',
sourceLanguage: 'en-US',
targetLanguage: '',
};
test('parsing XLIFF 1.2', function () {
var options = {
content: xliff1,
};
expect(index_1.parseToArb('xliff', options)).toEqual(result);
expect(index_1.parseToArb('xliff-1.x', options)).toEqual(result);
expect(index_1.parseToArb('xliff-1.2', options)).toEqual(result);
});
test('parsing XLIFF 2.1', function () {
var options = {
content: xliff2,
};
expect(index_1.parseToArb('xliff', options)).toEqual(result);
expect(index_1.parseToArb('xliff-2.x', options)).toEqual(result);
expect(index_1.parseToArb('xliff-2.0', options)).toEqual(result);
expect(index_1.parseToArb('xliff-2.1', options)).toEqual(result);
});
test('parsing unsupported XLIFF version', function () {
var options = {
content: '<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1"></xliff>',
};
expect(function () { return index_1.parseToArb('xliff', options); }).toThrow('Format xliff-1.1 is not supported');
expect(function () { return index_1.parseToArb('xliff-1.0', options); }).toThrow('Format xliff-1.0 is not supported');
expect(function () { return index_1.parseToArb('xliff-1.1', options); }).toThrow('Format xliff-1.1 is not supported');
// Malformed
expect(function () { return index_1.parseToArb('xliff', { content: '<xliff />' }); }).toThrow('Could not determine XLIFF version');
});
test('parsing gettext PO', function () {
var options = {
content: gettext,
};
expect(index_1.parseToArb('gettext', options)).toEqual(result);
});
test('parsing invalid format', function () {
var options = {
content: '',
};
expect(function () { return index_1.parseToArb('invalid', options); }).toThrow('Format invalid is not supported');
});
});