You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Been experiencing weird bugs sometimes that weren't present in the examples/react.
My problems started from this line when I followed the React guide:
Configure typesafe-i18n by creating the file .typesafe-i18n.json with following contents:
{
"adapter": "react"
}
This defaults to loadLocalesAsync: true, and generates an AsyncFormattersInitializer.
However after changing it to loadLocalesAsync: false, it never re-generated the file to a sync FormattersInitializer, which caused many weird bugs in my code.
I suppose this was intentional because formatters.ts is mostly user generated, and we wouldn't want to accidentally overwrite the dev's code.
a. One suggestion I can think of is to have formatters.ts only export const formatters: Formatters, and move initFormatters into i18n-util or a new file such as i18n-formatters.
b. Another suggestion I can think of is to remove the sync/async option from the config and always generate both, and let the developers pass in 'loadLocalesAsync' into initI18n. So it will now be controlled through code rather than config.
c. Third option is to simply add a note to update formatters.ts after changing the option.
On a side note, million thanks for creating this library and being so active in maintaining it! I've only had <50 translations to deal with so far, but it has already saved my team a ton of time! ❤️
The text was updated successfully, but these errors were encountered:
Thanks for filing this issue. I already have thought that the current implementation is not ideal.
The initFormatters function is needed because the formatters could be locale-dependent (e.g. date-formatting), so when you switch locale, also your formatters need to be recreated.
When running the generator, I think we could check if the formatter file was changed already
if no => replace it with the correct sync/async variant
if yes => output a red error message to the console with help-instructions
I think this would improve the developer experience a lot.
Been experiencing weird bugs sometimes that weren't present in the
examples/react
.My problems started from this line when I followed the React guide:
This defaults to
loadLocalesAsync: true
, and generates anAsyncFormattersInitializer
.However after changing it to
loadLocalesAsync: false
, it never re-generated the file to a syncFormattersInitializer
, which caused many weird bugs in my code.I suppose this was intentional because
formatters.ts
is mostly user generated, and we wouldn't want to accidentally overwrite the dev's code.a. One suggestion I can think of is to have
formatters.ts
only exportconst formatters: Formatters
, and moveinitFormatters
into i18n-util or a new file such as i18n-formatters.b. Another suggestion I can think of is to remove the sync/async option from the config and always generate both, and let the developers pass in 'loadLocalesAsync' into
initI18n
. So it will now be controlled through code rather than config.c. Third option is to simply add a note to update
formatters.ts
after changing the option.On a side note, million thanks for creating this library and being so active in maintaining it! I've only had <50 translations to deal with so far, but it has already saved my team a ton of time! ❤️
The text was updated successfully, but these errors were encountered: