Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat(i18n): derive language selection from configured locales (#681)

arch1eaea6807f9f01
diff --git a/frontend/app/components/AppFooter.vue b/frontend/app/components/AppFooter.vue
index b1fff8a7..d6d658bc 100644
--- a/frontend/app/components/AppFooter.vue
+++ b/frontend/app/components/AppFooter.vue
@@ -137,28 +137,14 @@
</template>
<script setup lang="ts">
-const { t, locale, loadLocaleMessages, setLocale } = useI18nT();
+const { t, locale, localeCodes, loadLocaleMessages, setLocale } = useI18nT();
-const localeCodes = ['en', 'fr', 'de', 'uk', 'ko', 'it'] as const;
-type LocaleCode = (typeof localeCodes)[number];
-
-const isLocaleCode = (value: string): value is LocaleCode => localeCodes.includes(value as LocaleCode);
-
-const localeItems = computed(() => {
- const displayNames = typeof Intl.DisplayNames === 'function' ? new Intl.DisplayNames([locale.value], { type: 'language' }) : null;
-
- return localeCodes.map(code => ({
- id: code,
- label: capitalize(displayNames?.of(code) ?? code.toUpperCase()),
- }));
-});
-
-const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
+const localeItems = useLocaleOptions();
const selectLocale = async (nextLocale: string | number) => {
- const normalizedLocale = String(nextLocale);
+ const normalizedLocale = localeCodes.value.find(code => code === nextLocale);
- if (!isLocaleCode(normalizedLocale) || normalizedLocale === locale.value) {
+ if (!normalizedLocale || normalizedLocale === locale.value) {
return;
}
diff --git a/frontend/app/composables/useLocaleOptions.ts b/frontend/app/composables/useLocaleOptions.ts
new file mode 100644
index 00000000..f4b113bc
--- /dev/null
+++ b/frontend/app/composables/useLocaleOptions.ts
@@ -0,0 +1,15 @@
+const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
+
+/** Choices for language selectors, built from the locales declared in nuxt.config. */
+export const useLocaleOptions = () => {
+ const { locale, localeCodes } = useI18nT();
+
+ return computed(() => {
+ const displayNames = typeof Intl.DisplayNames === 'function' ? new Intl.DisplayNames([locale.value], { type: 'language' }) : null;
+
+ return localeCodes.value.map(code => ({
+ id: code,
+ label: capitalize(displayNames?.of(code) ?? code.toUpperCase()),
+ }));
+ });
+};
diff --git a/frontend/app/pages/dashboard/settings/_views/apparence.vue b/frontend/app/pages/dashboard/settings/_views/apparence.vue
index 22459ae9..58824c7b 100644
--- a/frontend/app/pages/dashboard/settings/_views/apparence.vue
+++ b/frontend/app/pages/dashboard/settings/_views/apparence.vue
@@ -12,6 +12,7 @@ const appColors = useAppColors();
const { t } = useI18nT();
const colorMode = useColorMode();
+const localeOptions = useLocaleOptions();
const options = computed(
() =>
@@ -33,14 +34,7 @@ const options = computed(
description: t('settings.appearance.setLanguageDesc'),
type: 'select' as const,
key: 'locale' as const,
- choices: [
- { label: 'English', id: 'en' },
- { label: 'Français', id: 'fr' },
- { label: 'Deutsch', id: 'de' },
- { label: 'Українська', id: 'uk' },
- { label: '한국어', id: 'ko' },
- { label: 'Italian', id: 'it' },
- ],
+ choices: localeOptions.value,
},
{
label: t('settings.appearance.chooseAccentColor'),
diff --git a/frontend/app/stores/preferences/constants.ts b/frontend/app/stores/preferences/constants.ts
index 69851766..d5ec05e3 100644
--- a/frontend/app/stores/preferences/constants.ts
+++ b/frontend/app/stores/preferences/constants.ts
@@ -1,9 +1,11 @@
+import type { Locale } from 'vue-i18n';
+
import type { TreeItem } from '~/helpers/TreeBuilder';
export type ANode<ID = number | string> = Omit<TreeItem<unknown, ID>, 'data' | 'route'>;
export const DEFAULT_PREFERENCES = {
- locale: 'en' as 'en' | 'fr',
+ locale: 'en' as Locale,
readAnnouncements: [] as string[],
printMode: false as boolean,
darkMode: false as boolean,