How to use i18next-hmr - 3 common examples

To help you get started, we’ve selected a few i18next-hmr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felixmosh / i18next-hmr / examples / react-i18next / src / i18n.js View on Github external
.use(LanguageDetector)
  // pass the i18n instance to react-i18next.
  .use(initReactI18next)
  // init i18next
  // for all options read: https://www.i18next.com/overview/configuration-options
  .init({
    fallbackLng: 'en',

    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    },
  });

if(process.env.NODE_ENV === 'development') {
  const { applyClientHMR } = require('i18next-hmr');
  applyClientHMR(i18n);
}

export default i18n;
github felixmosh / i18next-hmr / examples / next-with-next-i18next / server.js View on Github external
const express = require('express');
const next = require('next');
const nextI18NextMiddleware = require('next-i18next/middleware').default;

const nextI18next = require('./i18n');

if (process.env.NODE_ENV === 'development') {
  const { applyServerHMR } = require('i18next-hmr/server');
  applyServerHMR(nextI18next.i18n);
}

const port = process.env.PORT || 3000;
const app = next({ dev: process.env.NODE_ENV !== 'production' });
const handle = app.getRequestHandler();
(async () => {
  await app.prepare();
  const server = express();
  server.use(nextI18NextMiddleware(nextI18next));
  server.get('*', (req, res) => handle(req, res));

  await server.listen(port);
  console.log(`> Ready on http://localhost:${port}`); // eslint-disable-line no-console
})();
github felixmosh / i18next-hmr / examples / next-with-next-i18next / i18n.js View on Github external
de: 'de',
  },
  all: {
    en: 'en',
    de: 'de',
  },
};

const nextI18Next = new NextI18Next({
  otherLanguages: ['de'],
  localeSubpaths: localeSubpathVariations[localeSubpaths],
});

if (process.env.NODE_ENV === 'development') {
  const { applyClientHMR } = require('i18next-hmr');
  applyClientHMR(nextI18Next.i18n);
}

module.exports = nextI18Next;

i18next-hmr

I18Next HMR🔥 webpack / vite plugin that allows reload translation resources instantly on the client & the server.

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis