All files / core/lib i18n.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39          14x   14x                                             14x 18x 18x 36x          
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
import { loadLocales } from '@fundraising/white-labeling'
 
const locales = loadLocales()
 
i18n.use(LanguageDetector)
    .use(initReactI18next)
    .init({
        resources: {
            en: { common: locales.en },
            fr: { common: locales.fr },
            de: { common: locales.de },
            it: { common: locales.it },
        },
        fallbackLng: 'en',
        defaultNS: 'common',
        ns: ['common'],
        debug: true, // import.meta.env.DEV
 
        interpolation: {
            escapeValue: false,
        },
    })
 
/**
 * Re-syncs i18n resources from the white-labeling package.
 * This should be called after initWhiteLabeling() to apply dynamic overrides.
 */
export const syncLocales = () => {
    const locales = loadLocales()
    Object.entries(locales).forEach(([lng, resources]) => {
        i18n.addResourceBundle(lng, 'common', resources, true, true)
    })
}
 
export default i18n