Skip to content

Conversation

@Bharath-K-Shetty
Copy link
Contributor

@Bharath-K-Shetty Bharath-K-Shetty commented Aug 14, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR refactors the Translation Builder to improve translation retention and schema sync:

  • Add per-language in-memory caching to keep user edits across language switches.

  • Introduce mergeTranslations(local, backend, fallback) to deterministically merge values: local > backend > fallback.

  • Add a schema-driven incremental sync effect that adds new keys and removes deleted ones without overwriting existing translations.

  • Update language switcher to reuse cached translations and to fetch+merge only when needed.

  • Ensure translations saved to formSchema.translations reflect merged state.

Screenshots

Related Issue

https://openmrs.atlassian.net/browse/O3-4964

Other

@Bharath-K-Shetty Bharath-K-Shetty changed the title (refactor) O3-4964 - Refactor Translation Builder - preserve edits & sync keys incrementally (refactor) O3-4964 : Refactor Translation Builder - preserve edits & sync keys incrementally Aug 14, 2025
@Bharath-K-Shetty Bharath-K-Shetty marked this pull request as ready for review August 21, 2025 12:24
@NethmiRodrigo
Copy link
Collaborator

@Bharath-K-Shetty looks like the e2e tests are failing, because the translations gets added to the form schema. Have you looked into this?

@Bharath-K-Shetty
Copy link
Contributor Author

Bharath-K-Shetty commented Aug 21, 2025

@Bharath-K-Shetty looks like the e2e tests are failing, because the translations gets added to the form schema. Have you looked into this?

Yeah, Nethmi. I was looking into it. But while adding some fixes and rerunning the tests, it started failing due to another issue related to the name field, which isn’t actually affected by this PR.

Screenshot 2025-08-21 190324

@NethmiRodrigo
Copy link
Collaborator

NethmiRodrigo commented Aug 21, 2025

  • E2E Tests / run_e2e_tests (pull_request)

Looking at the PR's failing action - https://github.com/openmrs/openmrs-esm-form-builder/actions/runs/17126732891/job/48580139556?pr=825, I see a different failing error, where are you getting the error in your screenshot from? Hard to say why the error in your screenshot happens, I'll try running locally and see

@NethmiRodrigo
Copy link
Collaborator

NethmiRodrigo commented Aug 27, 2025

@Bharath-K-Shetty just fyi, the remaining failing e2e tests are related to your changes

@Bharath-K-Shetty
Copy link
Contributor Author

@Bharath-K-Shetty just fyi, the remaining failing e2e tests are related to your changes

I know @NethmiRodrigo ,but i was unable to test the changes i made.

@Bharath-K-Shetty
Copy link
Contributor Author

@NethmiRodrigo fixed the test cases.Ig all good now..!!

Comment on lines +69 to +70
// Removed the onUpdateSchema call from here
// The schema should only be updated on user-initiated actions
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: We can remove this comment since it doesn't explain the functionality. Lets instead add a comment at the top of this useEffect to explain its purpose

Suggested change
// Removed the onUpdateSchema call from here
// The schema should only be updated on user-initiated actions
// Removed the onUpdateSchema call from here
// The schema should only be updated on user-initiated actions

return formSchema ? extractTranslatableStrings(formSchema) : {};
}, [formSchema]);

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: Seems like this is something that needs to be run whenever either a translation string gets updated or the language gets changed. In that case can't we extract this into a function and just call it in hamdleUpdateValue and languageChanger. That way we can avoid using a useEffect altogether, they can be cause infinite renders and would be very hard to debug.

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.

2 participants