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

set app namespace in appcontext #36

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

eperedo
Copy link
Contributor

@eperedo eperedo commented Jun 4, 2024

📌 References

📝 Implementation

  • Update i18n types
  • set default namespace in app-context.ts

The Problem

In our applications we have a locales/index.js file that set the namespace for the translations.

const namespace = 'homepage-app';
...
i18n.setDefaultNamespace(namespace);

The problem is that we use libraries like d2-ui-components or feedback-component that also have their own locale/index.js files:

const namespace = 'd2-ui-components';
...
i18n.setDefaultNamespace(namespace);

so eventually the application namespace will be overwritten by one of these libraries.

Fast solution

Force the whole application to use the namespace of the app by doing it in the app-context.ts file

i18n.setDefaultNamespace("homepage-app");

if you get the error: Property 'setDefaultNamespace' does not exist on type 'typeof import("@dhis2/d2-i18n")'
look for the i18n.d.ts file and add the type in there:

declare module "@dhis2/d2-i18n" {
    // ...
    export function setDefaultNamespace(namespace: string);
}

📹 Screenshots/Screen capture

🔥 Testing

For testing purposes I'm only adding a translation for the string Available Home Pages
image

#8694qwkw6

@eperedo eperedo requested a review from MiquelAdell June 4, 2024 15:58
@ifoche
Copy link
Member

ifoche commented Jun 4, 2024

Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

@MiquelAdell MiquelAdell merged commit 2ade2d5 into development Jun 13, 2024
1 check passed
@MiquelAdell MiquelAdell deleted the fix/translation-namespace branch June 13, 2024 09:37
@tokland
Copy link
Contributor

tokland commented Aug 1, 2024

Related: EyeSeeTea/dhis2-app-skeleton@54fcc22

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.

4 participants