Closed AniaKru95 closed 3 years ago
use lazy loading translations. Go check : https://kazupon.github.io/vue-i18n/guide/lazy-loading.html
Hi,
Thanks for your reply. I changed my code to lazy loading, and nothing changed.
Here's my code:
import VueI18n from 'vue-i18n'
import axios from 'axios'
import messages from './locales/en'
Vue.use(VueI18n)
export const i18n = new VueI18n({
locale: 'en', // set locale
fallbackLocale: 'en',
messages // set locale messages
})
const loadedLanguages = ['en'] // our default language that is preloaded
function setI18nLanguage (lang) {
i18n.locale = lang
axios.defaults.headers.common['Accept-Language'] = lang
document.querySelector('html').setAttribute('lang', lang)
return lang
}
export function loadLanguageAsync(lang) {
// If the same language
if (i18n.locale === lang) {
return Promise.resolve(setI18nLanguage(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]" */ `./locales/${lang}.json`).then(
messages => {
i18n.setLocaleMessage(lang, messages.default)
loadedLanguages.push(lang)
return setI18nLanguage(lang)
}
)
}
Screen result in the browser. Content is cut, and after 5 minutes all data is loaded.
Hi,
I think it related to your browser, try another one and check if any proxy is on
I checked in: Firefox (94.0.1 (64 bit)) - problem exists Chrome (95.0.4638.69 (64-bit)) - problem exists Internet explorer - ui does not work at all, but it's not problem for me. Also, it isn't problem with proxy.
I saw another strange issue. When all data has been loaded in "en" and then I changed to my locale "pl" - data translated fast. But when I returned to language "en", ui is freezing again.
change
i18n.setLocaleMessage(lang, messages);
to
i18n.setLocaleMessage(lang, Object.freeze(messages))
and to be more specific this issue isn't realted to vuejs but in the vue-cli-plugin-i18n : https://github.com/intlify/vue-cli-plugin-i18n/issues
Ok, I write there also. Unfortunately this change does not help. UI is freezing all the time :(
Aks for help at the mentioned repo. feel free to open a new issue here if it turns out to be a Vue UI related problem
Version
5.0.0-beta.7
Environment info
Steps to reproduce
What is expected?
Faster data loading
What is actually happening?
Browser is freezing and long duration for loading data