Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'formatters.ts' not re-generated when changing 'loadLocaleAsync' option #64

Closed
es-lynn opened this issue Jul 15, 2021 · 2 comments · Fixed by #162
Closed

'formatters.ts' not re-generated when changing 'loadLocaleAsync' option #64

es-lynn opened this issue Jul 15, 2021 · 2 comments · Fixed by #162
Labels
help wanted Extra attention is needed

Comments

@es-lynn
Copy link

es-lynn commented Jul 15, 2021

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! ❤️

@ivanhofer
Copy link
Owner

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.

@ivanhofer ivanhofer added the help wanted Extra attention is needed label Jul 19, 2021
@ivanhofer
Copy link
Owner

In version 3.0.0 the async initialization of the formatters was removed.
Please visit the release post for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants