-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
torn between changing the labels of the dropdowns when translating and having a separate page body for Bengali and English. Leaning towards having separate pages, this will require the pages to be kept to parity and will not be very DRY but keeps the language selection by className simple and maintains a good UX. This is DRY vs KISS moment
- Loading branch information
Showing
7 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
File renamed without changes.
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
24 changes: 24 additions & 0 deletions
24
frontEnd2024/functions/iarsenic-react/src/utils/LanguageSelector.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,24 @@ | ||
export default class LanguageSelector { | ||
static dataKey: string = 'language'; | ||
|
||
static init = () => { | ||
const language = LanguageSelector.get(); | ||
document.body.className = language; | ||
}; | ||
|
||
static get = (): 'english' | 'bengali' => { | ||
const language = localStorage.getItem(this.dataKey) || 'english'; | ||
|
||
if (language !== 'english' && language !== 'bengali') { | ||
throw new Error(`Invalid language in local storage ${language}`); | ||
} | ||
|
||
return language; | ||
}; | ||
|
||
static set = (language: 'english' | 'bengali') => { | ||
localStorage.setItem(LanguageSelector.dataKey, language); | ||
|
||
document.body.className = language; | ||
}; | ||
} |