-
-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lazy load files not working #2192
Comments
with new beta 13 not runs yet :( |
@kazupon you can clone the repo, remove the pnpm patch and update manually the i18 module: remove this 3 lines https://github.com/userquin/vuetify-nuxt-module/blob/main/playground/pages/index.vue#L61-L63 |
@kazupon it seems we've a problem using i18n to get old locale when calling I guess we need to calculate the old and the new locales from the I'm using a const route = useRoute()
const router = useRouter()
const switchLocalePath = useSwitchLocalePath({ route, router, i18n })
watch(current, (l) => {
router.push({ path: switchLocalePath(l) })
}, { immediate: true }) If I hack the old locale in the browser dev tools inside the |
This is the i18n: {
locales: availableLocales,
lazy: true,
strategy: 'prefix',
detectBrowserLanguage: {
fallbackLocale: 'en-US',
useCookie: false,
// alwaysRedirect: true,
// redirectOn: 'all',
},
langDir,
defaultLocale: 'en-US',
// types: 'composition',
// pages: undefined,
dynamicRouteParams: true,
skipSettingLocaleOnNavigate: false,
debug: true,
vueI18n: './config/i18n.config.ts',
}, |
about the nuxt.hook('vite:serverCreated', viteServer => {
viteServer.middlewares.stack.unshift({
route: '',
// @ts-expect-error just ignore
handle: (req, res, next) => {
const url = req.url
let idx = url?.indexOf('@nuxtjs/i18n/')
if (idx > -1) {
console.log('url', { url, idx })
}
next()
}
})
}) |
Thank you for your working which find out cause! The reason for the lazy loading not working is that the oldLocale obtained with If we are using the I tried using I seem that the |
So, we cannot use the locale as model from useI18n. I also test it using prefix, and prefix except default. I will change the logic and update the documentation. |
I have a custom module for it, check You can test my repo exposing a new ref and changing the value (also add the import // src/runtime/plugins/i18n.ts
const messages = i18n.messages
// add this in L22
const currentLocale = ref<Locale>(current.value)
const route = useRoute()
const router = useRouter()
const switchLocalePath = useSwitchLocalePath({ route, router, i18n })
watch(currentLocale, (l) => {
// i18n.setLocale(locale)
router.push({ path: switchLocalePath(l) })
}, { immediate: true }) then replace vuetifyOptions.locale.adapter = {
name: 'nuxt-vue-i18n',
current: currentLocale, // <=== we can use it in the index.vue page
fallback,
messages,
t: (key, ...params) => i18n.t(key, params),
n: i18n.n,
provide: createProvideFunction({ current, fallback, messages }),
} // src/pages/index.vue
<v-select
v-model="current" // <=== change the locale to use it from `useLocale`
:items="locales"
item-title="name"
item-value="code"
outlined
/>
|
@kazupon it seems to be working using edge version in my local, I'll send an update to my vuetify repo: added a few changes to avoid changing i18n local directly using |
@userquin |
@sauravbv |
This issue is still present in builds, it looks like lazy loaded locales are all loaded on page load as prefetch scripts (this can be confirmed by building I think the discussion in issue #1875 is on the right track, and nuxt-contrib/vue-bundle-renderer#50 could make it possible to prevent prefetching/preloading, but I think Nuxt needs to include this change first. In the meantime I will look into making the lazy loading tests more robusts, right now they only test whether lazy loaded files are loaded, not whether they are loaded on demand. |
Yes, recently tried with edge versions and the latest I am trying a lot to optimise page load performance. Translations are being used only in some components and these components are not being used always as my page is dynamic. Is there a way to load the i18n module only when that component is used? Right now I have added |
I’m back from short vacation.
I checked nuxt v3.7 PR. |
Have you tested with the edge channel? We should have updated to v2 of vue-bundle-renderer there. You can hook into the (It's also possible that vite injects prefetch links on the client-side in some situations.) |
Thank you for your mention about it. We have already PR that can confirm it. @BobbieGoede |
@kazupon @danielroe After installing the edge version I did run into a different issue and had to add an override for |
@BobbieGoede Yes, this is the case at the moment as edge channel currently relies on prerelease versions of both nitro/h3. Your workaround is correct, and won't be needed once next nitro version is released. |
Environment
Reproduction
Fork https://github.com/userquin/vuetify-nuxt-module/ and then chekout
feat-add-i18n-support
branch:https://github.com/userquin/vuetify-nuxt-module/tree/userquin/feat-add-i18n-support (I'm working in the PR to add i18n support to Vuetify 3)
Run
pnpm install
, and then you can run:nr dev:prepare && nr dev
: for single json file per localenr dev:prepare:multiple-json && nr dev:multiple-json
: for multiple json files per localeDescribe the bug
Cannot load lazy translation files other than the default/fallback locale.
Additional context
I'm preparing a PR to fix the error, PR in a few minutes.
Logs
No response
The text was updated successfully, but these errors were encountered: