-
Notifications
You must be signed in to change notification settings - Fork 59
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
(feat) Setup i18n for form engine lib #215
Conversation
271041b
to
e2f7ab8
Compare
3f0d89f
to
0c249a7
Compare
Size Change: -332 kB (-21%) 🎉 Total Size: 1.22 MB
ℹ️ View Unchanged
|
src/i18n.ts
Outdated
@@ -0,0 +1,23 @@ | |||
function loadResourcesFromFile() { | |||
const lang = window.i18next.language; |
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.
Rather than directly referencing window.i18next
, I'd mark i18next
as a peer dependency and import it in this file.
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.
Getting undefined with i18next
reference. Do you know what might be the reason?
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.
When in the app is that happening? It's vaguely possible that language
is undefined
, but window.i18next
should be set here. That's called after apps are registered, but it should be before anything gets mounted (since single-spa isn't called until setupI18n()
succeeds).
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.
window.18next.on is breaking the tests. Do we have a mock for it somewhere you're aware of, @ibacher? |
|
Hi @ibacher! |
src/withFormEngineTranslations.tsx
Outdated
export default function withFormEngineTranslations(WrappedComponent: React.ComponentType<any>) { | ||
return function WithTranslation(props: any) { | ||
return ( | ||
<I18nextProvider i18n={window.i18next} defaultNS="@openmrs/openmrs-form-engine-lib"> | ||
<WrappedComponent {...props} /> | ||
</I18nextProvider> | ||
); | ||
}; | ||
} |
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.
@vasharma05 There's a bunch of type errors in this file
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.
Should be resolved now, add the mock for I18nextProvider
bc5c95e
to
709eca1
Compare
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.
Really excellent work, @vasharma05!
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 some of the issue is that we're using i18next 21.x rather than 23.x? Anyways, very nice work!
Requirements
Summary
This PR implements internationalization in the Form Engine Library. Whenever the form engine lib is loaded, the lib will look for the active locale via the
window.i18next.language
and then load the particular file from the translation folder into the i18next instance. The same instance is then shared with the OHRIForm using theI18NextProvider
via a HOCwithTranslation
.Please note that in case the language is loaded, the corresponding translation resource will be loaded into the i18next in the runtime.
Screenshots
Related Issue
TBD
Other