Skip to content

Commit

Permalink
#131 Defined "month" template and stored it in "const dateTimeFormats…
Browse files Browse the repository at this point in the history
…" to be used inside the options object in the new VueI18n instance - call i18n.setDateTimeFormat() after fetching current page locale
  • Loading branch information
BeneRichi committed Jan 20, 2023
1 parent dbe76e9 commit 1f3f7f1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/setup/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ if (process.env.NODE_ENV !== 'production') {
}
}

const dateTimeFormats = { // @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#parameter
month: { // January, February, March, ...
month: 'long',
},
};

export const i18n = new VueI18n({
locale: I18N_FALLBACK,
fallbackLocale: I18N_FALLBACK,
warnHtmlInMessage: process.env.NODE_ENV !== 'production' ? 'error' : 'off',
dateTimeFormats: {
[I18N_FALLBACK]: dateTimeFormats,
[pageLang]: dateTimeFormats,
},

/**
* Callback for the 'missing' event, during translation lookup.
Expand Down Expand Up @@ -89,6 +99,7 @@ export const i18nSetLocale = function(locale) { // eslint-disable-line no-param-
if (i18n.locale !== locale) {
return i18nLoadMessages(locale).then((newLocale) => {
i18n.locale = newLocale;
i18n.setDateTimeFormat(locale, dateTimeFormats);
});
}

Expand Down

0 comments on commit 1f3f7f1

Please sign in to comment.