Dynamic loading a language object instead of load all in the begin when i have 10 language.
See original GitHub issuenow ,my code is like that:
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import en from 'module/user/i18n/en';
import zh from 'module/user/i18n/zh';
Vue.use(VueI18n);
const messages = {
en: en,
zh: zh,
...
};
let lang = window.localStorage.getItem('lang') || 'en';
export default new VueI18n({
locale: lang,
messages
});
but and i want to dynamic loading a language objec like this:
import Vue from 'vue';
import VueI18n from 'vue-i18n';
// import en from 'module/user/i18n/en';
// import zh from 'module/user/i18n/zh';
Vue.use(VueI18n);
const messages = {
en: () => import('module/user/i18n/en'); // i want to dynamic loading,but it does not work!!!
zh: () => import('module/user/i18n/zh');
};
...
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Creating a module system (dynamic loading) in C
dynamic loading library is a mechanism with which we can run our program, and at runtime, decide what function, we want to use...
Read more >Dynamic loading - Wikipedia
Dynamic loading is a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve...
Read more >Principles of Programming Languages: Chapter 9 - RICE CS
A static field f in a class C is simply a global variable with the name C.f: there is one such field in...
Read more >Dynamic component loader - Angular
Instead, you need a way to load a new component without a fixed reference to the ... Angular comes with its own API...
Read more >Vue i18n: Building a multi-language app with locale switcher
Datetime and number localization. Switching the locale. Integrating Vue Router and making it work with multiple locales. Lazy load translation ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi guys, I figure it out.
Here’s the code in my vuex.
if you want the full demo, you can check out my repo, vue-i18n sandbox
Loading all possible languages if your user only uses English for example is not sensible. Not only does it increase the bundle size, but the localizations for several languages also have to be kept in memory.