l-min-components 1.7.1598 → 1.7.1600
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.
- package/package.json +1 -1
- package/src/hooks/useTranslation.jsx +33 -37
package/package.json
CHANGED
|
@@ -45,30 +45,30 @@ const useTranslation = (initialSentences = []) => {
|
|
|
45
45
|
/**
|
|
46
46
|
* Send translation request to backend (fire-and-forget)
|
|
47
47
|
*/
|
|
48
|
-
const sendTranslationRequestToBackend = async (language, words) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
48
|
+
// const sendTranslationRequestToBackend = async (language, words) => {
|
|
49
|
+
// try {
|
|
50
|
+
// // Fire-and-forget - don't await or use response
|
|
51
|
+
// translate({
|
|
52
|
+
// url: `/iam/v1/utils/translate_async/`,
|
|
53
|
+
// data: {
|
|
54
|
+
// language,
|
|
55
|
+
// sentences: words,
|
|
56
|
+
// },
|
|
57
|
+
// params: {
|
|
58
|
+
// _account: "",
|
|
59
|
+
// },
|
|
60
|
+
// headers: {
|
|
61
|
+
// Authorization: "",
|
|
62
|
+
// },
|
|
63
|
+
// });
|
|
64
|
+
// } catch (err) {
|
|
65
|
+
// console.warn("Translation request failed:", err);
|
|
66
|
+
// }
|
|
67
|
+
// };
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
Fetch master translations from S3 with caching
|
|
71
|
+
**/
|
|
72
72
|
const getMasterTranslationsWithCache = async () => {
|
|
73
73
|
const now = Date.now();
|
|
74
74
|
const cached = window.translationCache.master;
|
|
@@ -119,23 +119,19 @@ const useTranslation = (initialSentences = []) => {
|
|
|
119
119
|
/**
|
|
120
120
|
* Extract relevant translations for specific texts
|
|
121
121
|
*/
|
|
122
|
-
const extractRelevantTranslations = (
|
|
123
|
-
// masterTranslations,
|
|
124
|
-
words,
|
|
125
|
-
language
|
|
126
|
-
) => {
|
|
122
|
+
const extractRelevantTranslations = (masterTranslations, words, language) => {
|
|
127
123
|
const relevantTranslations = {};
|
|
128
124
|
const languageCode = language.toUpperCase(); // ko -> KO, fr -> FR
|
|
129
125
|
|
|
130
126
|
words.forEach((word) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
if (masterTranslations[word] && masterTranslations[word][languageCode]) {
|
|
128
|
+
const translation = masterTranslations[word][languageCode];
|
|
129
|
+
// Only use translation if it's not empty
|
|
130
|
+
relevantTranslations[word] = translation.trim() || word;
|
|
131
|
+
} else {
|
|
132
|
+
// Return original text if translation not found
|
|
133
|
+
relevantTranslations[word] = word;
|
|
134
|
+
}
|
|
139
135
|
});
|
|
140
136
|
|
|
141
137
|
return relevantTranslations;
|
|
@@ -152,11 +148,11 @@ const useTranslation = (initialSentences = []) => {
|
|
|
152
148
|
// sendTranslationRequestToBackend(language, words);
|
|
153
149
|
|
|
154
150
|
// Step 2: Get master translations (cached or fresh from S3)
|
|
155
|
-
|
|
151
|
+
const masterTranslations = await getMasterTranslationsWithCache();
|
|
156
152
|
|
|
157
153
|
// Step 3: Extract only the translations we need
|
|
158
154
|
const relevantTranslations = extractRelevantTranslations(
|
|
159
|
-
|
|
155
|
+
masterTranslations,
|
|
160
156
|
words,
|
|
161
157
|
language
|
|
162
158
|
);
|