charliekassel / vuejs-datepicker

A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations
MIT License
2.61k stars 730 forks source link

Passing in unsupported language code causes JS error #191

Open gryphonmyers opened 7 years ago

gryphonmyers commented 7 years ago

I passed in "cs" (Czech) to see what would happen and got the following errors:

[Vue warn]: Error in render function: "TypeError: Cannot read property 'months' of undefined"

found in

---> <Datepicker>
       <Anonymous>
         <Anonymous>
           <App>
             <Root>

TypeError: Cannot read property 'months' of undefined
    at VueComponent.currMonthName (bundle.js:35145)
    at Watcher.get (bundle.js:30753)
    at Watcher.evaluate (bundle.js:30853)
    at Proxy.computedGetter (bundle.js:31107)
    at Proxy.render (bundle.js:35145)
    at VueComponent.Vue._render (bundle.js:31878)
    at VueComponent.updateComponent (bundle.js:30414)
    at Watcher.get (bundle.js:30753)
    at Watcher.run (bundle.js:30823)
    at flushSchedulerQueue (bundle.js:30590)

The component should probably fall back to english when it gets an unsupported language.

Edit: I just realized you claim support for Czech. Let me verify this isn't being caused by something wrong on my end.

Edit 2: As far as I can tell I am passing in "cs" correctly. The app seems to be breaking on both "cs" and "pt" (it looks like you support the non-standard "pt-br" but not "pt" in isolation)? My two cents, you should decide if you're supporting locales or languages and not some mix of them, then make everything adhere to http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

charliekassel commented 7 years ago

I'm ok with it throwing for an unsupported language, not sure if it should fallback to a default tbh.

All languages have been added by contributors as I am a typical ignorant Englishman that speaks only one language! So if a language is not supported here, it's because a user has not found the need to add it.

I totally agree with having a standard for adding these and will add this requirement to the readme. It should follow html language recommendations - https://www.w3.org/International/questions/qa-html-language-declarations - so am happy to go with the list at iana

Re: Czech - I changed the translations property from cs to cz recently but forgot to update the readme - so thanks for the heads up.

Looks like this was done in error so have reverted in f29b2a1
gryphonmyers commented 7 years ago

Re: fallback, my use case is an app-wide locale switcher. I have a locale / language code in my app state and it would be nice if I didn't have to pre-validate this code against your supported list (which should be encapsulated anyway) before passing it into your component. A fallback makes the most sense to me - you could maybe control what the fallback is through another prop?

charliekassel commented 7 years ago

I think you should be notified of invalid input.

If this feature works for you send in a PR and I'll happily review.

On Wed, Jun 28, 2017 at 7:31 AM, Gryphon Myers notifications@github.com wrote:

Re: fallback, my use case is an app-wide locale switcher. I have a locale / language code in my app state and it would be nice if I didn't have to pre-validate this code against your supported list (which should be encapsulated anyway) before passing it into your component. A fallback makes the most sense to me - you could maybe control what the fallback is through another prop?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/charliekassel/vuejs-datepicker/issues/191#issuecomment-311569157, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7YFMEFjm_tbGWjhX9knMfHdWuOvq_-ks5sIfNFgaJpZM4OHcTH .