diff --git a/resources/js/app.js b/resources/js/app.js index 14cc84bdb6..e6a6b6b000 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -238,11 +238,6 @@ Statamic.app({ this.$echo.start(); } - // Set moment locale - window.moment.locale(Statamic.$config.get('locale')); - Vue.moment.locale(Statamic.$config.get('locale')); - Vue.prototype.$moment.locale(Statamic.$config.get('locale')); - this.fixAutofocus(); this.showBanner = Statamic.$config.get('hasLicenseBanner'); @@ -271,6 +266,8 @@ Statamic.app({ .forEach(img => img.src = url); }); }); + + this.setupMoment(); }, methods: { @@ -306,6 +303,35 @@ Statamic.app({ inputs[0].focus(); } }, 100); + }, + + setupMoment() { + const locale = Statamic.$config.get('locale'); + window.moment.locale(locale); + Vue.moment.locale(locale); + Vue.prototype.$moment.locale(locale); + + const spec = { + relativeTime: { + future: __('moment.relativeTime.future'), + past: __('moment.relativeTime.past'), + s: __('moment.relativeTime.s'), + ss: __('moment.relativeTime.ss'), + m: __('moment.relativeTime.m'), + mm: __('moment.relativeTime.mm'), + h: __('moment.relativeTime.h'), + hh: __('moment.relativeTime.hh'), + d: __('moment.relativeTime.d'), + dd: __('moment.relativeTime.dd'), + M: __('moment.relativeTime.M'), + MM: __('moment.relativeTime.MM'), + y: __('moment.relativeTime.y'), + yy: __('moment.relativeTime.yy'), + } + }; + window.moment.updateLocale(locale, spec); + Vue.moment.updateLocale(locale, spec); + Vue.prototype.$moment.updateLocale(locale, spec); } } diff --git a/resources/lang/en/moment.php b/resources/lang/en/moment.php new file mode 100644 index 0000000000..dda1c36861 --- /dev/null +++ b/resources/lang/en/moment.php @@ -0,0 +1,18 @@ + 'in %s', + 'relativeTime.past' => '%s ago', + 'relativeTime.s' => 'a few seconds', + 'relativeTime.ss' => '%d seconds', + 'relativeTime.m' => 'a minute', + 'relativeTime.mm' => '%d minutes', + 'relativeTime.h' => 'an hour', + 'relativeTime.hh' => '%d hours', + 'relativeTime.d' => 'a day', + 'relativeTime.dd' => '%d days', + 'relativeTime.M' => 'a month', + 'relativeTime.MM' => '%d months', + 'relativeTime.y' => 'a year', + 'relativeTime.yy' => '%d years', +];