1.0.0 • Published 3 years ago

transpoco-translation-library-ts v1.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
3 years ago

Transpoco Translation Library js

Transpoco translation library for Typescript to handle translations returned from Transpoco Translation API.

Usage

First it's necessary to load the translation table, for example:

import Translation from '@transpoco/transpoco-translation-library-ts';
// Example of a translation table returned from API
const translationTable = [
    {
        id: 14,
        code: 'Original',
        string: 'Original',
    }, {
        id: 15,
        code: 'Translation',
        string: 'Traduction',
    }, {
        id: 16,
        code: 'More information...',
        string: 'Plus d\'informations',
    },
    {
        id: 17,
        code: 'Good morning {name}',
        string: 'Bonjour {name}',
    },
    {
        id: 17,
        code: 'Hello {name} and {name2}',
        string: 'Bonjour {name} et {name2}',
    },
];

// Set Translation to french
Translation.load(translationTable);

The library comes with the _ funtion to translate words and supports interpolation:

Translation._('Translation'); // Traduction
Translation._('Good morning {name}', {name: 'John'}); // Bonjour John

Development

All tests are handle by Mocha and Chai, the entry file it's Translation.js, the project uses Babel to transpile ES6 to ES5.

Publish to NPM

npm version patch -m 'Update reason'
npm publish
1.0.0

3 years ago