kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js
https://kazupon.github.io/vue-i18n/
MIT License
7.27k stars 861 forks source link

SSR example - no vue-i18n dependencies #416

Open Triloworld opened 6 years ago

Triloworld commented 6 years ago

As this : https://github.com/kazupon/vue-i18n/blob/master/examples/ssr/nuxt/package.json Line between 16 - 18

Is only nuxt needed in that situation? From this instruction it says other think: http://kazupon.github.io/vue-i18n/installation.html As example it won't work out of the box ;/ Need verification.

samuelterra22 commented 6 years ago

@Triloworld check this repository

Triloworld commented 6 years ago

Thanks for link. Found a way to handle it.

{
      src: 'nuxt-i18n',
      options: {
        baseUrl: process.env.BASE_URL,
        strategy: 'prefix',
        rootRedirect: 'pl',
        defaultLocale: 'pl',
        detectBrowserLanguage: {
          useCookie: true,
          cookieKey: 'i18n_redirected'
        },
        locales: [
          {
            code: 'en',
            iso: 'en-GB'
          },
          {
            code: 'pl',
            iso: 'pl-PL'
          }
        ],
        vueI18n: {
          fallbackLocale: 'en',
          messages: {
            'en': {
              welcome: 'Welcome'
            },
            'pl': {
              welcome: 'Witaj'
            }
          }
        }
      }
    }

And it work in SSR. The "nuxt-i18n" package is a wrapper to pass options and run vueI18n in SSR. In example I don't find it so create from scratch. Great experience :) it worth and now all works great 👍 Compare example and this repo: https://github.com/kazupon/vue-i18n/blob/master/examples/ssr/nuxt/plugins/i18n.js https://github.com/cretueusebiu/laravel-nuxt/blob/master/client/plugins/i18n.js

It is different. Nuxt-v18n work out of box with this solution :)