Skip to content

Feature/custom translations frontend #857

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

Merged

Conversation

rvveber
Copy link
Collaborator

@rvveber rvveber commented Apr 8, 2025

Adds the possibilty to inject/override custom translations at runtime.

@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from 10cd759 to d285bd1 Compare April 8, 2025 14:36
@rvveber rvveber mentioned this pull request Apr 8, 2025
9 tasks
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from 4ff16fa to 81fd1ed Compare April 8, 2025 15:12
@AntoLC AntoLC requested review from AntoLC and lunika April 8, 2025 15:19
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from b9b16aa to 06b91a1 Compare April 14, 2025 17:14
@rvveber rvveber requested a review from AntoLC April 14, 2025 17:14
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from 06b91a1 to af92119 Compare April 16, 2025 10:47
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from a65fca6 to cddc429 Compare May 7, 2025 14:21
@rvveber rvveber requested a review from AntoLC May 7, 2025 14:26
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from cddc429 to 9a9b717 Compare May 7, 2025 14:28
@rvveber rvveber marked this pull request as draft May 8, 2025 09:44
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 3 times, most recently from 5f855f1 to ed137ef Compare May 8, 2025 17:53
@rvveber rvveber marked this pull request as ready for review May 8, 2025 17:57
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from ed137ef to 2e7f552 Compare May 12, 2025 14:52
@rvveber rvveber marked this pull request as draft May 12, 2025 14:58
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from 2e7f552 to 6a036b3 Compare May 12, 2025 15:02
@rvveber rvveber marked this pull request as ready for review May 12, 2025 15:22
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from 6a036b3 to 6a75453 Compare May 12, 2025 15:43
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from 0080fdc to bf65c8b Compare May 13, 2025 10:51
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 3 times, most recently from d86f811 to f7abb03 Compare May 13, 2025 11:23

const availableFrontendLanguages = useMemo(
() => Object.keys(i18n?.options?.resources || { en: '<- fallback' }),
[i18n],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[i18n],
[i18n?.options?.resources],

Comment on lines 65 to 70
log('Updating frontend language (%O)', {
requested: language,
from: i18n.resolvedLanguage,
to: closestFrontendLanguage,
});
void i18n.changeLanguage(closestFrontendLanguage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same it is part of the development part, should be removed.

currentBackendLanguage,
currentFrontendLanguage,
changeLanguageSynchronized,
currentUser,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is currentUser necessary ?

[changeBackendLanguage, changeFrontendLanguage, currentUser],
);

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have the feeling this useEffect is trigger often.

Copy link
Collaborator Author

@rvveber rvveber May 27, 2025

Choose a reason for hiding this comment

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

It was not good to have the useEffect in the useSynchronizedLanguage hook anyways,
as it added 1 useEffect call, everytime useSynchronizedLanguage() is instantiated.

To counteract, one would need to develop a Provider to share Context.
Since i didn't see the need for a dedicated Provider just to prevent a race condition / enable singleton pattern, i instead moved the useEffect to the ConfigProvider and simplified useSynchronizedLanguage to only be responsible for change language.

The default behavior ("sync frontend detected language to backend if backend language is null") is now handeled in the ConfigProvider. It looks more on par with what we already have in there.

@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from f7abb03 to 4d59da8 Compare May 27, 2025 15:15
@rvveber rvveber requested a review from AntoLC May 27, 2025 15:20
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 3 times, most recently from 372b8d9 to bb1c96e Compare May 27, 2025 15:47
Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

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

Well done, very useful feature. 🚀

@rvveber rvveber force-pushed the feature/custom-translations-frontend branch 2 times, most recently from b7ed541 to 5ad421c Compare June 3, 2025 15:33
rvveber added 5 commits June 3, 2025 17:35
Part of customization PoC

Signed-off-by: Robin Weber <[email protected]>
Part of customization PoC

Signed-off-by: Robin Weber <[email protected]>
Introduces dedicated mutations
(for authentication/user operations)
separating them from queries to align with best practices
for data fetching and state management.

Queries remain responsible for READ operations, while mutations
now handle CREATE, UPDATE, and DELETE actions (for user data)
improving separation of concerns.

Signed-off-by: Robin Weber <[email protected]>
- Refactors "useTranslationsCustomizer" to "useCustomTranslations"
- Refactors "useLanguageSynchronizer" to "useSynchronizedLanguage"
- Refactors "LanguagePicker" to better reflect its component role
- Refactors "LanguagePicker" to use "useSynchronizedLangue"
- Removes unused "useChangeUserLanguage"
- To change the user language, use "useAuthMutation" instead

Signed-off-by: Robin Weber <[email protected]>
- Language will only be changed if different from current language
- Added test for custom translations

Signed-off-by: Robin Weber <[email protected]>
@rvveber rvveber force-pushed the feature/custom-translations-frontend branch from 5ad421c to 94e9978 Compare June 3, 2025 15:35
@AntoLC AntoLC merged commit 94e9978 into suitenumerique:main Jun 4, 2025
19 of 20 checks passed
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