Reads from an source file the translation keys and their corresponding translation values and creates the xliff file (here).
Currently only csv is supported.
The MIT License. See the license file for details.
$ npm run build-dev # build module incl. source maps
$ npm run build # build module (for production - no source maps), run eslint and execute unit tests
$ npm test
$ npm install --save xliff-generator
'use strict';
const xliffGenerator = require('xliff-generator');
try {
xliffGenerator.createFromCsvSync({
csvFile: 'input/csvFile.csv',
productName: 'myProject',
printPretty: true,
csvDelimiter: ',',
csvComment: '',
csvEscape: '"',
csvQuote: '"',
languageOptions: [
{
isSourceLanguage: true,
languageKey: 'en',
output: 'output/xliff.en.xml'
},
{
languageKey: 'de',
output: 'output/xliff.de.xml'
}
]
});
} catch (err) {
// An error occured...
console.error(err);
}
'use strict';
const xliffGenerator = require('xliff-generator');
xliffGenerator.createFromCsv({
csvFile: 'input/csvFile.csv',
productName: 'myProject',
printPretty: true,
csvDelimiter: ',',
csvComment: '',
csvEscape: '"',
csvQuote: '"',
languageOptions: [
{
isSourceLanguage: true,
languageKey: 'en',
output: 'output/xliff.en.xml'
},
{
languageKey: 'de',
output: 'output/xliff.de.xml'
}
]
})
.then(() => {
// Successfully completed
}).catch((err) => {
// An error occured...
console.error(err);
});
Parameter | Mandatory | Default Value | Description |
---|---|---|---|
csvFile | yes | -- | Specify the path to the csv file |
productName | yes | -- | Specify the product name used in the resulting xlif file |
printPretty | no | false |
true if the resulting xml files should be printed pretty (see also here) |
csvDelimiter | no | ',' |
Specify the csv delimiter. Exactly one character has to be entered (see also here) |
csvComment | no | '' |
Specify the csv comment character. Zero or one character has to be entered (see also here) |
csvEscape | no | '"' |
Specify the csv escape character. Exactly one character has to be entered (see also here) |
csvQuote | no | '"' |
Specify the csv quote character. Exactly one character has to be entered (see also here) |
languageOptions | yes | -- | Specify the supported languages. Exactly one element has to be a source language (the boolean value of the parameter isSourceLanguage has to be true ) |
Parameter | Mandatory | Default Value | Description |
---|---|---|---|
isSourceLanguage | depends | false |
true if the language is a source language. See also parameter languageOptions |
languageKey | yes | -- | Specify the language key. See also at the structure of the csv file |
output | yes | -- | Specify the path where the resulting xml file of the language will be stored |
The first row of the csv file contains the header information. The first column of the header contains the translation id. The following colums contains the language keys e.g. en
, de
etc.. The values of the language keys have to match with the entered values of the keys in parameter languageOptions
.
The following rows after the header row contains per row exactly one translation value per language.
key,en,de
errorMessage.error1,Error message 1,Fehlermeldung 1
errorMessage.error2,Error message 2,Fehlermeldung 2
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xliff version="1.0">
<file datatype="plaintext" date="2018-06-11T22:55:35.935Z"
original="input/csvFile.csv" productname="myProject"
source-language="en" target-language="de">
<header/>
<body>
<trans-unit id="errorMessage.error1" xml:space="preserve">
<source>Error message 1</source>
<target>Fehlermeldung 1</target>
</trans-unit>
<trans-unit id="errorMessage.error2" xml:space="preserve">
<source>Error message 2</source>
<target>Fehlermeldung 2</target>
</trans-unit>
</body>
</file>
</xliff>