-
Notifications
You must be signed in to change notification settings - Fork 337
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
AntoLC
merged 5 commits into
suitenumerique:main
from
rvveber:feature/custom-translations-frontend
Jun 4, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4ad26a
✨(frontend) Adds customization for translations
rvveber dc06315
📝(documentation) adds customization for translations
rvveber 5962f7a
♻️(frontend) Separate mutations from queries for auth logic
rvveber fa83955
♻️(frontend) Refactor language-related code
rvveber 94e9978
✅(tests) Add & adapt language tests
rvveber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
UseMutationResult, | ||
useMutation, | ||
useQueryClient, | ||
} from '@tanstack/react-query'; | ||
|
||
import { APIError, errorCauses, fetchAPI } from '@/api'; | ||
import { User } from '@/features/auth/api/types'; | ||
import { KEY_AUTH } from '@/features/auth/api/useAuthQuery'; | ||
|
||
type UserUpdateRequest = Partial<User>; | ||
|
||
async function updateUser(userUpdateData: UserUpdateRequest): Promise<User> { | ||
const response = await fetchAPI(`users/${userUpdateData.id}/`, { | ||
method: 'PATCH', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(userUpdateData), | ||
}); | ||
if (!response.ok) { | ||
throw new APIError( | ||
`Failed to update the user`, | ||
await errorCauses(response, userUpdateData), | ||
); | ||
} | ||
return response.json() as Promise<User>; | ||
} | ||
|
||
export const useUserUpdate = (): UseMutationResult< | ||
User, | ||
APIError, | ||
UserUpdateRequest | ||
> => { | ||
const queryClient = useQueryClient(); | ||
|
||
const mutationResult = useMutation<User, APIError, UserUpdateRequest>({ | ||
mutationFn: updateUser, | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries({ queryKey: [KEY_AUTH] }); | ||
}, | ||
onError: (error) => { | ||
console.error('Error updating user', error); | ||
}, | ||
}); | ||
|
||
return mutationResult; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
src/frontend/apps/impress/src/features/language/api/useChangeUserLanguage.tsx
This file was deleted.
Oops, something went wrong.
37 changes: 14 additions & 23 deletions
37
.../src/features/language/LanguagePicker.tsx → ...es/language/components/LanguagePicker.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/frontend/apps/impress/src/features/language/components/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LanguagePicker'; |
2 changes: 2 additions & 0 deletions
2
src/frontend/apps/impress/src/features/language/hooks/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './useSynchronizedLanguage'; | ||
export * from './useCustomTranslations'; |
27 changes: 27 additions & 0 deletions
27
src/frontend/apps/impress/src/features/language/hooks/useCustomTranslations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Resource } from 'i18next'; | ||
import { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const useCustomTranslations = () => { | ||
const { i18n } = useTranslation(); | ||
|
||
// Overwrite translations with a resource | ||
const customizeTranslations = useCallback( | ||
(currentCustomTranslations: Resource) => { | ||
Object.entries(currentCustomTranslations).forEach(([lng, namespaces]) => { | ||
Object.entries(namespaces).forEach(([ns, value]) => { | ||
i18n.addResourceBundle(lng, ns, value, true, true); | ||
}); | ||
}); | ||
// trigger re-render | ||
if (Object.entries(currentCustomTranslations).length > 0) { | ||
void i18n.changeLanguage(i18n.language); | ||
} | ||
}, | ||
[i18n], | ||
); | ||
|
||
return { | ||
customizeTranslations, | ||
}; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.