feat: user selectable language

This commit is contained in:
Matt Kilgore
2024-09-08 14:19:01 -04:00
parent cf2edc8d34
commit b37cf24f09
4 changed files with 43 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ export type LocationViewPreferences = {
theme: DaisyTheme; theme: DaisyTheme;
itemsPerTablePage: number; itemsPerTablePage: number;
displayHeaderDecor: boolean; displayHeaderDecor: boolean;
language?: string;
}; };
/** /**
@@ -28,6 +29,7 @@ export function useViewPreferences(): Ref<LocationViewPreferences> {
theme: "homebox", theme: "homebox",
itemsPerTablePage: 10, itemsPerTablePage: 10,
displayHeaderDecor: true, displayHeaderDecor: true,
language: null,
}, },
{ mergeDefaults: true } { mergeDefaults: true }
); );

View File

@@ -124,7 +124,9 @@
"url": "URL", "url": "URL",
"user_profile": "User Profile", "user_profile": "User Profile",
"user_profile_sub": "Invite users, and manage your account.", "user_profile_sub": "Invite users, and manage your account.",
"display_header": "{ currentValue, select, true {Hide Header} false {Show Header} other {Not Hit}}" "display_header": "{ currentValue, select, true {Hide Header} false {Show Header} other {Not Hit}}",
"language": "Language",
"update_language": "Update Language"
}, },
"tools": { "tools": {
"reports": "Reports", "reports": "Reports",
@@ -163,5 +165,25 @@
"set_primary_photo_sub": "In version v0.10.0 of Homebox, the primary image field was added to attachments of type photo. This action will set the primary image field to the first image in the attachments array in the database, if it is not already set. '<a class=\"link\" href=\"https://github.com/hay-kot/homebox/pull/576\">'See GitHub PR #576'</a>'", "set_primary_photo_sub": "In version v0.10.0 of Homebox, the primary image field was added to attachments of type photo. This action will set the primary image field to the first image in the attachments array in the database, if it is not already set. '<a class=\"link\" href=\"https://github.com/hay-kot/homebox/pull/576\">'See GitHub PR #576'</a>'",
"set_primary_photo_button": "Set Primary Photo" "set_primary_photo_button": "Set Primary Photo"
} }
},
"languages": {
"ca": "Catalan",
"de": "German",
"en": "English",
"es": "Spanish",
"fr": "French",
"hu": "Hungarian",
"it": "Italian",
"nl": "Dutch",
"pl": "Polish",
"pt-BR": "Portuguese (Brazil)",
"ru": "Russian",
"sl": "Slovenian",
"sv": "Swedish",
"tr": "Turkish",
"zh-CN": "Chinese (Simplified)",
"zh-HK": "Chinese (Hong Kong)",
"zh-MO": "Chinese (Macau)",
"zh-TW": "Chinese (Traditional)"
} }
} }

View File

@@ -8,7 +8,6 @@
import MdiFill from "~icons/mdi/fill"; import MdiFill from "~icons/mdi/fill";
import MdiPencil from "~icons/mdi/pencil"; import MdiPencil from "~icons/mdi/pencil";
import MdiAccountMultiple from "~icons/mdi/account-multiple"; import MdiAccountMultiple from "~icons/mdi/account-multiple";
import type {ViewType} from "~/composables/use-preferences";
definePageMeta({ definePageMeta({
middleware: ["auth"], middleware: ["auth"],
@@ -35,6 +34,9 @@
function setDisplayHeader() { function setDisplayHeader() {
preferences.value.displayHeaderDecor = !preferences.value.displayHeaderDecor; preferences.value.displayHeaderDecor = !preferences.value.displayHeaderDecor;
} }
function setLanguage(lang: string) {
preferences.value.language = lang;
}
// Currency Selection // Currency Selection
const currency = ref<CurrenciesCurrency>({ const currency = ref<CurrenciesCurrency>({
@@ -370,6 +372,19 @@
{{ token }} {{ token }}
</div> </div>
</div> </div>
<div class="p-5 pt-0 form-control w-full">
<label class="label">
<span class="label-text">{{ $t("profile.language") }}</span>
</label>
<select v-model="$i18n.locale" class="select select-bordered">
<option v-for="lang in $i18n.availableLocales" :key="lang" :value="lang">
{{ $t(`languages.${lang}`) }}
</option>
</select>
<div class="mt-4">
<BaseButton size="sm" @click="setLanguage($i18n.locale)"> {{ $t("profile.update_language") }} </BaseButton>
</div>
</div>
</BaseCard> </BaseCard>
<BaseCard> <BaseCard>

View File

@@ -20,11 +20,12 @@ export default defineNuxtPlugin(({ vueApp }) => {
} }
return matched; return matched;
} }
const preferences = useViewPreferences();
const i18n = createI18n({ const i18n = createI18n({
fallbackLocale: "en", fallbackLocale: "en",
globalInjection: true, globalInjection: true,
legacy: false, legacy: false,
locale: checkDefaultLanguage() || "en", locale: preferences.value.language || checkDefaultLanguage() || "en",
messageCompiler, messageCompiler,
messages: messages(), messages: messages(),
}); });