-
Notifications
You must be signed in to change notification settings - Fork 12
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
chore: fix i18n imports and usage #1380
base: master
Are you sure you want to change the base?
Conversation
Make them all the same and import from locales/index.js to ensure the translations are always added.
errorText: i18n.t( | ||
'There was a problem loading items. Try again or contact your system administrator.' | ||
), | ||
noDataText: i18n.t('No items found. Create a new to get started.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a weird sentence (I know this was already present): "Create a new to get started."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is perhaps a better solution to this problem. The current solution has 2 downsides as I see it:
- importing from the file
locales/index.js
is less ergonomic than importing from the package@dhis2/d2-i18n
- The file
locales/index.js
actually does do quite a lot. If we import this file in a lot of places the calls to.addResources()
will be happening often. I don't know if this is a problem, but doesn't seem desirable
I'm thinking the following:
- To ensure we always "load the translations" for consumers of the lib, we can import the
locales/index.js
file from our own index file, since consuming apps should be importing from there exclusively (if this is not true, I think the current implementation in this PR is probably the best solution) - To avoid running the code in
locales/index.js
multiple times, we probably would have to do a dynamic import, i.e. something like this:- Import the i18n singleton from
@dhis2/d2-i18n
- check if our translations have been added (not sure how, but I think it may be possible)
- If not dynamically import the
locales/index.js
file
- Import the i18n singleton from
- We could consider checking how this is done in @dhis2/ui
Key features
i18n
everywherei18n.t
gets executed for all translatable stringsDescription
We had 2 ways of import
i18n
in the library.I don't think we had problems due to this, but for consistency sake and to avoid possible issues, it's good to import everywhere from the same place.
Importing from
locales/index.js
ensures that the library translations are added and are available in the consumer apps.Some strings did not show translated in consumer apps, the reason is likely marking
i18n.t
strings in static constants or objects, in that case thei18n.t
function is not called at runtime.