Skip to content

Commit 5a1489c

Browse files
marcel-bitflyenzo-bitfly
authored andcommitted
refactor: make usage of locale typesafe
1 parent bc56807 commit 5a1489c

File tree

12 files changed

+34
-36
lines changed

12 files changed

+34
-36
lines changed

frontend/components/bc/BcMaintenanceBanner.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const maintenanceLabel = computed(() => {
2222
}
2323
const ts = new Date(parsed * 1000).getTime()
2424
if (ts > tick.value) {
25-
return $t('maintenance.planned', { date: formatTsToAbsolute(ts / 1000, $t('locales.date'), true) })
25+
return $t('maintenance.planned', { date: formatTsToAbsolute(ts / 1000, 'en-US', true) })
2626
}
2727
else {
2828
return $t('maintenance.ongoing')

frontend/components/bc/format/BcFormatPercent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const data = computed(() => {
6161
}
6262
}
6363
const localPercent = percent ?? calculatePercent(value, base)
64-
label = new Intl.NumberFormat('en', {
64+
label = new Intl.NumberFormat('en-Us', {
6565
maximumFractionDigits,
6666
// due to the default value of minimumFractionDigits: 2
6767
// there will be an error when `minimumFractionDigits > maximumFractionDitigs`

frontend/components/bc/format/FormatTimePassed.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ interface Props {
1717
value?: number | string,
1818
}
1919
const props = defineProps<Props>()
20-
const { t: $t } = useTranslation()
2120
const { timestamp } = useDate()
2221
const { ageFormat } = storeToRefs(useSettingsStore())
2322
@@ -44,7 +43,7 @@ const label = computed(() => {
4443
ts,
4544
mappedSetting.value,
4645
props.unitLength,
47-
$t('locales.date'),
46+
'en-US',
4847
)
4948
break
5049
case 'slot':
@@ -53,7 +52,7 @@ const label = computed(() => {
5352
ts,
5453
mappedSetting.value,
5554
props.unitLength,
56-
$t('locales.date'),
55+
'en-US',
5756
)
5857
break
5958
case 'epoch':
@@ -63,7 +62,7 @@ const label = computed(() => {
6362
ts,
6463
mappedSetting.value,
6564
props.unitLength,
66-
$t('locales.date'),
65+
'en-US',
6766
)
6867
}
6968

frontend/components/dashboard/chart/DashboardChartRewards.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const option = computed<EChartsOption>(() => {
320320
},
321321
end: dataZoomEnd.value,
322322
labelFormatter: (_value: number, valueStr: string) => {
323-
return formatEpochToDate(parseInt(valueStr), $t('locales.date'))
323+
return formatEpochToDate(parseInt(valueStr), 'en-US')
324324
},
325325
start: dataZoomStart.value,
326326
type: 'slider',
@@ -420,7 +420,7 @@ const option = computed<EChartsOption>(() => {
420420
fontSize: textSize,
421421
fontWeight: fontWeightMedium,
422422
formatter: (value: number) => {
423-
const date = formatEpochToDate(value, $t('locales.date'))
423+
const date = formatEpochToDate(value, 'en-US')
424424
if (date === undefined) {
425425
return ''
426426
}

frontend/components/dashboard/chart/DashboardChartSummary.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ const formatTSToDate = (value: string) => {
264264
undefined,
265265
'absolute',
266266
'narrow',
267-
$t('locales.date'),
267+
'en-US',
268268
false,
269269
)
270270
}
@@ -284,7 +284,7 @@ const formatTimestamp = (value: string) => {
284284
case 'epoch':
285285
return `${date}\n${formatTSToEpoch(value)}`
286286
case 'hourly':
287-
return `${date}\n${formatTsToTime(Number(value), $t('locales.date'))}`
287+
return `${date}\n${formatTsToTime(Number(value), 'en-US')}`
288288
default:
289289
return date
290290
}

frontend/components/dashboard/chart/DashboardChartTooltipHeader.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const dateText = computed(() => {
5656
undefined,
5757
'absolute',
5858
'narrow',
59-
props.t('locales.date'),
59+
'en-US',
6060
true,
6161
)
6262
if (!endTs.value) {
@@ -67,7 +67,7 @@ const dateText = computed(() => {
6767
undefined,
6868
'absolute',
6969
'narrow',
70-
props.t('locales.date'),
70+
'en-US',
7171
true,
7272
)
7373

frontend/components/dashboard/validator/subset/DashboardValidatorSubsetList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function createDutyLabels(dutyObjects?: number[]) {
6969
undefined,
7070
'relative',
7171
'short',
72-
$t('locales.date'),
72+
'en-US',
7373
true,
7474
)
7575
case 'got_slashed':

frontend/components/notifications/management/NotificationsManagementGeneralTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const textMutedUntil = computed(() => {
112112
return $t('notifications.general.mute.until', {
113113
date: formatTsToAbsolute(
114114
store.settings.general_settings.do_not_disturb_timestamp,
115-
$t('locales.date'),
115+
'en-US',
116116
true,
117117
),
118118
})

frontend/composables/useFormat.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { StringUnitLength } from 'luxon'
2+
import type { Locale } from '~/i18n/i18n.config'
23
import type { AgeFormat } from '~/types/settings'
34

45
export function useFormat() {
@@ -12,7 +13,7 @@ export function useFormat() {
1213
timestamp?: number,
1314
format?: AgeFormat,
1415
style?: StringUnitLength,
15-
locales?: string,
16+
locales?: Locale,
1617
withTime?: boolean,
1718
): null | string | undefined {
1819
return formatTs(
@@ -30,7 +31,7 @@ export function useFormat() {
3031
timestamp?: number,
3132
format?: AgeFormat,
3233
style?: StringUnitLength,
33-
locales?: string,
34+
locales?: Locale,
3435
withTime?: boolean,
3536
): null | string | undefined {
3637
return formatTs(
@@ -45,7 +46,7 @@ export function useFormat() {
4546

4647
function formatEpochToDate(
4748
epoch: number,
48-
locales: string,
49+
locales: Locale,
4950
): null | string | undefined {
5051
return formatEpochToDateTime(
5152
epoch,

frontend/i18n/i18n.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import en from '~/i18n/locales/en.json'
22

33
export type MessageSchema = typeof en
4+
const messages = { 'en-US': en }
5+
export type Locale = keyof typeof messages
46

57
export default defineI18nConfig(() => ({
68
legacy: false,
7-
locale: 'en',
8-
messages: { en },
9+
locale: 'en-US',
10+
messages,
911
}))

0 commit comments

Comments
 (0)