Content: Support for i18n

Created on 25 May 2020  路  4Comments  路  Source: nuxt/content

Hello, thanks for such a wonderful module. I have a question, is there any possibility to use i18n together with your module?

question

Most helpful comment

If you're using nuxt-i18n, you can save you files in different directories based on your supported languages and fetch them like this.

export default {
  async asyncData({ app, params, $content }) {
    const { slug } = params;
    const posts = await $content("blog", app.i18n.locale, slug).fetch();

    return { posts };
  },
};

Content directory

content/
  blog/
    en/
      article-1.md
      article-2.md
    es/
      article-1.md
      article-2.md

All 4 comments

If you're using nuxt-i18n, you can save you files in different directories based on your supported languages and fetch them like this.

export default {
  async asyncData({ app, params, $content }) {
    const { slug } = params;
    const posts = await $content("blog", app.i18n.locale, slug).fetch();

    return { posts };
  },
};

Content directory

content/
  blog/
    en/
      article-1.md
      article-2.md
    es/
      article-1.md
      article-2.md

There is my code
async fetch() { this.submenu = await this.$content('submenu', this.$i18n.locale, 'index').fetch().catch(); },

but when i switch page, content wouldn't update(
Also, have error in console UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().

My structure:

content/
    submenu/
        ru/
            index.md
        uk/
            index.md

@juliomrqz answer is the one I recommend, and also the one we use in the content documentation: https://github.com/nuxt/content/blob/master/docs/pages/_slug.vue#L31

@juliomrqz answer is the one I recommend, and also the one we use in the content documentation: https://github.com/nuxt/content/blob/master/docs/pages/_slug.vue#L31

But what if i want use this module not on page component. I have nav which i want place in .md file and get it in fetch function in my Header component.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pi0 picture pi0  路  3Comments

thely picture thely  路  4Comments

haykokalipsis picture haykokalipsis  路  4Comments

adrianschubek picture adrianschubek  路  4Comments

jonathanmach picture jonathanmach  路  4Comments