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.

Data attributes are not updated when switching language in nuxt

See original GitHub issue

# vue & vue-i18n version

“nuxt”: “1.3.0” “vue”:“2.5.13” “vue-i18n”: “7.4.2”

Hi, I see a problem when switching language and using this.$i18n.t("message") inside the data object/function using nuxt.

Steps to reproduce

This is happening only when using components and the component is loaded in the layout of the page. If I put the component whitin the page file itself the problem dissapear.

I don’t know if there is an issue of nuxt, vue-i18n or something about vue.

this is the layout I use,

<v-app >
   <Toolbar />
    <v-content>
     <nuxt ></nuxt>
    </v-content>
    <Footer />
  </v-app>
</template>

Toolbar component data:

data() {
      return {        
         links: [
          {  title: this.$i18n.t('toolbar.about'), to: 'about' },
        ]
      }
    }

Here is the link I use to switch the language <nuxt-link flat v-if="$i18n.locale === 'es'" :to="`/en` + $route.fullPath" active-class="none" class="lang" exact>EN </nuxt-link>

The problem is also not occurring if I use the $t('message') function directly in the html elements, only when use the data attributes to populate the links.

What is Expected?

data attributes to be translated on language switching

What is actually happening?

The problem is that the data attributes doesn’t get translated/refreshed.

Reproduction Link

Sorry for not attach a codepen, but I don’t know how to include nuxt in there.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

48reactions
agctycommented, Dec 9, 2018

OK the solution is really easy: For example I had a Navbar which iterated over a list of items which were defined in the data function like this:

data() {
    return {
      navItems: [
        { id: 1, text: this.$t("house.house"), link: "/" },
        { id: 2, text: this.$t("forum.forum"), link: "/forum" },
        { id: 3, text: this.$t("poll.polls"), link: "/vote" },
        {
          id: 4,
          text: this.$t("blackboard.blackboard"),
          link: "/blackboard"
        },
        {
          id: 6,
          text: this.$t("issue.reportIssue"),
          link: "/issues"
        }
      ];
    }
}

I literally just moved it to a computed property:

computed: {
navItems() {
      return [
        { id: 1, text: this.$t("house.house"), link: "/" },
        { id: 2, text: this.$t("forum.forum"), link: "/forum" },
        { id: 3, text: this.$t("poll.polls"), link: "/vote" },
        {
          id: 4,
          text: this.$t("blackboard.blackboard"),
          link: "/blackboard"
        },
        {
          id: 6,
          text: this.$t("issue.reportIssue"),
          link: "/issues"
        }
      ];
    }
}
7reactions
bakhti-uzbcommented, Jan 21, 2019

@agcty Thank you, Worked for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data not updating properly on i18n lang switch - Stack Overflow
I need to get new language data from strapi api server and reflect this lang selection in URL. So yes, I'm using a...
Read more >
A Guide to Localizing with Nuxt.js | Phrase
Since we are manually updating the code, it becomes tedious to change the locale every time. Let us create a dropdown to choose...
Read more >
Nuxt configuration file
Nuxt configuration file. By default, Nuxt is configured to cover most use cases. This default configuration can be overwritten with the nuxt.config.js file....
Read more >
Multi-Language Blog with Nuxt content module.
You might think, why not use the route inside the context instead of computing the route using the current locale?. You can totally...
Read more >
The complete guide to building a multilanguage ... - Storyblok
env and not directly in the nuxt.config.js as we did. Updating the Index Page & Requesting First Data. Replace the source code of...
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