Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-3589] improvement: reset language to default on sign out (#6775)

Prateek Shouryaf82d4a9eadb9
diff --git a/packages/i18n/src/constants/language.ts b/packages/i18n/src/constants/language.ts
index ab58bf6298..132ee68c96 100644
--- a/packages/i18n/src/constants/language.ts
+++ b/packages/i18n/src/constants/language.ts
@@ -19,4 +19,4 @@ export const SUPPORTED_LANGUAGES: ILanguageOption[] = [
{ label: "ν•œκ΅­μ–΄", value: "ko" },
];
-export const STORAGE_KEY = "userLanguage";
+export const LANGUAGE_STORAGE_KEY = "userLanguage";
diff --git a/packages/i18n/src/store/index.ts b/packages/i18n/src/store/index.ts
index dafa61027c..c711e0e63a 100644
--- a/packages/i18n/src/store/index.ts
+++ b/packages/i18n/src/store/index.ts
@@ -3,7 +3,7 @@ import get from "lodash/get";
import merge from "lodash/merge";
import { makeAutoObservable, runInAction } from "mobx";
// constants
-import { FALLBACK_LANGUAGE, SUPPORTED_LANGUAGES, STORAGE_KEY } from "../constants";
+import { FALLBACK_LANGUAGE, SUPPORTED_LANGUAGES, LANGUAGE_STORAGE_KEY } from "../constants";
// core translations imports
import coreEn from "../locales/en/core.json";
// types
@@ -48,14 +48,14 @@ export class TranslationStore {
private initializeLanguage() {
if (typeof window === "undefined") return;
- const savedLocale = localStorage.getItem(STORAGE_KEY) as TLanguage;
+ const savedLocale = localStorage.getItem(LANGUAGE_STORAGE_KEY) as TLanguage;
if (this.isValidLanguage(savedLocale)) {
this.setLanguage(savedLocale);
return;
}
- const browserLang = this.getBrowserLanguage();
- this.setLanguage(browserLang);
+ // Fallback to default language
+ this.setLanguage(FALLBACK_LANGUAGE);
}
/** Loads the translations for the current language */
@@ -175,40 +175,6 @@ export class TranslationStore {
return lang !== null && this.availableLanguages.some((l) => l.value === lang);
}
- /** Checks if a language code is similar to any supported language */
- private findSimilarLanguage(lang: string): TLanguage | null {
- // Convert to lowercase for case-insensitive comparison
- const normalizedLang = lang.toLowerCase();
-
- // Find a supported language that includes or is included in the browser language
- const similarLang = this.availableLanguages.find(
- (l) => normalizedLang.includes(l.value.toLowerCase()) || l.value.toLowerCase().includes(normalizedLang)
- );
-
- return similarLang ? similarLang.value : null;
- }
-
- /** Gets the browser language based on the navigator.language */
- private getBrowserLanguage(): TLanguage {
- const browserLang = navigator.language;
-
- // Check exact match first
- if (this.isValidLanguage(browserLang)) {
- return browserLang;
- }
-
- // Check base language without region code
- const baseLang = browserLang.split("-")[0];
- if (this.isValidLanguage(baseLang)) {
- return baseLang as TLanguage;
- }
-
- // Try to find a similar language
- const similarLang = this.findSimilarLanguage(browserLang) || this.findSimilarLanguage(baseLang);
-
- return similarLang || FALLBACK_LANGUAGE;
- }
-
/**
* Gets the cache key for the given key and locale
* @param key - the key to get the cache key for
@@ -293,7 +259,7 @@ export class TranslationStore {
}
if (typeof window !== "undefined") {
- localStorage.setItem(STORAGE_KEY, lng);
+ localStorage.setItem(LANGUAGE_STORAGE_KEY, lng);
document.documentElement.lang = lng;
}
diff --git a/web/core/store/root.store.ts b/web/core/store/root.store.ts
index 5a10df45be..d06ed2418d 100644
--- a/web/core/store/root.store.ts
+++ b/web/core/store/root.store.ts
@@ -1,4 +1,6 @@
import { enableStaticRendering } from "mobx-react";
+// plane imports
+import { FALLBACK_LANGUAGE, LANGUAGE_STORAGE_KEY } from "@plane/i18n";
// plane web store
import { CommandPaletteStore, ICommandPaletteStore } from "@/plane-web/store/command-palette.store";
import { RootStore } from "@/plane-web/store/root.store";
@@ -97,7 +99,7 @@ export class CoreRootStore {
resetOnSignOut() {
// handling the system theme when user logged out from the app
localStorage.setItem("theme", "system");
-
+ localStorage.setItem(LANGUAGE_STORAGE_KEY, FALLBACK_LANGUAGE);
this.router = new RouterStore();
this.commandPalette = new CommandPaletteStore();
this.instance = new InstanceStore();