Migration help 1.0.0 to @js-joda/locale 2.0.x
kuhnroyal opened this issue · 3 comments
I have used the described way to build my own core
package including de
and en
locales with version 1.0.0 and imported this into my angular app like this.
"@js-joda/locale": {
"packages": {
"core": [
"de",
"en"
]
},
"stats": false,
"debug": false
}
import {
LocalDate,
Locale as LocaleDef,
use as jsJodaUse
} from "js-joda";
import * as jsJodaLocale from "js-joda-locale/build/package/core";
const {
Locale,
DateTimeFormatter
} = jsJodaUse(jsJodaLocale);
This worked as expected.
Now I am trying to migrate to @js-joda/locale
but I can not reproduce the above. As this is no longer documented, I am wondering what the correct approach is.
Hi @kuhnroyal
first of all , thanks for using js-joda-locale and thanks for the report
indeed we changed how to build and use js-joda-locale for 2.0 since the building was not always easy.. so there are now prebuilt packages for de and en e.g. @js-joda/locale_de-de or @js-joda/locale_de and @js-joda/locale_en-us or @js-joda/locale_en ... the idea was to make it easier to use js-joda-locale and to reduce the amount of data and packages needed to download... or you can use @js-joda/locale which should contain prebuilt locales in the dist/prebuilt folder
also the js-joda plugins no longer need to be registered/used to work... all you need to do is require/import the js-joda-locale package you need
For an example, please take a look here: https://github.com/js-joda/js-joda-examples/blob/master/examples/node/node-modules-07.js
One caveat however is bug #93 ... currently when loading a locale package, only the last loaded locale can be used, e.g. when you reguire @js-joda/locale_en and then @js-joda/locale_de only the de locales are available since they have been loaded last ... i know that that is by far not ideal to force users to do dynamic requires and i already have a solution in mind but haven't had time to implement it yet :/
That said, it should still be possible to build your own custom package but with a little more manual effort than in 1.0 since the automatic build on install is no longer available.
I hope this helps, please feel free to comment/ask further question, i'll be glad to help :)
Regards, Pattrick
Hello Pattrick,
thanks for your answer, I will take a look at the example.
If I go the dynamic import path, can I switch the locale packages at runtime and have them correctly registered?
Regards
Hi,
to be honest.. .i don't know... since the requires should be cached it might be possible, but there also might be very strange effects ...
Regards, Pattrick