Skip to content

Commit 76ed1b5

Browse files
authored
feat: set locale based on browser language when user is not logged in (#4635)
* feat: set locale based on browser language when user is not logged in * docs: comments for locale fallback logic
1 parent f6e4e50 commit 76ed1b5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

web/src/store/v2/user.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { makeAutoObservable } from "mobx";
33
import { authServiceClient, inboxServiceClient, userServiceClient } from "@/grpcweb";
44
import { Inbox } from "@/types/proto/api/v1/inbox_service";
55
import { Shortcut, User, UserSetting, UserStats } from "@/types/proto/api/v1/user_service";
6+
import { findNearestMatchedLanguage } from "@/utils/i18n";
67
import workspaceStore from "./workspace";
78

89
class LocalState {
@@ -223,7 +224,11 @@ export const initialUserStore = async () => {
223224
appearance: userSetting.appearance,
224225
});
225226
} catch {
226-
// Do nothing.
227+
// find the nearest matched lang based on the `navigator.language` if the user is unauthenticated or settings retrieval fails.
228+
const locale = findNearestMatchedLanguage(navigator.language);
229+
workspaceStore.state.setPartial({
230+
locale: locale,
231+
});
227232
}
228233
};
229234

0 commit comments

Comments
 (0)