JSPM

@phrase/i18next-backend

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 891
  • Score
    100M100P100Q114174F
  • License MIT

Phrase Strings OTA i18next backend

Package Exports

  • @phrase/i18next-backend
  • @phrase/i18next-backend/dist/index.cjs.js
  • @phrase/i18next-backend/dist/index.esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@phrase/i18next-backend) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

i18nextPhraseBackend - Phrase Strings backend for i18next

Description

This small library implements an example backend for i18next which retrieves the translations from Phrase OTA releases. The distribution should be created for i18next platform.

Usage

A demo project can be found at https://github.com/phrase/ota-web-demo

Basic usage

npm install --save @phrase/i18next-backend
import i18n from "i18next";
import { I18nextPhraseBackend } from "@phrase/i18next-backend";

i18n
  .use(I18nextPhraseBackend)
  .init({
    fallbackLng: 'en',
    backend: {
      distribution: 'DISTRIBUTION_ID',
      secret: 'YOUR_ENVIRONMENT_SECRET',
      appVersion: '1.0.0',
    }
  });

Caching

The library is caching translations and won't check for new translations for 5 minutes. This can be configured by setting the cacheExpirationTime option in the backend configuration for testing purposes. It's recommended to use at least 5 minutes in production.

i18n
  .use(I18nextPhraseBackend)
  .init({
    fallbackLng: 'en',
    backend: {
      distribution: 'DISTRIBUTION_ID',
      secret: 'YOUR_ENVIRONMENT_SECRET',
      appVersion: '1.0.0',
      cacheExpirationTime: 60 * 5, // time in seconds
    }
  });