Skip to content

Commit

Permalink
Localise dates #210
Browse files Browse the repository at this point in the history
  • Loading branch information
sbs20 committed Apr 22, 2021
1 parent 795d014 commit 08e1372
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion webui/src/components/Files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tbody>
<tr v-for="file in files" v-bind:key="file.name">
<td><a @click="open(file)">{{ file.name }}</a></td>
<td class="file-date">{{ file.lastModified }}</td>
<td class="file-date">{{ $d(new Date(file.lastModified), 'long', $i18n.locale) }}</td>
<td>{{ file.sizeString }}</td>
<td><v-btn color="secondary" v-on:click="fileRemove(file)" icon><v-icon>mdi-delete</v-icon></v-btn></td>
</tr>
Expand Down
22 changes: 22 additions & 0 deletions webui/src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import Constants from './classes/constants';

Vue.use(VueI18n);

const dateTimeFormats = {};
for (const locale of Constants.Locales) {
dateTimeFormats[locale] = {
short: {
year: 'numeric',
month: 'short',
day: 'numeric'
},
long: {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: false
}
};
}

function loadLocaleMessages () {
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i);
const messages = {};
Expand All @@ -17,6 +38,7 @@ function loadLocaleMessages () {
}

export default new VueI18n({
dateTimeFormats,
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages()
Expand Down

0 comments on commit 08e1372

Please sign in to comment.