Przeglądaj źródła

Move util to existing file

arvid-e 4 miesięcy temu
rodzic
commit
19a329f9fa

+ 1 - 1
apps/app/src/client/components/RecentActivity/ActivityListItem.tsx

@@ -1,7 +1,7 @@
 import { formatDistanceToNow } from 'date-fns';
 import { formatDistanceToNow } from 'date-fns';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import { type Locale } from 'date-fns/locale';
 import { type Locale } from 'date-fns/locale';
-import { getLocale } from '~/client/util/date-local';
+import { getLocale } from '~/server/util/locale-utils';
 import type { ActivityHasUserId, SupportedActivityActionType } from '~/interfaces/activity';
 import type { ActivityHasUserId, SupportedActivityActionType } from '~/interfaces/activity';
 import { ActivityLogActions } from '~/interfaces/activity';
 import { ActivityLogActions } from '~/interfaces/activity';
 
 

+ 0 - 28
apps/app/src/client/util/date-local.ts

@@ -1,28 +0,0 @@
-import { type Locale } from 'date-fns/locale';
-import {
-  enUS, ja, fr, ko, zhCN,
-} from 'date-fns/locale';
-
-const DATE_FNS_LOCALE_MAP: Record<string, Locale | undefined> = {
-  'en': enUS, 'en-US': enUS, 'en_US': enUS,
-  'ja': ja, 'ja-JP': ja, 'ja_JP': ja,
-  'fr': fr, 'fr-FR': fr, 'fr_FR': fr,
-  'ko': ko, 'ko-KR': ko, 'ko_KR': ko,
-  'zh': zhCN, 'zh-CN': zhCN, 'zh_CN': zhCN,
-};
-
-/**
- * Gets the corresponding date-fns Locale object from an i18next language code.
- * @param langCode The i18n language code (e.g., 'ja_JP').
- * @returns The date-fns Locale object, defaulting to enUS if not found.
- */
-export const getLocale = (langCode: string): Locale => {
-  let locale = DATE_FNS_LOCALE_MAP[langCode];
-
-  if (!locale) {
-    const baseCode = langCode.split(/[-_]/)[0];
-    locale = DATE_FNS_LOCALE_MAP[baseCode];
-  }
-
-  return locale ?? enUS;
-};

+ 29 - 1
apps/app/src/server/util/locale-utils.ts

@@ -1,6 +1,9 @@
 import { Lang } from '@growi/core/dist/interfaces';
 import { Lang } from '@growi/core/dist/interfaces';
 import type { IncomingHttpHeaders } from 'http';
 import type { IncomingHttpHeaders } from 'http';
-
+import { type Locale } from 'date-fns/locale';
+import {
+  enUS, ja, fr, ko, zhCN,
+} from 'date-fns/locale';
 import * as i18nextConfig from '^/config/i18next.config';
 import * as i18nextConfig from '^/config/i18next.config';
 
 
 const ACCEPT_LANG_MAP = {
 const ACCEPT_LANG_MAP = {
@@ -11,6 +14,31 @@ const ACCEPT_LANG_MAP = {
   ko: Lang.ko_KR,
   ko: Lang.ko_KR,
 };
 };
 
 
+const DATE_FNS_LOCALE_MAP: Record<string, Locale | undefined> = {
+  'en': enUS, 'en-US': enUS, 'en_US': enUS,
+  'ja': ja, 'ja-JP': ja, 'ja_JP': ja,
+  'fr': fr, 'fr-FR': fr, 'fr_FR': fr,
+  'ko': ko, 'ko-KR': ko, 'ko_KR': ko,
+  'zh': zhCN, 'zh-CN': zhCN, 'zh_CN': zhCN,
+};
+
+/**
+ * Gets the corresponding date-fns Locale object from an i18next language code.
+ * @param langCode The i18n language code (e.g., 'ja_JP').
+ * @returns The date-fns Locale object, defaulting to enUS if not found.
+ */
+export const getLocale = (langCode: string): Locale => {
+  let locale = DATE_FNS_LOCALE_MAP[langCode];
+
+  if (!locale) {
+    const baseCode = langCode.split(/[-_]/)[0];
+    locale = DATE_FNS_LOCALE_MAP[baseCode];
+  }
+
+  return locale ?? enUS;
+};
+
+
 /**
 /**
  * It return the first language that matches ACCEPT_LANG_MAP keys from sorted accept languages array
  * It return the first language that matches ACCEPT_LANG_MAP keys from sorted accept languages array
  * @param sortedAcceptLanguagesArray
  * @param sortedAcceptLanguagesArray