Skip to content
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

Crashes when fallbackLocale is not provided #849

Closed
rchl opened this issue Apr 20, 2020 · 2 comments
Closed

Crashes when fallbackLocale is not provided #849

rchl opened this issue Apr 20, 2020 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Improvement Includes backwards-compatible fixes

Comments

@rchl
Copy link
Contributor

rchl commented Apr 20, 2020

This is not a bug but it's a behavior change for nuxt-i18n so I'm creating it for your consideration.

vue & vue-i18n version

vue-i18n: 8.17.3

Reproduction Link

https://jsfiddle.net/4m5yaq1e/5/
(It doesn't reproduce any issue but shows the sort of configuration that nuxt-i18n has a problem with)

Steps to reproduce

In nuxt-i18n I have one test that started failing with latest version of vue-i18n.

That test asserts that vue-i18n with an empty configuration doesn't cause any issues but it started crashing.

An empty configuration would normally not cause issues in vue-i18n but, for specific reasons, I'm explicitly altering i18n.locale and i18n.fallbackLocale to null at runtime when no values were provided for those.

vue-i18n didn't have problems with that before, until #138 which added code that crashes when locale/fallbackLocale is null.

The stack trace is something like this:

ERROR  Cannot read property 'split' of null                                                                                                                                                                10:01:00

  at VueI18n._appendLocaleToChain (node_modules/vue-i18n/dist/vue-i18n.common.js:1518:23)
  at VueI18n._appendBlockToChain (node_modules/vue-i18n/dist/vue-i18n.common.js:1531:19)
  at VueI18n._getLocaleChain (node_modules/vue-i18n/dist/vue-i18n.common.js:1555:20)
  at VueI18n._translate (node_modules/vue-i18n/dist/vue-i18n.common.js:1603:20)
  at VueI18n._t (node_modules/vue-i18n/dist/vue-i18n.common.js:1629:18)

What is Expected?

I don't expect this to be treated as a bug as the usage is somewhat non-standard and not in line with documentation, but also it probably would be easy to change the code to not crash in this situation.

@rchl
Copy link
Contributor Author

rchl commented Apr 20, 2020

I can work around that on my side by using some "random" string value rather than null. The point of me doing that is to initialize those to something that is not likely to match any of the locales provided explicitly by the user.

@kazupon kazupon added good first issue Good for newcomers help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Improvement Includes backwards-compatible fixes labels Apr 20, 2020
rchl added a commit to nuxt-modules/i18n that referenced this issue Apr 22, 2020
rchl added a commit to nuxt-modules/i18n that referenced this issue Apr 22, 2020
rchl added a commit to nuxt-modules/i18n that referenced this issue Apr 22, 2020
@rchl
Copy link
Contributor Author

rchl commented Apr 22, 2020

Thanks for considering it but I've realized I can use empty string instead of null which will fix my issue and will be in line with the expected type of the locale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Improvement Includes backwards-compatible fixes
Projects
None yet
Development

No branches or pull requests

2 participants