We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is my en.json: { "message": "hello i18n !!" }
my i18n.ts
import Vue from "vue"; import VueI18n, { LocaleMessages } from "vue-i18n";
Vue.use(VueI18n); //imported and then used here
//this method loads all the json files needed for translations function loadLocaleMessages(): LocaleMessages { const locales = require.context("./locales", true, /[A-Za-z0-9-,\s]+.json$/i); const messages: LocaleMessages = {}; locales.keys().forEach((key) => { const matched = key.match(/([A-Za-z0-9-]+)./i); if (matched && matched.length > 1) { const locale = matched[1]; messages[locale] = locales(key).default; } }); return messages; }
export default new VueI18n({ locale: "en", //change locale here fallbackLocale: "en", messages: loadLocaleMessages() //makes json translations available in messages key });
my main.ts
import Vue from "vue"; import App from "./App.vue"; import router from "./router"; import i18n from "./i18n"; //i18n imported here Vue.config.productionTip = false; new Vue({ router, i18n, render: (h) => h(App) }).$mount("#app");
Not able to translate using
{{ $t("message") }}
Dont know whats wrong gives me this error: [vue-i18n] Cannot translate the value of keypath 'message'. Use the value of keypath as default.
The text was updated successfully, but these errors were encountered:
But it works when my loadLocaleMessages is this
function loadLocaleMessages(): LocaleMessages { const messages = { en: { message: "world" }, fr: { message: "french world" } };
return messages; }
Why is it not readiing from json files directly
Sorry, something went wrong.
Solved!!
just replace messages[locale] = locales(key).default;
with
messages[locale] = locales(key)
in i18n.ts file
But why it doesnt work with default idk.
Yes, same issue here,
I had stopped by to find out if anyone else had the problem and give the same answer as you. after removing .default it's work
this is vue-cli-plugin-i18n issue. fixed with intlify/vue-cli-plugin-i18n#183
thanks!
Cheers 👍
No branches or pull requests
This is my en.json:
{
"message": "hello i18n !!"
}
my i18n.ts
import Vue from "vue";
import VueI18n, { LocaleMessages } from "vue-i18n";
Vue.use(VueI18n); //imported and then used here
//this method loads all the json files needed for translations
function loadLocaleMessages(): LocaleMessages {
const locales = require.context("./locales", true, /[A-Za-z0-9-,\s]+.json$/i);
const messages: LocaleMessages = {};
locales.keys().forEach((key) => {
const matched = key.match(/([A-Za-z0-9-]+)./i);
if (matched && matched.length > 1) {
const locale = matched[1];
messages[locale] = locales(key).default;
}
});
return messages;
}
export default new VueI18n({
locale: "en", //change locale here
fallbackLocale: "en",
messages: loadLocaleMessages() //makes json translations available in messages key
});
my main.ts
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import i18n from "./i18n"; //i18n imported here
Vue.config.productionTip = false;
new Vue({
router,
i18n,
render: (h) => h(App)
}).$mount("#app");
Not able to translate using
{{ $t("message") }}
in my component's htmlDont know whats wrong gives me this error:
[vue-i18n] Cannot translate the value of keypath 'message'. Use the value of keypath as default.
The text was updated successfully, but these errors were encountered: