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

chore: fix i18n imports and usage #1380

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

edoardo
Copy link
Member

@edoardo edoardo commented Nov 18, 2022

Key features

  1. use the same import for i18n everywhere
  2. ensure i18n.t gets executed for all translatable strings

Description

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 the i18n.t function is not called at runtime.

@edoardo edoardo marked this pull request as ready for review November 1, 2024 12:22
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.'),
Copy link
Collaborator

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."

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a 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:

  1. importing from the file locales/index.js is less ergonomic than importing from the package @dhis2/d2-i18n
  2. 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:

  1. 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)
  2. 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:
    1. Import the i18n singleton from @dhis2/d2-i18n
    2. check if our translations have been added (not sure how, but I think it may be possible)
    3. If not dynamically import the locales/index.js file
  3. We could consider checking how this is done in @dhis2/ui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants