UNPKG

i18next-hmr

Version:

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

23 lines (16 loc) • 627 B
export function applyViteClientHMR(i18nOrGetter) { if (import.meta.hot) { const { extractList, printList, reloadTranslations, log } = require('../utils'); log('Client HMR has started'); import.meta.hot.on('i18next-hmr:locale-changed', ({ changedFiles }) => { const i18nInstance = typeof i18nOrGetter === 'function' ? i18nOrGetter({ changedFiles }) : i18nOrGetter; const list = extractList(changedFiles, i18nInstance); if (!list.length) { return; } log(`Got an update with ${printList(list)}`); return reloadTranslations(list, i18nInstance); }); } }