Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Reload translations without page refresh #86

Open
martijnmichel opened this issue Dec 12, 2019 · 0 comments
Open

Reload translations without page refresh #86

martijnmichel opened this issue Dec 12, 2019 · 0 comments

Comments

@martijnmichel
Copy link

So im trying to hot reload translations. The changes are detected and i can do a console.log with the correct new translations, but the ui itself is not updated weird enough.

import Vue from "vue";
//import VueI18n from "vue-i18n";
import i18next from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";

import VueI18Next from "@panter/vue-i18next";

import messages from "src/i18n";

//import { applyI18NextHMR } from "i18next-hmr";

Vue.use(VueI18Next);

import moment from "moment";

i18next.use(LanguageDetector).init({
  resources: messages,
  fallbackLng: "en-US",
  ns: ["translation", "md", "wiki"],
  defaultNS: "translation"
});

const i18n = new VueI18Next(i18next);

moment.locale(i18next.language);

if (module.hot) {
  module.hot.accept("src/i18n", () => {
    // this method will be invoked each time webpack sees a change in `src/i18n` import
    const newResources = require("src/i18n");
    Object.keys(newResources).forEach(lang => {
      const langObj = newResources[lang];

      Object.keys(langObj).forEach(namespace => {
        const nsResource = langObj[namespace];
        i18next.addResourceBundle(lang, namespace, nsResource);
      });
    });
  });
}

export default ({ app }) => {
  app.i18n = i18n;
};
export { i18n };
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

1 participant