An i18next backend to connect to the Calinga service.
npm install i18next-calinga-backend
import i18n from 'i18next';
import { CalingaBackend, CalingaBackendOptions } from 'i18next-calinga-backend';
...
const backendOptions: CalingaBackendOptions = {
organization: '<YOUR_ORGANIZATION_NAME_HERE>',
team: '<YOUR_TEAM_NAME_HERE>',
project: '<YOUR_PROJECT_NAME_HERE>',
apiToken: '<YOUR_PROJECTS_API_TOKEN_HERE>'
resources: {
en: {
default: en
},
de: {
default: de
}
}
};
i18n
.use(CalingaBackend)
.init({
backend: backendOptions,
...
});
For use in React or React Native also add the following lines to the init options:
react: {
bindI18n: 'loaded';
}
If custom namespaces are used e.g.
i18next.init({
...
ns:['myNamespace1'],
...
}
these namespaces must match project names in calinga and translations will be fetched from there accordingly.
Available languages can be accessed at CalingaBackend.languages
or by addding a handler for CalingaBackend.onLanguageChanged
.
If devMode
is set to true
in CalingaBackendOptions
this list also contains a language that shows keys (cimode).
Set the includeDrafts
option to true
if your project has drafts enabled and you want so to see the pending version of your translations.
For a full integration sample for nodejs including a cache have a look here.