-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remember to use language choice between browser sessions (#675)
### Summary & Motivation Ensure that a user's language selection is saved in the browser, so the same language is used when they sign out or later return. If an anonymous user changes the language while signing up, the created user will have the selected language set. Maintain the logic that sets the language to match the user's profile language upon signing in. This is achieved by saving the preferred language in the browser storage. Additionally, the `CreateUser` and `CompleteSignup` endpoints have been extended to include language preferences, ensuring that language settings are properly stored during user creation and signup completion. ### Downstream projects Please update the `/WebApp/routes/__root.tsx` file to initialize the correct locale. ```typescript import { useInitializeLocale } from "@repo/infrastructure/translations/useInitializeLocale"; function Root() { const navigate = useNavigate(); useInitializeLocale(); // Add this line return ( ... ) } ``` - [x] I have added tests, or done manual regression tests - [x] I have updated the documentation, if necessary
- Loading branch information
Showing
14 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ public DatabaseSeeder(AccountManagementDbContext accountManagementDbContext) | |
{ | ||
Tenant1 = Tenant.Create(new TenantId("tenant-1"), "[email protected]"); | ||
accountManagementDbContext.Tenants.AddRange(Tenant1); | ||
User1 = User.Create(Tenant1.Id, "[email protected]", UserRole.Owner, true); | ||
User1 = User.Create(Tenant1.Id, "[email protected]", UserRole.Owner, true, null); | ||
accountManagementDbContext.Users.AddRange(User1); | ||
|
||
accountManagementDbContext.SaveChanges(); | ||
|
This file contains 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 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 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 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 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 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
application/shared-webapp/infrastructure/translations/constants.ts
This file contains 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 const preferredLocaleKey = "preferred-locale"; |
22 changes: 22 additions & 0 deletions
22
application/shared-webapp/infrastructure/translations/useInitializeLocale.ts
This file contains 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,22 @@ | ||
import { useEffect, useContext } from "react"; | ||
import { preferredLocaleKey } from "./constants"; | ||
import { AuthenticationContext } from "../auth/AuthenticationProvider"; | ||
import { translationContext } from "./TranslationContext"; | ||
import type { Locale } from "./Translation"; | ||
|
||
export function useInitializeLocale() { | ||
const { userInfo } = useContext(AuthenticationContext); | ||
const { setLocale } = useContext(translationContext); | ||
|
||
useEffect(() => { | ||
if (userInfo?.isAuthenticated) { | ||
localStorage.setItem(preferredLocaleKey, document.documentElement.lang); | ||
} else { | ||
const storedLocale = localStorage.getItem(preferredLocaleKey) as Locale; | ||
if (storedLocale) { | ||
document.documentElement.lang = storedLocale; | ||
setLocale(storedLocale); | ||
} | ||
} | ||
}, [userInfo?.isAuthenticated, setLocale]); | ||
} |