From d174c485b08d3d775a58e3186eb98d55072fb3a0 Mon Sep 17 00:00:00 2001 From: malkja Date: Mon, 7 Oct 2024 11:04:28 +0200 Subject: [PATCH] fix: make 'item' label configurable --- examples/ahiqar-arabic-karshuni-local.html | 3 +- src/components/header/TitleBar.vue | 36 +++++++++++++++++----- src/utils/translations.js | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/examples/ahiqar-arabic-karshuni-local.html b/examples/ahiqar-arabic-karshuni-local.html index 396d19c6..d7c1b42e 100644 --- a/examples/ahiqar-arabic-karshuni-local.html +++ b/examples/ahiqar-arabic-karshuni-local.html @@ -159,7 +159,8 @@ "next_item": "Next Sheet", "previous_item": "Previous Sheet", "next_manifest": "Next Manuscript", - "previous_manifest": "Previous Manuscript" + "previous_manifest": "Previous Manuscript", + "item": "Sheet" }, } }); diff --git a/src/components/header/TitleBar.vue b/src/components/header/TitleBar.vue index 8bdb5b88..2abba5b9 100644 --- a/src/components/header/TitleBar.vue +++ b/src/components/header/TitleBar.vue @@ -18,7 +18,7 @@ class="t-px-2 text-gray-500 dark:text-gray-300" name="chevronRight" /> - {{ getItemLabel() }} {{ item.n }} + {{ getItemLabel(configStore.config) }} {{ item.n }} @@ -50,7 +50,9 @@ import { computed } from 'vue'; import { useConfigStore } from '@/stores/config'; import { useContentsStore } from '@/stores/contents' import BaseIcon from '@/components/base/BaseIcon.vue'; -import { getNavButtonsLabels } from '@/utils/translations'; +import { useI18n } from 'vue-i18n'; + +const { t } = useI18n() export interface Props { item: Item @@ -63,13 +65,33 @@ withDefaults(defineProps(), { const configStore = useConfigStore() const contentStore = useContentsStore() +const itemLabelKey = 'item' + const collectionTitle = computed(() => contentStore.collectionTitle); -const manifestTitle = computed(() => contentStore.manifest?.label ); +const manifestTitle = computed(() => contentStore.manifest?.label); + + +function isItemLabelInConfig(config) { + const lang = config['lang'] + const translations = config.translations[lang] + const numberKeys = Object.keys(translations).length -function getItemLabel() { - const navButtonsLabels = getNavButtonsLabels(configStore.config) - return navButtonsLabels[0].split(' ')[1] + if(numberKeys > 0) { + for (const key in translations) { + if(key === itemLabelKey) return true + } + } + return false } + +function getItemLabel(config) { + const lang = config['lang'] + if(isItemLabelInConfig(config)) { + return config['translations'][lang][itemLabelKey] + } + return t('item') +} + diff --git a/src/utils/translations.js b/src/utils/translations.js index dcc0ec05..4cd7e0b4 100644 --- a/src/utils/translations.js +++ b/src/utils/translations.js @@ -16,7 +16,7 @@ export function areNavButtonsLabelsInConfig(config) { } -export function getNavButtonsLabels(config, navButtonsDefaultTextArray) { +export function getNavButtonsLabels(config) { const lang = config['lang'] if (areNavButtonsLabelsInConfig(config)) {