wegue-oss / wegue

Template and components for webmapping applications with OpenLayers and Vue.js
BSD 2-Clause "Simplified" License
93 stars 41 forks source link

Refactor VueI18n creation to own module #387

Closed chrismayer closed 2 months ago

chrismayer commented 2 months ago

This refactors the creation of the VueI18n instance by encapsulating it in an own ES module. So the i18n instance can be imported to other pure ES modules and will allow internationalization there.

This follows the approach given here: https://github.com/kazupon/vue-i18n/issues/149#issuecomment-357455921

This would make the introduction of a global $appLanguage variable in #356 obsolete by this much cleaner and more versatile approach. If you approve this PR, I'd happily revert #356 afterwards in a separate PR.

Accessing the current app language in pure ES modules could then be done by the following code:

const { i18n } = await import('../../../src/locales/wgu-i18n.js');
console.log(i18n.locale);
chrismayer commented 2 months ago

Thanks for your review @sronveaux and thanks for your suggestion regarding the assignment to Vue.prototype in the tests. I created an issue to improve that as a whole :arrow_right: #388. Going to merge now...