|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { MathSettings } from '~/main/store/types' |
| 3 | +import * as Select from '@/components/ui/shadcn/select' |
| 4 | +import { |
| 5 | + formatMathDate, |
| 6 | + formatMathNumber, |
| 7 | +} from '@/composables/math-notebook/math-engine/format' |
| 8 | +import { i18n, store } from '@/electron' |
| 9 | +
|
| 10 | +const settings = reactive(store.preferences.get('math') as MathSettings) |
| 11 | +
|
| 12 | +watch( |
| 13 | + settings, |
| 14 | + () => { |
| 15 | + store.preferences.set('math', JSON.parse(JSON.stringify(settings))) |
| 16 | + }, |
| 17 | + { deep: true }, |
| 18 | +) |
| 19 | +
|
| 20 | +const localeOptions = [ |
| 21 | + { label: 'English (US)', value: 'en-US' }, |
| 22 | + { label: 'English (UK)', value: 'en-GB' }, |
| 23 | + { label: 'Deutsch', value: 'de-DE' }, |
| 24 | + { label: 'Fran\u00E7ais', value: 'fr-FR' }, |
| 25 | + { label: '\u0420\u0443\u0441\u0441\u043A\u0438\u0439', value: 'ru-RU' }, |
| 26 | + { label: 'Espa\u00F1ol', value: 'es-ES' }, |
| 27 | + { label: 'Portugu\u00EAs (BR)', value: 'pt-BR' }, |
| 28 | + { label: '\u65E5\u672C\u8A9E', value: 'ja-JP' }, |
| 29 | + { label: '\u4E2D\u6587', value: 'zh-CN' }, |
| 30 | + { label: '\uD55C\uAD6D\uC5B4', value: 'ko-KR' }, |
| 31 | + { label: 'Italiano', value: 'it-IT' }, |
| 32 | + { label: 'Polski', value: 'pl-PL' }, |
| 33 | + { |
| 34 | + label: '\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430', |
| 35 | + value: 'uk-UA', |
| 36 | + }, |
| 37 | + { label: 'T\u00FCrk\u00E7e', value: 'tr-TR' }, |
| 38 | + { label: 'Nederlands', value: 'nl-NL' }, |
| 39 | +] |
| 40 | +
|
| 41 | +const decimalPlacesOptions = Array.from({ length: 15 }, (_, i) => ({ |
| 42 | + label: String(i), |
| 43 | + value: String(i), |
| 44 | +})) |
| 45 | +
|
| 46 | +const localePreview = computed(() => { |
| 47 | + const num = formatMathNumber( |
| 48 | + 1234.5678, |
| 49 | + settings.locale, |
| 50 | + settings.decimalPlaces, |
| 51 | + ) |
| 52 | + const date = formatMathDate(new Date(), settings.locale) |
| 53 | + return `${num} \u00B7 ${date}` |
| 54 | +}) |
| 55 | +
|
| 56 | +const decimalPlacesPreview = computed(() => { |
| 57 | + return `1/3 = ${formatMathNumber(1 / 3, settings.locale, settings.decimalPlaces)}` |
| 58 | +}) |
| 59 | +</script> |
| 60 | + |
| 61 | +<template> |
| 62 | + <div class="space-y-4"> |
| 63 | + <UiMenuFormSection :label="i18n.t('preferences:math.label')"> |
| 64 | + <UiMenuFormItem :label="i18n.t('preferences:math.locale.label')"> |
| 65 | + <Select.Select v-model="settings.locale"> |
| 66 | + <Select.SelectTrigger class="w-64"> |
| 67 | + <Select.SelectValue /> |
| 68 | + </Select.SelectTrigger> |
| 69 | + <Select.SelectContent> |
| 70 | + <Select.SelectItem |
| 71 | + v-for="option in localeOptions" |
| 72 | + :key="option.value" |
| 73 | + :value="option.value" |
| 74 | + > |
| 75 | + {{ option.label }} |
| 76 | + </Select.SelectItem> |
| 77 | + </Select.SelectContent> |
| 78 | + </Select.Select> |
| 79 | + <template #description> |
| 80 | + {{ i18n.t("preferences:math.locale.description") }} |
| 81 | + {{ localePreview }} |
| 82 | + </template> |
| 83 | + </UiMenuFormItem> |
| 84 | + <UiMenuFormItem :label="i18n.t('preferences:math.decimalPlaces.label')"> |
| 85 | + <Select.Select |
| 86 | + :model-value="String(settings.decimalPlaces)" |
| 87 | + @update:model-value="settings.decimalPlaces = Number($event)" |
| 88 | + > |
| 89 | + <Select.SelectTrigger class="w-64"> |
| 90 | + <Select.SelectValue /> |
| 91 | + </Select.SelectTrigger> |
| 92 | + <Select.SelectContent> |
| 93 | + <Select.SelectItem |
| 94 | + v-for="option in decimalPlacesOptions" |
| 95 | + :key="option.value" |
| 96 | + :value="option.value" |
| 97 | + > |
| 98 | + {{ option.label }} |
| 99 | + </Select.SelectItem> |
| 100 | + </Select.SelectContent> |
| 101 | + </Select.Select> |
| 102 | + <template #description> |
| 103 | + {{ i18n.t("preferences:math.decimalPlaces.description") }} |
| 104 | + {{ decimalPlacesPreview }} |
| 105 | + </template> |
| 106 | + </UiMenuFormItem> |
| 107 | + </UiMenuFormSection> |
| 108 | + </div> |
| 109 | +</template> |
0 commit comments