PageSourceSearch

https://ssonda.ai/assets/js/core/localization-manager.js;jsessioni…D56BE6DAB1154E1FCC0E706408B?v=1790258051472

js ssonda.ai collected 2026-09-24 13:55:22 UTC 5,933 bytes, 172 lines download raw bytes

1function LocalizationManager(config) {
2    // 기본 언어 설정
3    this.language = config?.language ?? 'ko-KR';
4    this.fallbackLanguage = config?.fallbackLanguage ?? 'ko-KR';
5    this.supportedLanguages = config?.supportedLanguages ?? ['ko-KR', 'en-US'];
6    this.basePath = config?.basePath ?? '/assets/locales';
7    this.namespaces = config?.namespaces ?? ['common'];
8    this.isInitialized = false;
9
10    // i18next 초기화 함수
11    this.init = function () {
12        i18next
13        .use(i18nextChainedBackend)
14        // .use(i18nextLocalStorageBackend)
15        // .use(i18nextHttpBackend) // 번역 파일 로드용 플러그인
16        .init(
17            {
18                lng: this.language,
19                fallbackLng: this.fallbackLanguage,
20                supportedLngs: this.supportedLanguages,
21                debug: false,
22                ns: this.namespaces,
23                defaultNS: 'common',
24                backend: {
25                    backends: [i18nextLocalStorageBackend, i18nextHttpBackend],
26                    backendOptions: [
27                        {
28                            defaultVersion: '1.3.193',
29                            // defaultVersion: new Date().toISOString(), // 개발용: 매 로드마다 localStorage 캐시 무효화 → 새 번역 키 즉시 반영
30                        },
31                        {
32                            loadPath: `${this.basePath}/{{lng}}/{{ns}}.json?v=${new Date().getTime()}`,
33                        },
34                    ],
35                },
36                interpolation: {
37                    escapeValue: false,
38                },
39            },
40            (err, t) => {
41                if (err) {
42                    console.error('i18next 초기화 중 오류:', err);
43                } else {
44                    // console.log('i18next 초기화 성공');
45                }
46            }
47        )
48        .then(() => {
49            this.isInitialized = true;
50            document.dispatchEvent(new Event('i18nInitialized'));
51        });
52    };
53
54    // 조사 처리하여 단어에 붙이는 함수
55    // 사용 예시: i18n.withJosa('사람', '이')
56    this.withJosa = function (key, josaType) {
57        let word = this.translate(key); // i18next.t(key)와 동일한 기능
58
59        if (!i18next.exists(key)) {
60            word = key; // 키가 존재하지 않을 경우 원본 단어 사용
61        }
62
63        if (this.language !== 'ko-KR') {
64            return word; // 한국어가 아닐 경우 원본 단어 반환
65        }
66
67        if (!word || !josaType) {
68            console.warn("[WARN] item 또는 type 값 누락");
69            return '';
70        }
71
72        
73        let lastChar; // 마지막 글자를 가지고 있기 위한 변수
74        let verifyWord = word.replace(/[^가-힣]/g, ''); // 한글만 추출해서 검증
75        if (verifyWord.length > 1) {
76            lastChar = verifyWord.charAt(verifyWord.length - 1);
77        } else {
78            lastChar = verifyWord;
79        }
80
81        const code = lastChar.charCodeAt(0) - 0xAC00;
82        const hasFinalConsonant = code % 28 !== 0;
83
84        let particle = "";
85        if (josaType === "은는" || josaType === "은" || josaType === "는") {
86            particle = hasFinalConsonant ? "은" : "는";
87        } else if (josaType === "이가" || josaType === "이" || josaType === "가") {
88            particle = hasFinalConsonant ? "이" : "가";
89        } else if (josaType === "을를" || josaType === "을" || josaType === "를") {
90            particle = hasFinalConsonant ? "을" : "를";
91        } else if (josaType === "로으로" || josaType === "로" || josaType === "으로") {
92            particle = hasFinalConsonant ? "으로" : "로";
93        }
94
95        return word + particle;
96    }
97
98    this.addNamespace = function (namespace) {
99        if (!this.namespaces.includes(namespace)) {
100            this.namespaces.push(namespace);
101            i18next.loadNamespaces(this.namespaces, (err) => {
102                if (err) {
103                    console.error('namespace 추가 중 오류:', err);
104                } else {
105                    console.log(`namespace 추가 완료: ${namespace}`);
106                }
107            });
108        }
109    }
110
111    // 언어 변경 함수
112    this.changeLanguage = function (language) {
113        if (!this.supportedLanguages.includes(language)) {
114            console.warn(`지원되지 않는 언어: ${language}`);
115            return;
116        }
117
118        i18next.changeLanguage(language, (err) => {
119            if (err) {
120                console.error('언어 변경 중 오류:', err);
121            } else {
122                // console.log(`언어가 변경되었습니다: ${language}`);
123            }
124        });
125    };
126
127    this.exists = function (key) {
128        return i18next.exists(key);
129    }
130
131    // 번역 함수
132    this.translate = (key, options = {}) => {
133        if (key === undefined || key === null) {
134            console.warn("[WARN] key 값 누락");
135            return '';
136        }
137
138        if (!i18next.exists(key)) {
139            return '';
140        }
141
142        return i18next.t(key, options);
143    };
144
145    // 줄임 함수
146    this.t = this.translate;
147
148    // i18next를 즉시 초기화
149    this.init();
150}
151
152function waitForI18nInitialization(callback) {
153    if (i18n && i18n.isInitialized) {
154        callback(); // 이미 초기화된 경우 즉시 콜백 실행
155    } else {
156        // i18n 초기화 이벤트를 기다림
157        document.addEventListener('i18nInitialized', callback, { once: true });
158    }
159}
160
161async function changeLanguage(language) {
162    let sendHttp =  new SendHttp('/changeLocale');
163    sendHttp.method = 'POST';
164    sendHttp.data = new FormData();
165    sendHttp.data.append('lang', language);
166
167    let resultMap = await sendHttp.send();
168    return resultMap;
169}
170
171// LocalizationManager를 전역 스코프에 연결
172window.LocalizationManager = LocalizationManager;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.