Skip to content

Commit

Permalink
feat(language): Update language store for auto language detection
Browse files Browse the repository at this point in the history
This commit updates the `useLanguageStore` in `language.ts` to support auto language detection. Instead of hardcoding the language as "en", the store now sets the language to "auto". When updating the language using `updateLanguage` action, if the language parameter is "auto", it will use the auto-detected language value from `autoLanguage` instead. The `updateAvailableLanguages` action also updates the `availableLanguages` state using `gettext.available`.
  • Loading branch information
realashleybailey committed Oct 4, 2023
1 parent 45ac906 commit c7e137f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/src/stores/language.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { defineStore } from "pinia";
import type { Language } from "vue3-gettext";
import { language as autoLanguage } from "@/i18n";
import { defineStore } from "pinia";

export const useLanguageStore = defineStore("language", {
state: () => ({
language: "en" as string,
language: "auto" as string,
availableLanguages: {} as { [key: string]: string },
}),
actions: {
setLanguage(language: string) {
this.language = language;
},
updateLanguage(gettext: Language, language: string) {
gettext.current = language;
gettext.current = language === "auto" ? autoLanguage : language;
},
updateAvailableLanguages(gettext: Language) {
this.availableLanguages = gettext.available;
Expand Down

0 comments on commit c7e137f

Please sign in to comment.