Skip to content

Commit 0b29d85

Browse files
martinapippiwkramer
authored andcommitted
add datetimeFormats i18n
1 parent c91b373 commit 0b29d85

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

src/components/general/DateTimeSlider.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import { findDateIndex } from '@/lib/utils/findDateIndex'
110110
111111
import VueSlider from 'vue-slider-component'
112112
import 'vue-slider-component/theme/antd.css'
113+
import { useI18n } from 'vue-i18n'
113114
114115
interface Properties {
115116
selectedDate?: Date
@@ -145,6 +146,7 @@ const doFollowNow = ref(props.doFollowNow)
145146
let followNowIntervalTimer: ReturnType<typeof setInterval> | null = null
146147
147148
const hideLabel = ref(true)
149+
const { d } = useI18n()
148150
149151
onMounted(() => {
150152
if (props.doFollowNow) {
@@ -258,7 +260,8 @@ const playButtonColor = computed(() =>
258260
259261
const dateString = computed(() =>
260262
props.dates[dateIndex.value]
261-
? props.dates[dateIndex.value].toLocaleString()
263+
? // ? props.dates[dateIndex.value].toLocaleString()
264+
d(props.dates[dateIndex.value], 'datetimeslider')
262265
: '',
263266
)
264267

src/components/time-control/IntervalSelector.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<template>
22
<v-list class="interval-list" density="compact">
3-
<v-list-item :active="0 === selectedIndex" @click="onSelectInterval(0)">
4-
Default
3+
<v-list-item
4+
:active="0 === selectedIndex"
5+
@click="onSelectInterval(0)"
6+
v-t="'time.default'"
7+
>
58
<template v-slot:append="{ isActive }">
69
<v-icon v-show="isActive" small> mdi-check </v-icon>
710
</template>
@@ -10,14 +13,14 @@
1013
:active="1 === selectedIndex"
1114
@click="onSelectInterval(1)"
1215
disabled
16+
v-t="'time.custom'"
1317
>
14-
Custom
1518
<template v-slot:append="{ isActive }">
1619
<v-icon v-show="isActive" small> mdi-check </v-icon>
1720
</template>
1821
</v-list-item>
1922
<v-divider></v-divider>
20-
<v-list-subheader>Period presets</v-list-subheader>
23+
<v-list-subheader v-t="'time.presets'"></v-list-subheader>
2124
<v-list-item
2225
v-for="(item, index) in props.items"
2326
:key="index"
@@ -35,6 +38,7 @@
3538
<script setup lang="ts">
3639
import { DateTime, Duration } from 'luxon'
3740
import { onBeforeMount, ref, watch } from 'vue'
41+
import { useI18n } from 'vue-i18n'
3842
3943
interface Props {
4044
modelValue: string
@@ -52,6 +56,7 @@ const props = withDefaults(defineProps<Props>(), {
5256
5357
const emit = defineEmits(['update:modelValue'])
5458
const selectedIndex = ref(0)
59+
const { locale } = useI18n()
5560
5661
onBeforeMount(() => {
5762
updateIndex(props.modelValue)
@@ -66,12 +71,16 @@ const intervalToLocaleString = (interval: string) => {
6671
const endDateTime = DateTime.fromJSDate(props.now).plus(
6772
Duration.fromISO(parts[1]),
6873
)
69-
return startDateTime.toRelative() + ' / ' + endDateTime.toRelative()
74+
return (
75+
startDateTime.setLocale(locale.value).toRelative() +
76+
' / ' +
77+
endDateTime.setLocale(locale.value).toRelative()
78+
)
7079
} else {
7180
const startDateTime = DateTime.fromJSDate(props.now).plus(
7281
Duration.fromISO(parts[0]),
7382
)
74-
return startDateTime.toRelative()
83+
return startDateTime.setLocale(locale.value).toRelative()
7584
}
7685
}
7786

src/components/time-control/TimeControlMenu.vue

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
<v-menu left bottom :close-on-content-click="false" class="menu">
33
<template v-slot:activator="{ props, isActive }">
44
<v-btn v-bind="props" variant="tonal" rounded>
5-
{{
6-
Intl.DateTimeFormat('nl', {
7-
hour: '2-digit',
8-
minute: '2-digit',
9-
timeZoneName: 'short',
10-
}).format(store.systemTime)
11-
}}
5+
{{ $d(store.systemTime, 'time') }}
126
<v-icon>{{ isActive ? 'mdi-chevron-up' : 'mdi-chevron-down' }}</v-icon>
137
</v-btn>
148
</template>
@@ -85,15 +79,9 @@
8579
</v-col>
8680
</v-row>
8781
<v-card-actions>
88-
<span>Browser time:</span>
82+
<span v-t="'time.browserTime'"></span>
8983
<v-chip small>
90-
{{
91-
Intl.DateTimeFormat('nl', {
92-
hour: '2-digit',
93-
minute: '2-digit',
94-
timeZoneName: 'short',
95-
}).format(store.systemTime)
96-
}}
84+
{{ $d(store.systemTime, 'time') }}
9785
</v-chip>
9886
</v-card-actions>
9987
</v-card>
@@ -106,7 +94,9 @@ import IntervalSelector from './IntervalSelector.vue'
10694
import { ref, computed } from 'vue'
10795
import { useSystemTimeStore } from '../../stores/systemTime'
10896
import { DateTime } from 'luxon'
97+
import { useI18n } from 'vue-i18n'
10998
99+
const { locale } = useI18n()
110100
const store = useSystemTimeStore()
111101
const datesAreValid = ref(true)
112102
const DATE_FMT = 'yyyy-MM-dd'
@@ -142,7 +132,9 @@ const endDates = computed({
142132
143133
const startDateString = computed({
144134
get() {
145-
return DateTime.fromJSDate(dates.value[0]).toFormat(DATE_FMT)
135+
return DateTime.fromJSDate(dates.value[0])
136+
.setLocale(locale.value)
137+
.toFormat(DATE_FMT)
146138
},
147139
set(newValue: string) {
148140
dates.value[0] = DateTime.fromFormat(newValue, DATE_FMT).toJSDate()
@@ -151,7 +143,9 @@ const startDateString = computed({
151143
152144
const endDateString = computed({
153145
get() {
154-
return DateTime.fromJSDate(dates.value[1]).toFormat(DATE_FMT)
146+
return DateTime.fromJSDate(dates.value[1])
147+
.setLocale(locale.value)
148+
.toFormat(DATE_FMT)
155149
},
156150
set(newValue: string) {
157151
dates.value[1] = DateTime.fromFormat(newValue, DATE_FMT).toJSDate()

src/locales/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"settings": {
33
"all": "All settings ..."
4+
},
5+
"time": {
6+
"browserTime": "Browser time:",
7+
"default": "Default",
8+
"custom": "Custom",
9+
"presets": "Period presets"
410
}
511
}

src/locales/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { en, nl } from 'vuetify/locale'
22
import enCustom from './en.json'
33
import nlCustom from './nl.json'
4+
import type { DateTimeFormat } from '@intlify/core-base'
45

56
export const messages = {
67
en: {
@@ -16,3 +17,37 @@ export const messages = {
1617
...nlCustom,
1718
},
1819
}
20+
21+
export const datetimeFormats: Record<keyof typeof messages, DateTimeFormat> = {
22+
en: {
23+
time: {
24+
hour: 'numeric',
25+
minute: 'numeric',
26+
timeZoneName: 'short',
27+
},
28+
datetimeslider: {
29+
year: 'numeric',
30+
month: 'numeric',
31+
day: 'numeric',
32+
hour: 'numeric',
33+
minute: 'numeric',
34+
second: 'numeric',
35+
hour12: true,
36+
},
37+
},
38+
nl: {
39+
time: {
40+
hour: 'numeric',
41+
minute: 'numeric',
42+
timeZoneName: 'short',
43+
},
44+
datetimeslider: {
45+
year: 'numeric',
46+
month: 'numeric',
47+
day: 'numeric',
48+
hour: 'numeric',
49+
minute: 'numeric',
50+
second: 'numeric',
51+
},
52+
},
53+
} as const

src/locales/nl.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"settings": {
33
"all": "Alle instellingen ..."
4+
},
5+
"time": {
6+
"browserTime": "Browser tijd:",
7+
"default": "Standaard",
8+
"custom": "Aangepast",
9+
"presets": "Voorinstellingen voor perioden"
410
}
511
}

src/plugins/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { createI18n } from 'vue-i18n'
2-
import { messages } from '../locales/index.js'
2+
import { messages, datetimeFormats } from '../locales/index.js'
33

44
export const i18n = createI18n<false>({
55
legacy: false,
66
locale: import.meta.env.VITE_I18N_LOCALE || 'en',
77
fallbackLocale: import.meta.env.VITE_I18N_FALLBACK_LOCALE || 'en',
88
messages,
9+
datetimeFormats,
910
globalInjection: true,
1011
})

0 commit comments

Comments
 (0)