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.