question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v-t attributes in a <router-link /> element does not translate when changing $i18n.locale

See original GitHub issue

vue & vue-i18n version

Vue 2.5.17-beta.0 Vue-i18n 7.6.0

Steps to reproduce

<template v-for="category in CATEGORIES">
    <router-link :to="{}" class="category" :key="category.category">
        <div class="column title-description">
            <div class="title" v-t="category.category">
            <div class="description" v-t="category.category + '_description'" />
        </div>
    </router-link>
</template>

What is Expected?

When I change $i18n.locale all v-t attributes should be translated.

What is actually happening?

The translations doesn’t render. If I change at least one of the v-t attributes to interpolation with $t it actually works, even on the v-t attributes.

Code sample that works perfectly:

<template v-for="category in CATEGORIES">
    <router-link :to="{}" class="category" :key="category.category">
        <div class="column title-description">
            <div class="title">{{ $t(category.category) }}</div>
            <div class="description" v-t="category.category + '_description'" />
        </div>
    </router-link>
</template>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
Rouchecommented, Aug 28, 2018

I also have this problem. But it happens inside a <router-view /> of a Vuetify application. None of the v-t are working. Outside seems ok.

<template>
    <div id="app">
        <v-app>
            <app-navigation></app-navigation>
            <v-container grid-list-xs grid-list-sm gird-list-md>
                <router-view></router-view>
            </v-container>
            <div>
                <!-- this one is working -->
                <span v-t="'title'"></span>
            </div>
        </v-app>
    </div>
</template>

routes


const verifyLocale: NavigationGuard = (to, from, next) => {

    loadLanguageAsync(to.params.locale).then( (): void => {
        next();

    }).catch( (): void => {
        next(`/${i18n.locale}`);
    });
};

const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,

    routes: [
        {
            path: '/',
            redirect: `/${i18n.locale}`,
        },
        {
            path: '/:locale',
            component: Locale,
            beforeEnter: verifyLocale,

            children: [
                {
                    path: '',
                    name: 'dashboard',
                    component: Dashboard,
                    beforeEnter: ifAuthenticated,
                },
                {
                    path: 'login',
                    name: 'login',
                    component: Login,
                    beforeEnter: ifNotAuthenticated,
                },
                {
                    path: '*',
                    redirect: `/${i18n.locale}`,
                },
            ],
        },
    ],
});
router.beforeEach(verifyLocale);

export default router;
0reactions
DorianGreycommented, Sep 4, 2018

Seeing a similar issue on my playground application. It seems that the language update isnt’ immediately adopted for elements using the v-t directive. However, it gets updated the new time the component is re-rendered. In case of the playground app mentioned above: changing the language (here: via the top-right button) does not update the texts in the menu and header, until I toggle the menu again, or perform any route change (some texts are actually adopted - those are using $t, mostly in places where v-t could not be used).

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Ultimate Guide to Vue Localization with Vue I18n - Medium
This end-to-end tutorial will give you a deep insight into Vue localization with the extremely popular Vue I18n library for you to take...
Read more >
Vue I18N Adding Locale To The Url Using Routerview - ADocLib
vt attributes in a routerlink / element does not translate when changing i18n.locale #399.Kansuler posted onGitHub.! BUG REPORT TEMPLATE.
Read more >
i18n component | fluent-vue
Message attributes are passed as scoped slot parameters. This allows to not split translation into multiple messages. And attributes have access to same ......
Read more >
Angular i18n for text containing routerLink and requires ...
2 Answers 2 · But then you are maintaining code in your translation files. If the href needs to change, or you need...
Read more >
The Ultimate Vue Localization Guide | Phrase
Note » To focus on the i18n, we won't show any CSS styling in this ... a region subtag (like en-US ) to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found