i18next
Transifex Native over i18next
For cases where the codebase is already localized using i18next and code migration to the Transifex Native SDK is difficult, you may use the Transifex Native extensions for i18next.
This way, you can get the benefits of over-the-air delivery, by using the @transifex/i18next backend plugin.
This can be a fast entry point, although migrating to the Javascript Transifex Native SDK, can offer the additional benefits of:
- Hassle free extraction and push of content using a simple command.
- Attach content metadata that will aid the localization process and improve translation quality.
Quick starting guide
Install the library using:
npm install @transifex/i18next --save
Webpack
import { TransifexI18next } from '@transifex/i18next';
const txBackend = new TransifexI18next({
token: 'public token',
// other options from @transifex/native init function
});
// add plugin to i18next
i18next.use(txBackend).init(...);
Node.js
const { TransifexI18next } = require('@transifex/i18next');
const txBackend = new TransifexI18next({
token: 'public token',
// other options from @transifex/native init function
});
// add plugin to i18next
i18next.use(txBackend).init(...);
Browser
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@transifex/i18next/dist/browser.i18next.min.js"></script>
<script type="text/javascript">
const TransifexI18next = TxNativeI18next.TransifexI18next;
const txBackend = new TransifexI18next({
token: 'public token',
// other options from @transifex/native init function
});
// add plugin to i18next
i18next.use(txBackend).init(...);
</script>
Uploading phrases for translation
You can use @transifex/cli
to push i18next JSON files for translation. First step is to install the CLI tool
into the project using the command:
npm i @transifex/cli --save
Then, given that you have generated a source i18next JSON v4, use the following command to
upload to Transifex for translation.
npx txjs-cli push source.json --parser=i18next
That's it. Given that the content is translated, translations will be downloaded over-the-air using the Transifex i18next backend.
Known limitations
CLI does NOT parse and push the following key types:
- keyWithArrayValue
- keyWithObjectValue
Updated over 2 years ago