From ba247f3bf1de8e1b0f93558c94df0c4778d3d82e Mon Sep 17 00:00:00 2001 From: Peiman Nourani Date: Thu, 9 May 2024 19:46:01 +0100 Subject: [PATCH 1/5] translate moment relative date statements --- resources/js/app.js | 21 +++++++++++++++++++++ resources/lang/en/moment.php | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 resources/lang/en/moment.php diff --git a/resources/js/app.js b/resources/js/app.js index 14cc84bdb6..009a477c49 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -242,6 +242,27 @@ Statamic.app({ window.moment.locale(Statamic.$config.get('locale')); Vue.moment.locale(Statamic.$config.get('locale')); Vue.prototype.$moment.locale(Statamic.$config.get('locale')); + const momentLocalSpec = { + relativeTime: { + future: __('moment.future'), + past: __('moment.past'), + s: __('moment.s'), + ss: __('moment.ss'), + m: __('moment.m'), + mm: __('moment.mm'), + h: __('moment.h'), + hh: __('moment.hh'), + d: __('moment.d'), + dd: __('moment.dd'), + M: __('moment.M'), + MM: __('moment.MM'), + y: __('moment.y'), + yy: __('moment.yy'), + } + }; + window.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); + Vue.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); + Vue.prototype.$moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); this.fixAutofocus(); diff --git a/resources/lang/en/moment.php b/resources/lang/en/moment.php new file mode 100644 index 0000000000..99d0d0e8d0 --- /dev/null +++ b/resources/lang/en/moment.php @@ -0,0 +1,18 @@ + "in %s", + "past" => "%s ago", + "s" => 'a few seconds', + "ss" => '%d seconds', + "m" => "a minute", + "mm" => "%d minutes", + "h" => "an hour", + "hh" => "%d hours", + "d" => "a day", + "dd" => "%d days", + "M" => "a month", + "MM" => "%d months", + "y" => "a year", + "yy" => "%d years" +]; From c28dc31b3161f33b60adae4ac0871239c6842272 Mon Sep 17 00:00:00 2001 From: Peiman Nourani Date: Thu, 9 May 2024 19:56:10 +0100 Subject: [PATCH 2/5] fix php linter error --- resources/lang/en/moment.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/lang/en/moment.php b/resources/lang/en/moment.php index 99d0d0e8d0..7c32c5703d 100644 --- a/resources/lang/en/moment.php +++ b/resources/lang/en/moment.php @@ -1,18 +1,18 @@ "in %s", - "past" => "%s ago", - "s" => 'a few seconds', - "ss" => '%d seconds', - "m" => "a minute", - "mm" => "%d minutes", - "h" => "an hour", - "hh" => "%d hours", - "d" => "a day", - "dd" => "%d days", - "M" => "a month", - "MM" => "%d months", - "y" => "a year", - "yy" => "%d years" + 'future' => 'in %s', + 'past' => '%s ago', + 's' => 'a few seconds', + 'ss' => '%d seconds', + 'm' => 'a minute', + 'mm' => '%d minutes', + 'h' => 'an hour', + 'hh' => '%d hours', + 'd' => 'a day', + 'dd' => '%d days', + 'M' => 'a month', + 'MM' => '%d months', + 'y' => 'a year', + 'yy' => '%d years', ]; From f079bacf05d1657fda3c791e6b10089d34732378 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 May 2024 12:55:14 -0400 Subject: [PATCH 3/5] setup moment during create so its setup correctly before other components are mounted --- resources/js/app.js | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 009a477c49..7410407fe4 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -238,32 +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')); - const momentLocalSpec = { - relativeTime: { - future: __('moment.future'), - past: __('moment.past'), - s: __('moment.s'), - ss: __('moment.ss'), - m: __('moment.m'), - mm: __('moment.mm'), - h: __('moment.h'), - hh: __('moment.hh'), - d: __('moment.d'), - dd: __('moment.dd'), - M: __('moment.M'), - MM: __('moment.MM'), - y: __('moment.y'), - yy: __('moment.yy'), - } - }; - window.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); - Vue.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); - Vue.prototype.$moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); - this.fixAutofocus(); this.showBanner = Statamic.$config.get('hasLicenseBanner'); @@ -292,6 +266,32 @@ Statamic.app({ .forEach(img => img.src = url); }); }); + + // 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')); + const momentLocalSpec = { + relativeTime: { + future: __('moment.future'), + past: __('moment.past'), + s: __('moment.s'), + ss: __('moment.ss'), + m: __('moment.m'), + mm: __('moment.mm'), + h: __('moment.h'), + hh: __('moment.hh'), + d: __('moment.d'), + dd: __('moment.dd'), + M: __('moment.M'), + MM: __('moment.MM'), + y: __('moment.y'), + yy: __('moment.yy'), + } + }; + window.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); + Vue.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); + Vue.prototype.$moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); }, methods: { From 23aea5e0016c030d24c5c867845a4b5c2ea6beb6 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 May 2024 12:59:28 -0400 Subject: [PATCH 4/5] prefix to match moment translation --- resources/js/app.js | 28 ++++++++++++++-------------- resources/lang/en/moment.php | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 7410407fe4..26abcd55f7 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -273,20 +273,20 @@ Statamic.app({ Vue.prototype.$moment.locale(Statamic.$config.get('locale')); const momentLocalSpec = { relativeTime: { - future: __('moment.future'), - past: __('moment.past'), - s: __('moment.s'), - ss: __('moment.ss'), - m: __('moment.m'), - mm: __('moment.mm'), - h: __('moment.h'), - hh: __('moment.hh'), - d: __('moment.d'), - dd: __('moment.dd'), - M: __('moment.M'), - MM: __('moment.MM'), - y: __('moment.y'), - yy: __('moment.yy'), + 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(Statamic.$config.get('locale'), momentLocalSpec); diff --git a/resources/lang/en/moment.php b/resources/lang/en/moment.php index 7c32c5703d..dda1c36861 100644 --- a/resources/lang/en/moment.php +++ b/resources/lang/en/moment.php @@ -1,18 +1,18 @@ 'in %s', - 'past' => '%s ago', - 's' => 'a few seconds', - 'ss' => '%d seconds', - 'm' => 'a minute', - 'mm' => '%d minutes', - 'h' => 'an hour', - 'hh' => '%d hours', - 'd' => 'a day', - 'dd' => '%d days', - 'M' => 'a month', - 'MM' => '%d months', - 'y' => 'a year', - 'yy' => '%d years', + 'relativeTime.future' => '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', ]; From e5e45c75a5abdbdc2952b60cab1fda9888216997 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 May 2024 13:02:53 -0400 Subject: [PATCH 5/5] tidy --- resources/js/app.js | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 26abcd55f7..e6a6b6b000 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -267,31 +267,7 @@ Statamic.app({ }); }); - // 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')); - const momentLocalSpec = { - 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(Statamic.$config.get('locale'), momentLocalSpec); - Vue.moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); - Vue.prototype.$moment.updateLocale(Statamic.$config.get('locale'), momentLocalSpec); + this.setupMoment(); }, methods: { @@ -327,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); } }