@team-monolith/cds 1.117.7 → 1.117.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { COLOR } from "./foundation/color";
5
5
  import { FONT } from "./foundation/font";
6
6
  import { createTheme } from "@mui/material";
7
7
  import { createContext, useMemo } from "react";
8
- import { getI18nInstance } from "./i18n/i18n";
8
+ import { createAndInitI18nInstance } from "./i18n/i18n";
9
9
  import { I18nextProvider } from "react-i18next";
10
10
  export const light = {
11
11
  fontFamily: {
@@ -311,7 +311,7 @@ export const dark = {
311
311
  };
312
312
  export const CdsContext = createContext({});
313
313
  export function CdsProvider(props) {
314
- const i18nInstance = useMemo(() => getI18nInstance(props.i18nextConfig), []);
314
+ const i18nInstance = useMemo(() => createAndInitI18nInstance(props.i18nextConfig), []);
315
315
  const muiTheme = createTheme({
316
316
  typography: {
317
317
  fontFamily: props.fontFamily,
@@ -1,7 +1,8 @@
1
+ import { i18n } from "i18next";
1
2
  export type i18nextConfig = {
2
3
  environment: string;
3
4
  mainLanguage: string;
4
5
  projectId: string;
5
6
  apiKey?: string;
6
7
  };
7
- export declare function getI18nInstance(config: i18nextConfig | undefined): import("i18next").i18n;
8
+ export declare function createAndInitI18nInstance(config: i18nextConfig | undefined): i18n;
package/dist/i18n/i18n.js CHANGED
@@ -3,19 +3,26 @@ import LanguageDetector from "i18next-browser-languagedetector";
3
3
  import Backend from "i18next-locize-backend";
4
4
  import { COOKIE_NAME, I18N_COMMON_CONFIGS, QUERYSTRING_NAME, } from "./i18nConfigs";
5
5
  import { initReactI18next } from "react-i18next";
6
- export function getI18nInstance(config) {
7
- const languageDetector = new LanguageDetector(null, {
8
- lookupCookie: COOKIE_NAME,
9
- lookupQuerystring: QUERYSTRING_NAME,
10
- caches: [], // 사용자의 language 설정을 저장하지 않습니다.
11
- });
12
- const DETECTED_LANGUAGE = languageDetector.detect();
13
- const CONTAINS_KOREAN = typeof DETECTED_LANGUAGE === "string"
14
- ? DETECTED_LANGUAGE.startsWith("ko")
15
- : Array.isArray(DETECTED_LANGUAGE)
16
- ? DETECTED_LANGUAGE.some((lang) => lang.startsWith("ko"))
17
- : false;
18
- const i18nextInstance = i18next
6
+ const languageDetector = new LanguageDetector(null, {
7
+ lookupCookie: COOKIE_NAME,
8
+ lookupQuerystring: QUERYSTRING_NAME,
9
+ caches: [], // 사용자의 language 설정을 저장하지 않습니다.
10
+ });
11
+ const DETECTED_LANGUAGE = languageDetector.detect();
12
+ const CONTAINS_KOREAN = typeof DETECTED_LANGUAGE === "string"
13
+ ? DETECTED_LANGUAGE.startsWith("ko")
14
+ : Array.isArray(DETECTED_LANGUAGE)
15
+ ? DETECTED_LANGUAGE.some((lang) => lang.startsWith("ko"))
16
+ : false;
17
+ // AIDEV-NOTE: CDS 안에서 i18n 인스턴스를 1개만 유지하기 위해
18
+ // 전역 변수로 관리합니다.
19
+ let i18nInstance = null;
20
+ console.log(`[i18n] module loaded. Detected language:`, DETECTED_LANGUAGE);
21
+ export function createAndInitI18nInstance(config) {
22
+ if (i18nInstance) {
23
+ return i18nInstance;
24
+ }
25
+ i18nInstance = i18next
19
26
  .createInstance()
20
27
  .use(languageDetector)
21
28
  .use(initReactI18next);
@@ -23,8 +30,8 @@ export function getI18nInstance(config) {
23
30
  // config가 없는 경우, backend 플러그인 없이 기본 i18next 설정을 사용하여,
24
31
  // fallbackValue(=key)를 항상 사용하게 됩니다.
25
32
  console.log("[i18n] i18n config is not provided. Using default i18n instance.");
26
- i18nextInstance.init(Object.assign(Object.assign({}, I18N_COMMON_CONFIGS), { fallbackLng: false }));
27
- return i18nextInstance;
33
+ i18nInstance.init(Object.assign(Object.assign({}, I18N_COMMON_CONFIGS), { fallbackLng: false }));
34
+ return i18nInstance;
28
35
  }
29
36
  /**
30
37
  * AIDEV-NOTE:
@@ -34,9 +41,7 @@ export function getI18nInstance(config) {
34
41
  */
35
42
  const LOCIZE_ENABLED = config.environment !== "production" || !CONTAINS_KOREAN;
36
43
  console.log(`[i18n] Initializing i18n instance with config`);
37
- (LOCIZE_ENABLED && config.projectId
38
- ? i18nextInstance.use(Backend)
39
- : i18nextInstance).init(Object.assign(Object.assign({}, I18N_COMMON_CONFIGS), { debug: config.environment !== "production",
44
+ (LOCIZE_ENABLED ? i18nInstance.use(Backend) : i18nInstance).init(Object.assign(Object.assign({}, I18N_COMMON_CONFIGS), { debug: config.environment !== "production",
40
45
  // AIDEV-NOTE:
41
46
  // - 유저의 언어가 Korean인 경우:
42
47
  // fallbackLng를 false로 설정하여, 번역이 없는 경우 key 자체를 반환하도록 합니다.
@@ -50,5 +55,5 @@ export function getI18nInstance(config) {
50
55
  apiKey: config.apiKey,
51
56
  referenceLng: "ko",
52
57
  } }));
53
- return i18nextInstance;
58
+ return i18nInstance;
54
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.117.7",
3
+ "version": "1.117.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,