A
A
ashfedor2021-02-09 11:10:12
Internationalization and localization
ashfedor, 2021-02-09 11:10:12

How to properly set up multilingualism for a project on NUXT VUE?

Hello, I'm doing a project, Beck is on my laravel and for the front I tried to use nuxt for the first time.
Larvel gives api json like this.

{
            "menu_id": 1,
            "menu_item__id": 1,
            "menu_item_title_ru": "Главная",
            "menu_item_title_uk": "Головна",
            "menu_item_path": "/",
            "menu_item_icon": null,
            "menu_item_parent_id": 1,
            "menu_item_status": "1"
        },
        {
            "menu_item_id": 2,
            "menu_item_menu_id": 1,
            "menu_item_title_ru": "Контакты",
            "menu_item_title_uk": "Контакти",
            "menu_item_path": "/contacts",
            "menu_item_icon": null,
            "menu_item_parent_id": 1,
            "menu_item_status": "1"
        },

this is an example))
I put i18n for multilingualism, it translates static names perfectly.
further there was a question how to receive the necessary variant from json
Now I solved a question so far. I get the locale and, depending on it, I display the desired language
<nuxt-link
          :to="item.menu_item_path">
          <span v-if="$i18n.locale === 'ru'">{{item.menu_item_title_ru}}</span>
          <span v-else>{{item.menu_item_title_uk}}</span>
        </nuxt-link>

but I feel that this is still that crutch))
Maybe someone has a better solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-02-09
@ashfedor

And if so?

<span>{{item[`menu_item_title_${$i18n.locale}`]}}</span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question