1.0.0-beta.0 • Published 6 years ago

xliff-generator v1.0.0-beta.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

xliff-generator

Build Status Coverage Status License: MIT Dependency Status devDependency Status

https://nodei.co/npm/xliff-generator.png?downloads=true&downloadRank=true&stars=true

Reads from an source file the translation keys and their corresponding translation values and creates the xliff file (here).

Currently only csv is supported.

License

The MIT License. See the license file for details.

Build

$ 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

Testing

$ npm test

Install

$ npm install --save xliff-generator

Usage

sync

'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);
}

async

'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);
});

Parameters

ParameterMandatoryDefault ValueDescription
csvFileyes--Specify the path to the csv file
productNameyes--Specify the product name used in the resulting xlif file
printPrettynofalsetrue if the resulting xml files should be printed pretty (see also here)
csvDelimiterno','Specify the csv delimiter. Exactly one character has to be entered (see also here)
csvCommentno''Specify the csv comment character. Zero or one character has to be entered (see also here)
csvEscapeno'"'Specify the csv escape character. Exactly one character has to be entered (see also here)
csvQuoteno'"'Specify the csv quote character. Exactly one character has to be entered (see also here)
languageOptionsyes--Specify the supported languages. Exactly one element has to be a source language (the boolean value of the parameter isSourceLanguage has to be true)

Parameters: languageOptions

ParameterMandatoryDefault ValueDescription
isSourceLanguagedependsfalsetrue if the language is a source language. See also parameter languageOptions
languageKeyyes--Specify the language key. See also at the structure of the csv file
outputyes--Specify the path where the resulting xml file of the language will be stored

Structure of the csv file

Header

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.

Example

key,en,de
errorMessage.error1,Error message 1,Fehlermeldung 1
errorMessage.error2,Error message 2,Fehlermeldung 2

Example of a xml file

<?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>