Skip to content
fluenti

@fluenti/vue-i18n-compat

Create a bridge plugin that installs both vue-i18n and Fluenti, syncs locale state bidirectionally, and provides unified translation functions.

import { createI18n } from 'vue-i18n'
import { createFluentVue } from '@fluenti/vue'
import { createFluentBridge } from '@fluenti/vue-i18n-compat'
const vueI18n = createI18n({ legacy: false, locale: 'en', messages: legacyMessages })
const fluenti = createFluentVue({ locale: 'en', messages: newMessages })
const bridge = createFluentBridge({
vueI18n,
fluenti,
priority: 'fluenti-first',
})
app.use(bridge)
PropertyTypeDefaultDescription
vueI18nVueI18nInstancerequiredvue-i18n instance from createI18n()
fluentiFluentVuePluginrequiredFluenti plugin from createFluentVue()
priorityBridgePriority'fluenti-first'Which library to check first
type BridgePriority = 'fluenti-first' | 'vue-i18n-first'
  • fluenti-first — Check Fluenti catalog first; fall back to vue-i18n if the key is missing. Use this when actively migrating messages to Fluenti.
  • vue-i18n-first — Check vue-i18n first; fall back to Fluenti. Use this during early adoption when most messages are still in vue-i18n.
PropertyTypeDescription
install(app: App) => voidVue plugin install method
globalBridgeContextThe global bridge context

The context object available via useI18n() or bridge.global.

MethodSignatureDescription
t(key, values?) => stringTranslate — checks both libraries per priority
tc(key, count, values?) => stringPluralized translation (vue-i18n pipe syntax or ICU plurals)
te(key, locale?) => booleanCheck if key exists in either library
tm(key) => unknownGet raw message object
MethodSignatureDescription
d(value, style?) => stringFormat a date (delegates to Fluenti)
n(value, style?) => stringFormat a number (delegates to Fluenti)
format(message, values?) => stringDirect ICU interpolation
PropertyTypeDescription
localeReadonly<Ref<string>>Current locale (synced across both libraries)
setLocale(locale: string) => Promise<void>Change locale in both libraries
availableLocalesComputedRef<string[]>Merged locales from both libraries
isLoadingReadonly<Ref<boolean>>Whether a Fluenti locale chunk is loading
PropertyTypeDescription
fluentiFluentVueContextDirect access to the Fluenti context
vueI18nVueI18nGlobalDirect access to the vue-i18n global composer

Composable to inject the bridge context in a component.

<script setup>
import { useI18n } from '@fluenti/vue-i18n-compat'
const { t, tc, te, locale, setLocale, availableLocales } = useI18n()
</script>

Returns a BridgeContext — see the table above for all properties.

The Vue injection key used by the bridge. Useful for manual inject() calls:

import { inject } from 'vue'
import { BRIDGE_KEY } from '@fluenti/vue-i18n-compat'
const bridge = inject(BRIDGE_KEY)

When the bridge plugin is installed, it overrides the following Vue global properties with bridged versions:

PropertyBehavior
$tUses bridgedT() — checks both libraries
$teUses bridgedTe() — checks both libraries
$tcUses bridgedTc() — ICU plurals or pipe-separated

This means existing templates using {{ $t('key') }} continue to work — they now resolve keys from both libraries.

The bridge sets up bidirectional watch on both locale refs:

  • Changing fluenti.locale → updates vueI18n.global.locale
  • Changing vueI18n.global.locale → updates fluenti.locale
  • An internal guard prevents infinite loops

Calling bridge.setLocale('ja') updates both atomically.