Skip to content

Commit

Permalink
persist locale in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
samluiz committed May 28, 2024
1 parent 52442c6 commit 8be6d2b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,31 @@ const setThemeOnLocalStorage = (darkMode: boolean) => {
localStorage.setItem("isDarkMode", JSON.stringify(darkMode));
};
const getLocaleFromLocalStorage = () => {
const localeLs = localStorage.getItem("locale");
if (localeLs) {
locale.value = JSON.parse(localeLs);
} else {
locale.value = isUserPortugueseSpeaker() ? "pt-BR" : "en-US";
}
};
const setLocaleOnLocalStorage = (locale: string) => {
localStorage.setItem("locale", locale);
};
onMounted(() => {
getThemeFromLocalStorage();
watch(isDarkMode, (newVal) => {
setThemeOnLocalStorage(newVal);
});
if (isUserPortugueseSpeaker()) {
locale.value = "pt-BR";
} else {
locale.value = "en-US";
}
getLocaleFromLocalStorage();
watch(locale, (newVal) => {
setLocaleOnLocalStorage(newVal);
});
fetchData();
});
Expand Down

0 comments on commit 8be6d2b

Please sign in to comment.