Replace cookie by local storage to store language
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { FALLBACK_LANGUAGE } from "../Enum/EnvironmentVariable";
|
||||
import { getCookie } from "../Utils/Cookies";
|
||||
|
||||
export type Language = {
|
||||
language: string;
|
||||
@@ -90,7 +89,7 @@ class Translator {
|
||||
);
|
||||
|
||||
if (!languageObject) {
|
||||
return reject();
|
||||
return reject(new Error("Language not found in cache"));
|
||||
}
|
||||
|
||||
this.currentLanguageObject = languageObject as LanguageObject;
|
||||
@@ -135,13 +134,13 @@ class Translator {
|
||||
*/
|
||||
private defineCurrentLanguage() {
|
||||
const navigatorLanguage: string | undefined = navigator.language;
|
||||
const cookieLanguage = getCookie("language");
|
||||
const localStorageLanguage = localStorage.getItem("language");
|
||||
let currentLanguage = undefined;
|
||||
|
||||
if (cookieLanguage && typeof cookieLanguage === "string") {
|
||||
const cookieLanguageObject = this.getLanguageByString(cookieLanguage);
|
||||
if (cookieLanguageObject) {
|
||||
currentLanguage = cookieLanguageObject;
|
||||
if (localStorageLanguage && typeof localStorageLanguage === "string") {
|
||||
const localStorageLanguageObject = this.getLanguageByString(localStorageLanguage);
|
||||
if (localStorageLanguageObject) {
|
||||
currentLanguage = localStorageLanguageObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +206,7 @@ class Translator {
|
||||
/**
|
||||
* Get translation by a key and formatted with params by {{ }} tag
|
||||
* @param {string} key Translation key
|
||||
* @param {{ [key: string]: string | number }} params Tags to replace by value
|
||||
* @param {TranslationParams} params Tags to replace by value
|
||||
* @returns {string} Translation formatted
|
||||
*/
|
||||
public _(key: string, params?: TranslationParams): string {
|
||||
|
||||
Reference in New Issue
Block a user