Skip to content

Commit

Permalink
Translate setting options
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Dec 10, 2024
1 parent 922abed commit 729694e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/dialog/content/setting/SettingItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Tag from 'primevue/tag'
import FormItem from '@/components/common/FormItem.vue'
import { useSettingStore } from '@/stores/settingStore'
import { SettingParams } from '@/types/settingTypes'
import type { SettingOption, SettingParams } from '@/types/settingTypes'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
Expand All @@ -29,13 +29,31 @@ const props = defineProps<{
}>()
const { t } = useI18n()
function translateOptions(options: (SettingOption | string)[]) {
return options.map((option) => {
const optionLabel = typeof option === 'string' ? option : option.text
const optionValue = typeof option === 'string' ? option : option.value
return {
text: t(
`settingsDialog.${props.setting.id}.options.${optionLabel}`,
optionLabel
),
value: optionValue
}
})
}
const formItem = computed(() => {
const normalizedId = props.setting.id.replace(/\./g, '_')
return {
...props.setting,
name: t(`settingsDialog.${normalizedId}.name`, props.setting.name),
tooltip: props.setting.tooltip
? t(`settingsDialog.${normalizedId}.tooltip`, props.setting.tooltip)
: undefined,
options: props.setting.options
? translateOptions(props.setting.options)
: undefined
}
})
Expand Down

0 comments on commit 729694e

Please sign in to comment.