Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/helpers/dayjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const dayjsLocaleMap = {
en: 'en-gb',
it: 'it-ch',
fr: 'fr-ch',
rm: 'de-ch',
}

export function toDayjsLocale(locale) {
const twoLetterLocale = locale.substring(0, 2);
return Object.keys(dayjsLocaleMap).includes(twoLetterLocale)
? dayjsLocaleMap[twoLetterLocale]
: locale;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"global": {
"datetime": {
"dateLong": "dd L",
"dateShort": "dd M/D",
"dateShort": "dd D/M",
"dateTimeLong": "dd L LT",
"duration": {
"daysAndHours": "{days} d {hours} h",
Expand Down Expand Up @@ -295,4 +295,4 @@
"title": "Table of contents"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/browser'
import { renderPdf } from './renderPdf.js'
import dayjs, { dayjsLocaleMap } from '@/common/helpers/dayjs.js'
import dayjs, { toDayjsLocale } from '@/common/helpers/dayjs.js'

// Work around an incompatibility between comlink, vite and react-pdf...
// Comlink works with a globally defined function 'start'. And apparently the way we import
Expand All @@ -26,7 +26,7 @@ export const renderPdfInWorker = async (data) => {

// We need to set the locale again here. Otherwise dayjs falls back to the default
// on production deployments
dayjs.locale(Object.keys(dayjsLocaleMap).includes(lang) ? dayjsLocaleMap[lang] : lang)
dayjs.locale(toDayjsLocale(lang))

const result = { ...(await renderPdf(data)) }
if (result.error) {
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/plugins/store/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue from 'vue'
import axios from 'axios'
import VueI18n from '@/plugins/i18n'
import { localeChanged } from 'vee-validate'
import { dayjsLocaleMap } from '@/common/helpers/dayjs.js'
import { toDayjsLocale } from '@/common/helpers/dayjs.js'

const LANG_KEY = 'language'

Expand All @@ -23,9 +23,7 @@ export const mutations = {

state.language = lang
VueI18n.locale = lang
Vue.dayjs.locale(
Object.keys(dayjsLocaleMap).includes(lang) ? dayjsLocaleMap[lang] : lang
)
Vue.dayjs.locale(toDayjsLocale(lang))
localeChanged()
axios.defaults.headers.common['Accept-Language'] = lang
document.querySelector('html').setAttribute('lang', lang)
Expand Down
6 changes: 5 additions & 1 deletion print/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</template>

<script setup>
import { toDayjsLocale } from '@/common/helpers/dayjs.js'

// parse query config
const route = useRoute()
const query = route.query
Expand All @@ -26,7 +28,9 @@ const { setLocale, fallbackLocale } = useI18n()
const { $date } = useNuxtApp()
const locale = config.language || fallbackLocale.value
await setLocale(locale) // i18n
$date.locale(locale) //dayjs

//dayjs
$date.locale(toDayjsLocale(locale))

// load camp
const { $api } = useNuxtApp()
Expand Down