Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Cannot translate the value of keypath 'message.hello'. Use the value of keypath as default. #29

Closed
Konafets opened this issue Oct 11, 2017 · 3 comments

Comments

@Konafets
Copy link
Contributor

Konafets commented Oct 11, 2017

I encountered that error above and read all issue reports at kazupon/vue-i18n repo. The error happens apparently because the Vue instance is loaded before the localization.

One guy pointed to vuex-i18n, another translation lib. I gave it a shot and this worked like a charm. The best thing: I could use the generated localization files from this package with vuex-i18n. Here is my setup:

import store from './vuex';
import vuexI18n from 'vuex-i18n';
Vue.use(vuexI18n.plugin, store);

import Locales from './vue-i18n-locales.generated.js';
Vue.i18n.add('en', Locales.en);
Vue.i18n.add('de', Locales.de);

// set the start locale to use
Vue.i18n.set(Laravel.locale);

const app = new Vue({
    store, // inject store into all children
    el: '#app',
});

The Laravel.locale comes from my Layout:

<head>
    <!-- Header stuff -->
  
    <!-- Scripts -->
    <script>
        const Laravel = {
            csrfToken: "{{ csrf_token() }}",
            locale: "{{ config('app.locale') }}"
        };
    </script>
</head>
@martinlindhe
Copy link
Owner

Nice find, we should update the README with info about this!

@Abonive
Copy link

Abonive commented Feb 19, 2018

So, I got around this error, like this.

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import Locales from './vue-i18n-locales.generated.js'

Vue.use(VueI18n)

const i18n = new VueI18n({locale: 'en', messages: Locales})

const app = new Vue({
  i18n,
  el: '#app',
})

I've tried changing the language to other than English, selecting the Vue root instance in devtools and running

$vm0.$i18n.locale = 'es'

and it works fine.

@martinlindhe
Copy link
Owner

martinlindhe commented Feb 19, 2018

@Abonive Something similar is already documented in the README (a default language needs to be set):

import Vue from 'vue';
import VueInternalization from 'vue-i18n';
import Locales from './vue-i18n-locales.generated.js';

Vue.use(VueInternalization);

Vue.config.lang = 'en';

...

Also gonna close this, as documented solutions is implemented in #31 and #34

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants