kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js
https://kazupon.github.io/vue-i18n/
MIT License
7.28k stars 861 forks source link

Available locales and lazy loading #924

Open arpi17 opened 4 years ago

arpi17 commented 4 years ago

Hi there! I have two issues/questions regarding the availableLocales property.

  1. According to the docs availableLocales is a constructor option of the VueI18n class. I think this is by mistake and it should be a part of the Properties section instead
  2. The availableLocales property is computed based on the messages property https://github.com/kazupon/vue-i18n/blob/fe6787f4c24ce1a19d0eb72500b39ebe6873f77c/src/index.js#L279 This means it can only include locales that are already loaded. If using lazy loading it might be the case that some locales are not loaded yet and thus those won't show up in the availableLocales array. I put up a simple CodeSandbox to demonstrate this. As I found the name availableLocales a bit misleading in this case I'd like to propose to
    • add some notes to the docs explaining that this property includes only the currently loaded locales to avoid some possible confusion
    • add an option to specify all the supported locales that are already loaded or ever intended to be loaded. I'm aware that this could be error-prone as one could accidentally specify a different list of supported locales that are eventually going to be loaded so that case might need to be taken care of (if possible). I think however it would be a valuable addition to the VueI18n class to contain this information. What do you think?
BlakeHancock commented 2 years ago

Related to lazy loading. The 'locale' value when calling createI18n is considered available even if no messages have been set yet.

This makes relying on availableLocales for lazy loading potentially problematic if the user overrode it, but i18n gets loaded first.

Tracking it outside of vue-i18n seems to be the best bet.