i18n setting global interpolation

Viewed 26

I'm using i18n interpolation to render non-breaking hyphen (html code: ‑) in my translations:

component:

{{ $t('message', {char: '‑'}) }}

en.json:

"message": "I am working full{char}time on this project."

I would like to do that for every translation in my project without having to pass char parameter to each translation. Is there a way to set char = &#8209 globally in i18n and pass it to all translations without having to specify it each time?

Here's my i18n.js setup file:

import {createI18n} from 'vue-i18n';


function loadLocaleMessages() {

    const pathsGlob = import.meta.glob('../../lang/*.json')

    const messages = {}

    for (const path in pathsGlob) {
        pathsGlob[path]().then((mod) => {
            const locale = path.split('/')[path.split('/').length - 1].split('.')[0]
            messages[locale] = mod
        })
    }
    return messages
}


export default new createI18n({
    locale: navigator.language.substring(0, 2),
    fallbackLocale: 'en',
    messages: loadLocaleMessages(),
    silentTranslationWarn: true,
    silentFallbackWarn: true,
});
0 Answers
Related