From 4afdb6bb44e5e360ba44ee97e6ffcb99dec9bb49 Mon Sep 17 00:00:00 2001
From: Dalton <daltojohnso@users.noreply.github.com>
Date: Tue, 16 Nov 2021 09:54:22 -0800
Subject: [PATCH] Fix issue with moment locale not working (#18943)

* add fn that maps from our locale string to moment's

* use moment with locales

* add a require for the specific locale

* don't require en

* ensure locale is lowercased for moment more generally

* default locale to a string
---
 frontend/src/metabase/lib/i18n.js | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/frontend/src/metabase/lib/i18n.js b/frontend/src/metabase/lib/i18n.js
index e6ce82c3a1e..095b4ab1202 100644
--- a/frontend/src/metabase/lib/i18n.js
+++ b/frontend/src/metabase/lib/i18n.js
@@ -74,10 +74,28 @@ export function setLocalization(translationsObject) {
   // eslint-disable-next-line react-hooks/rules-of-hooks
   useLocale(locale);
 
-  moment.locale(locale);
+  updateMomentLocale(locale);
   updateMomentStartOfWeek(locale);
 }
 
+function updateMomentLocale(locale) {
+  const momentLocale = mapToMomentLocale(locale);
+  if (momentLocale !== "en") {
+    require("moment/locale/" + momentLocale);
+  }
+
+  moment.locale(momentLocale);
+}
+
+function mapToMomentLocale(locale = "") {
+  switch (locale) {
+    case "zh-Hans":
+      return "zh-cn";
+    default:
+      return locale.toLowerCase();
+  }
+}
+
 // Format a fixed timestamp in local time to see if the current locale defaults
 // to using a 24 hour clock.
 export function isLocale24Hour() {
-- 
GitLab