JSPM

@phrase/i18next-backend

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1177
  • Score
    100M100P100Q113113F
  • License ISC

Phrase Strings OTA i18next backend

Package Exports

    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/react_ota_example

    Basic usage

    import i18n from "i18next";
    import { I18nextPhraseBackend } from "i18next-phrase-backend";
    
    i18n
      .use(I18nextPhraseBackend)
      .init({
        fallbackLng: 'en',
        backend: {
          distribution: 'DISTRIBUTION_ID',
          secret: 'YOUR_ENVIRONMENT_SECRET',
          appVersion: '1.0.0',
        }
      });

    Combining with LocalStorage

    It is usually a good idea to cache the translations in order to reduce the load to OTA servers, so you can chain Phrase backend with LocalStorage cache:

    i18next
      .use(i18nextChainedBackend)
      .init({
        fallbackLng: "en",
        backend: {
          backends: [
            i18nextLocalStorageBackend,
            I18nextPhraseBackend
          ],
          backendOptions: [{
            // options for local storage backend
            expirationTime: 5 * 60 * 1000 // 5 minutes
          }, {
            // options for phrase backend
            distribution: 'DISTRIBUTION_ID',
            secret: 'YOUR_ENVIRONMENT_SECRET',
            appVersion: '1.0.0',
          }]
        }
      })