profileShare

rasmusjy / splitapp-frontend-vue

Read-only snapshot

No repository description.

main default branch 96 files Expires Sep 13, 2026, 9:06 AM
index.ts 1,381 bytes
1 import { createI18n } from 'vue-i18n'
2 import en from '@/locales/en.json'
3 import et from '@/locales/et.json'
4
5 export type AppLocale = 'en' | 'et'
6
7 const numberFormats = {
8 en: {
9 currency: { style: 'currency', currency: 'EUR', notation: 'standard' },
10 decimal: { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 },
11 },
12 et: {
13 currency: { style: 'currency', currency: 'EUR', notation: 'standard' },
14 decimal: { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 },
15 },
16 } as const
17
18 const datetimeFormats = {
19 en: {
20 short: { year: 'numeric', month: 'short', day: 'numeric' },
21 long: { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' },
22 },
23 et: {
24 short: { year: 'numeric', month: 'short', day: 'numeric' },
25 long: { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' },
26 },
27 } as const
28
29 export const SUPPORTED_LOCALES: AppLocale[] = ['en', 'et']
30 export const DEFAULT_LOCALE: AppLocale = 'en'
31
32 function initialLocale(): AppLocale {
33 const saved = localStorage.getItem('locale')
34 if (saved === 'en' || saved === 'et') return saved
35 return DEFAULT_LOCALE
36 }
37
38 const i18n = createI18n({
39 legacy: false,
40 locale: initialLocale(),
41 fallbackLocale: DEFAULT_LOCALE,
42 messages: { en, et },
43 numberFormats,
44 datetimeFormats,
45 })
46
47 export default i18n
48