t1m0n / air-datepicker

Lightweight, dependency-free JavaScript datepicker.
https://air-datepicker.com
MIT License
2.62k stars 1.37k forks source link

Locale dynamic import #584

Open TiGR opened 8 months ago

TiGR commented 8 months ago

So, the question is: we have multiple site versions, and in each of these the entire interface is in some specific language. We'd like to provide translations according to the site language. The problem here is that there is no simple way to import only specific translations for specific site language versions.

The only way I see it could be achieved is by using client-side imports, but that would require somehow adding all files to build process, so that all translations be copied to build directory, even if it is not imported directly. And also that puts some requirements for browser support and there is no way to support legacy browsers.

The only way I see it is by loading all supported languages in some for all website versions, which I see as suboptimal.

t1m0n commented 8 months ago

I guess you could use something like webpack lazy loading or implement it by yourself if you don't want to include all locale files in your bundle. I think it would be great to have index file in AirDatepicker which would export all possible locales 🤔 . I guess I'll add such in the next release

TiGR commented 8 months ago

For most libraries that I've worked with, you could either import specific language, or just include a locale file on page and it would automatically register with the library, and then you could just specify the locale code, and it would take it from the locale registry.

As for the locale files in air-datepicker dist directory, there is no way to import/add these in browser environment, you can't add a script tag (even with type="module") with it. It could work only on build step with some sort of builder (which is not always present).