Skip to content

Commit

Permalink
Rename LocalizationKey to Locale
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvonen committed May 28, 2024
1 parent b9b540e commit f7152c5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {LocalizationKey} from '@/types';
import type {Locale} from '@/types';

export const ACTIVITIES = [
'badminton',
Expand All @@ -22,12 +22,12 @@ export const ACTIVITIES = [
'walking',
];

export const DATE_FORMATS: {[key in LocalizationKey]: string} = {
export const DATE_FORMATS: {[key in Locale]: string} = {
en: 'MM/dd/y',
fi: 'd.M.y',
};

export const SHORT_DATE_FORMATS: {[key in LocalizationKey]: string} = {
export const SHORT_DATE_FORMATS: {[key in Locale]: string} = {
en: 'MM/dd',
fi: 'd.M',
};
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/weekdays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useScheduleStore} from '@/stores/schedule';
import {useI18n} from 'vue-i18n';
import {DateTime} from 'luxon';
import {DATE_FORMATS, SHORT_DATE_FORMATS, WEEKDAYS} from '@/constants';
import type {Locale} from '@/types';

export default function useWeekDays() {
const scheduleStore = useScheduleStore();
Expand All @@ -30,12 +31,14 @@ export default function useWeekDays() {
});

const getDateInterval = computed(() => (weekIndex: number) => {
const formattedStart = getWeekStart.value(weekIndex).toFormat(DATE_FORMATS[locale.value]);
const formattedStart = getWeekStart
.value(weekIndex)
.toFormat(DATE_FORMATS[locale.value as Locale]);
const formattedEnd = getWeekStart
.value(weekIndex)
.plus({days: 6})
.endOf('day')
.toFormat(DATE_FORMATS[locale.value]);
.toFormat(DATE_FORMATS[locale.value as Locale]);
return `${formattedStart} - ${formattedEnd}`;
});

Expand All @@ -51,7 +54,7 @@ export default function useWeekDays() {
getWeekStart
.value(weekIndex)
.plus({days: dayIndex})
.toFormat(SHORT_DATE_FORMATS[locale.value]),
.toFormat(SHORT_DATE_FORMATS[locale.value as Locale]),
);

return {weekdays, shortWeekdays, getDateInterval, getDisplayWeekNumber, getShortDate};
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {createI18n} from 'vue-i18n';
import type {LocalizationKey} from '@/types';
import type {Locale} from '@/types';
import en from './en.json';
import fi from './fi.json';

type MessageSchema = typeof en;

export default createI18n<[MessageSchema], LocalizationKey>({
export default createI18n<[MessageSchema], Locale>({
locale: 'en',
fallbackLocale: 'en',
legacy: false,
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type LocalizationKey = 'en' | 'fi';
export type Locale = 'en' | 'fi';

export type Rating = 1 | 2 | 3 | 4 | 5 | null;

Expand Down
3 changes: 2 additions & 1 deletion src/views/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {useScheduleStore} from '@/stores/schedule';
import useLocalizedActivities from '@/hooks/localizedActivities';
import useValidatedRef from '@/hooks/validatedRef';
import {DATE_FORMATS} from '@/constants';
import type {Locale} from '@/types';
import {decimalRegex, getIcon} from '@/utils';
import BaseView from '@/components/BaseView.vue';
Expand Down Expand Up @@ -86,7 +87,7 @@ const [duration, durationErrors] = useValidatedRef(settings, 'defaultDuration',
:min-date="DateTime.now().minus({years: 1}).toJSDate()"
:locale="$i18n.locale"
:clearable="false"
:format="DATE_FORMATS[$i18n.locale]"
:format="DATE_FORMATS[$i18n.locale as Locale]"
:teleport="true"
>
<template #dp-input="{value, onClear, openMenu}">
Expand Down

0 comments on commit f7152c5

Please sign in to comment.