Skip to content

Commit

Permalink
📝 docs(vuepress): Update lazy-loading.md (#682) by @Alex-Sokolov
Browse files Browse the repository at this point in the history
* Update lazy-loading.md

* Update lazy-loading.md
  • Loading branch information
Alex-Sokolov authored and kazupon committed Aug 12, 2019
1 parent 71ca843 commit 1cc4c72
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions vuepress/guide/lazy-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ function setI18nLanguage (lang) {
return lang
}

export function loadLanguageAsync (lang) {
if (i18n.locale !== lang) {
if (!loadedLanguages.includes(lang)) {
return import(/* webpackChunkName: "lang-[request]" */ `@/lang/${lang}`).then(msgs => {
i18n.setLocaleMessage(lang, msgs.default)
loadedLanguages.push(lang)
return setI18nLanguage(lang)
})
}
export function loadLanguageAsync(lang) {
// If the same language
if (i18n.locale === lang) {
return Promise.resolve(setI18nLanguage(lang))
}
return Promise.resolve(lang)

// If the language was already loaded
if (loadedLanguages.includes(lang)) {
return Promise.resolve(setI18nLanguage(lang))
}

// If the language hasn't been loaded yet
return import(/* webpackChunkName: "lang-[request]" */ `@/i18n/messages/${lang}.js`).then(
messages => {
i18n.setLocaleMessage(lang, messages.default)
loadedLanguages.push(lang)
return setI18nLanguage(lang)
}
)
}
```

Expand Down

0 comments on commit 1cc4c72

Please sign in to comment.