Skip to content

Wait for lazy loading promises#163

Merged
paulgv merged 2 commits intonuxt-modules:masterfrom
Alex--C:master
Jan 14, 2019
Merged

Wait for lazy loading promises#163
paulgv merged 2 commits intonuxt-modules:masterfrom
Alex--C:master

Conversation

@Alex--C
Copy link
Copy Markdown

@Alex--C Alex--C commented Dec 5, 2018

According to the docs, lazy loaded locales should be able to return a promise. Doing this creates a warning message ever since nuxt switched to https://github.com/Rich-Harris/devalue .

This pull request prevents this warning. If lazy loading returns a promise, it waits for it before returning from loadLanguageAsync and returns the resolved value instead.
Resolves nuxt/nuxt#4424 . Related: #161 .

Comment thread src/templates/utils.js Outdated
const module = await import(/* webpackChunkName: "lang-[request]" */ '~/<%= options.langDir %>' + file)
const messages = module.default ? module.default : module
i18n.setLocaleMessage(locale, typeof messages === 'function' ? await Promise.resolve(messages()) : messages)
let result = typeof messages === 'function' ? await Promise.resolve(messages()) : messages
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const result is better I guess

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I changed that.

@michaelwnyc michaelwnyc mentioned this pull request Jan 6, 2019
@paulgv paulgv merged commit 8b42631 into nuxt-modules:master Jan 14, 2019
@paulgv
Copy link
Copy Markdown
Collaborator

paulgv commented Jan 14, 2019

Thanks @Alex--C and sorry for the delay!

@Alex--C
Copy link
Copy Markdown
Author

Alex--C commented Jan 14, 2019

Thanks @Alex--C and sorry for the delay!

No problem - thank you for the merge! :D

farnabaz added a commit to farnabaz/i18n-module that referenced this pull request Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WARN Cannot stringify a function

3 participants