I recently came across an example of internationalization (i18n) in the Nuxt.Js documentation. While I understand most of it, I am curious about how clicking on the Language option in the Navbar menu can switch the locale from 'en' to 'fr' or vice versa, triggering a language swap.
Check out the code snippet here: https://nuxtjs.org/examples/i18n
Within the default layout, this code is used:
<nuxt-link class="Header__Link" v-if="$i18n.locale === 'en'" :to="`/fr` + $route.fullPath" active-class="none" exact>
{{ $t('links.french') }}
</nuxt-link>
<nuxt-link class="Header__Link" v-else :to="$route.fullPath.replace(/^\/[^\/]+/, '')" active-class="none" exact>
{{ $t('links.english') }}
</nuxt-link>
Experience the live demo firsthand:
If anyone can provide further clarification on this topic, I would greatly appreciate it.
Thank you.