Skip to content

fix(frontend): fixes dayjs locales #7639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions common/helpers/dayjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const dayjsLocaleMap = {
en: 'en-gb',
it: 'it-ch',
fr: 'fr-ch',
rm: 'de-ch',
}

/**
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
Expand Up @@ -26,7 +26,12 @@ 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)
const twoLetterLocale = lang.substring(0, 2)
dayjs.locale(
Object.keys(dayjsLocaleMap).includes(twoLetterLocale)
? dayjsLocaleMap[twoLetterLocale]
: lang
)

const result = { ...(await renderPdf(data)) }
if (result.error) {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/plugins/store/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export const mutations = {

state.language = lang
VueI18n.locale = lang
const twoLetterLocale = lang.substring(0, 2)
Vue.dayjs.locale(
Object.keys(dayjsLocaleMap).includes(lang) ? dayjsLocaleMap[lang] : lang
Object.keys(dayjsLocaleMap).includes(twoLetterLocale)
? dayjsLocaleMap[twoLetterLocale]
: lang
)
localeChanged()
axios.defaults.headers.common['Accept-Language'] = lang
Expand Down
11 changes: 10 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 { dayjsLocaleMap } from '@/common/helpers/dayjs.js'

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

//dayjs
const twoLetterLocale = locale.substring(0, 2)
$date.locale(
Object.keys(dayjsLocaleMap).includes(twoLetterLocale)
? dayjsLocaleMap[twoLetterLocale]
: locale
)

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