Refactor datetimeFormats to dedicated locale files

This commit is contained in:
Florian Dupret 2021-02-23 13:39:47 +01:00
commit 13507afebf
17 changed files with 83 additions and 22 deletions

View file

@ -3,12 +3,8 @@ import VueI18n from "vue-i18n";
Vue.use(VueI18n);
function loadLocaleMessages() {
const locales = require.context(
"./locales",
true,
/[A-Za-z0-9-_,\s]+\.json$/i
);
function parseLocaleFiles(locales) {
const messages = {};
locales.keys().forEach(key => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i);
@ -20,21 +16,22 @@ function loadLocaleMessages() {
return messages;
}
const dateTimeFormats = {
'en': {
short: {
month: 'short',
day: 'numeric',
weekday: 'long'
},
},
'fr': {
short: {
month: 'short',
day: 'numeric',
weekday: 'long'
}
}
function loadLocaleMessages() {
const locales = require.context(
"./locales/messages",
true,
/[A-Za-z0-9-_,\s]+\.json$/i
);
return parseLocaleFiles(locales);
}
function loadDateTimeFormats() {
const locales = require.context(
"./locales/dateTimeFormats",
true,
/[A-Za-z0-9-_,\s]+\.json$/i
);
return parseLocaleFiles(locales);
}
@ -42,5 +39,5 @@ export default new VueI18n({
locale: "en",
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || "en",
messages: loadLocaleMessages(),
dateTimeFormats
dateTimeFormats: loadDateTimeFormats()
});

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -0,0 +1,7 @@
{
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
}

View file

@ -1,4 +1,12 @@
{
"dateTimeFormats": {
"short": {
"month": "short",
"day": "numeric",
"weekday": "long"
}
},
"404": {
"page-not-found": "404 Page Not Found",
"take-me-home": "Take me Home"