How multiple I18n instances work
mainThe I18n class encapsulates translation logic and the active language. You can create multiple instances of I18n to support different active languages within the same application (e.g., a main UI in English and a specific component in Portuguese).
While each instance maintains its own active language, loaded language files are shared across all instances to prevent redundant network requests or memory usage.
import { I18n } from 'laravel-vue-i18n'
const resolver = lang => import(`./fixtures/lang/${lang}.json`)
const i18nEn = new I18n({
lang: 'en',
resolve: resolver
})
const i18nPt = new I18n({
lang: 'pt',
resolve: resolver
})
i18nEn.trans('Welcome!') // outputs "Welcome!"
i18nPt.trans('Welcome!') // outputs "Bem-vindo!"