-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathlanguages.js
More file actions
410 lines (378 loc) · 14.2 KB
/
languages.js
File metadata and controls
410 lines (378 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*
* Material You NewTab
* Copyright (c) 2023-2025 XengShi
* Licensed under the GNU General Public License v3.0 (GPL-3.0)
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
// Translation data
const translations = {
en: en, // English
pt: pt, // Portuguese-BR (Brazil)
zh: zh, // Chinese (Simplified)
zh_TW: zh_TW, // Chinese (Traditional)
hi: hi, // Hindi
hu: hu, // Hungarian
cs: cs, // Czech
it: it, // Italian
tr: tr, // Turkish
bn: bn, // Bengali
vi: vi, // Vietnamese
ru: ru, // Russian
uz: uz, // Uzbek
es: es, // Spanish
ja: ja, // Japanese
ko: ko, // Korean
idn: idn, // Indonesian
mr: mr, // Marathi
fr: fr, // French
az: az, // Azerbaijani
sl: sl, // Slovenian
np: np, // Nepali
ur: ur, // Urdu
de: de, // German
fa: fa, // Farsi (Persian)
ar_SA: ar_SA, // Arabic (Saudi Arabia)
el: el, // Greek
ta: ta, // தமிழ்
th: th, // Thai
pl: pl, // Polish
};
// Define the width of the menu container for each language
const menuWidths = {
en: "400px",
ta: "480px",
pt: "470px",
bn: "416px",
uz: "455px",
vi: "445px",
cs: "452px",
es: "446px",
hi: "408px",
hu: "445px",
ja: "444px",
ru: "400px",
it: "437px",
idn: "435px",
tr: "430px",
fr: "475px",
az: "418px",
sl: "470px",
np: "430px",
de: "460px",
fa: "460px",
ar_SA: "440px",
el: "455px",
th: "455px",
pl: "455px",
// Add more languages and widths as needed
};
const numberMappings = {
"bn": { "0": "০", "1": "১", "2": "২", "3": "৩", "4": "৪", "5": "৫", "6": "৬", "7": "৭", "8": "৮", "9": "৯" },
"ta": { "0": "௦", "1": "௧", "2": "௨", "3": "௩", "4": "௪", "5": "௫", "6": "௬", "7": "௭", "8": "௮", "9": "௯" },
"mr": { "0": "०", "1": "१", "2": "२", "3": "३", "4": "४", "5": "५", "6": "६", "7": "७", "8": "८", "9": "९" },
"np": { "0": "०", "1": "१", "2": "२", "3": "३", "4": "४", "5": "५", "6": "६", "7": "७", "8": "८", "9": "९" },
"fa": { 0: "۰", 1: "۱", 2: "۲", 3: "۳", 4: "۴", 5: "۵", 6: "۶", 7: "۷", 8: "۸", 9: "۹" },
"ar_SA": { 0: "۰", 1: "۱", 2: "۲", 3: "۳", 4: "٤", 5: "٥", 6: "٦", 7: "۷", 8: "۸", 9: "۹" }
// Add more languages as needed, Ensure it is supported in the fonts
};
const LRM = "\u200E"; // Left-to-Right Mark
function localizeNumbers(text, language) {
const map = numberMappings[language]; // Get the numeral map for the current language
// Define languages that use a comma as the decimal separator instead of a dot
const specialDecimalLanguages = ["cs", "it", "pt", "ru", "tr", "vi", "uz", "es", "ko", "idn", "fr", "az", "sl", "hu", "de", "fa", "el"]; // Add more languages here as needed
if (specialDecimalLanguages.includes(language)) {
// Replace decimal point with a comma for specific languages
text = text.replace(".", ",");
}
// Apply digit localization if the numeral map exists
if (map) {
text = text.replace(/\d/g, (digit) => map[digit] || digit);
}
// LRM marks, for RTL languages to ensure correct display
const rtlFlipLanguages = ["ar_SA"];
if (rtlFlipLanguages.includes(language)) {
text = `${LRM}${text}${LRM}`;
}
return text; // Return the localized text
}
// Right-to-left languages
const rtlLanguages = ["ur", "fa", "ar_SA"];
// Function to apply the language to the page
function applyLanguage(lang) {
// Mapping of text elements and their translation keys
const translationMap = [
"feedback",
"resetsettings",
"shortcutsText",
"enableShortcutsText",
"editShortcutsText",
"shortcutsInfoText",
"editShortcutsList",
"editShortcutsListInfo",
"adaptiveIconText",
"adaptiveIconInfoText",
"ai_tools_button",
"enable_ai_tools",
"aiToolsSettingsText",
"aiToolsSettingsInfo",
"googleAppsMenuText",
"googleAppsMenuInfo",
"todoListText",
"todoListInfo",
"fahrenheitCelsiusCheckbox",
"fahrenheitCelsiusText",
"minMaxTempText",
"minMaxTempSubText",
"hideWeatherTitle",
"hideWeatherInfo",
"hideWeatherBox",
"hideWeatherBoxInfo",
"micIconTitle",
"micIconInfo",
"hideSearchWith",
"hideSearchWithInfo",
"motivationalQuotesText",
"motivationalQuotesInfo",
"search_suggestions_button",
"search_suggestions_text",
"hideClockBox",
"hideClockBoxInfo",
"digitalclocktitle",
"digitalclockinfo",
"timeformattitle",
"timeformatinfo",
"greetingtitle",
"greetinginfo",
"userTextTitle",
"userTextInfo",
"useproxytitletext",
"useproxyText",
"ProxyText",
"ProxySubtext",
"HostproxyButton",
"UserLocText",
"UserLocSubtext",
"useGPS",
"useGPSInfo",
"PrivacyPolicy",
"WeatherApiText",
"WeatherApiSubtext",
"LearnMoreButton",
"saveAPI",
"enterBtn",
"ai_tools",
"defaultEngine",
"googleEngine",
"duckEngine",
"bingEngine",
"braveEngine",
"youtubeEngine",
"gImagesEngine",
"redditEngine",
"wikipediaEngine",
"quoraEngine",
"chatGPT",
"gemini",
"copilot",
"claude",
"grok",
"qwen",
"perplexity",
"deepseek",
"metaAI",
'firefly',
"github",
"googleAppsHover",
"todoListHover",
"uploadWallpaperText",
"backupText",
"restoreText",
"rangColor",
"bookmarksText",
"bookmarksInfo",
"bookmarksHeading",
"bookmarkSortBy",
"sortAlphabetical",
"sortTimeAdded",
"bookmarkViewAs",
"bookmarkViewGrid",
"bookmarkViewList",
"editBookmarkHeading",
"lightThemed",
"darkThemed",
"systemThemed",
"switchSearchModes",
"switchSearchModesInfo",
"adjustZoom",
"changeBrowserTheme",
"updateFirefoxHomepage",
"dontShowTips",
"aiSettingsIntro",
"resetAISettingsBtn",
/* Glassmorphism */
"glassmorphismText",
"glassmorphismInfo",
"glassBlurTitle",
"glassBlurDesc",
"opacityTitle",
"adjustOpacityDesc",
"footerToastTitle",
"footerToastMessage"
];
// Specific mapping for placeholders
const placeholderMap = [
{ id: "userLoc", key: "userLoc" },
{ id: "userAPI", key: "userAPI" },
{ id: "searchQ", key: "searchPlaceholder" },
{ id: "todoInput", key: "todoPlaceholder" },
{ id: "bookmarkSearch", key: "bookmarkSearch" },
{ id: "editBookmarkName", key: "editBookmarkName" },
{ id: "editBookmarkURL", key: "editBookmarkURL" }
];
// Mapping of elements and their different translation keys
const elementsMap = [
{ id: "todoListHeading", key: "todoListText" },
{ id: "defaultEngineDD", key: "defaultEngine" },
{ id: "googleEngineDD", key: "googleEngine" },
{ id: "duckEngineDD", key: "duckEngine" },
{ id: "bingEngineDD", key: "bingEngine" },
{ id: "braveEngineDD", key: "braveEngine" },
{ id: "youtubeEngineDD", key: "youtubeEngine" },
{ id: "gImagesEngineDD", key: "gImagesEngine" },
{ id: "redditEngineDD", key: "redditEngine" },
{ id: "wikipediaEngineDD", key: "wikipediaEngine" },
{ id: "quoraEngineDD", key: "quoraEngine" },
{ id: "bookmarksHover", key: "bookmarksHeading" },
{ id: "saveproxy", key: "saveAPI" },
{ id: "saveLoc", key: "saveAPI" },
{ id: "saveBookmarkChanges", key: "saveAPI" },
{ id: "cancelBookmarkEdit", key: "cancelText" },
{ id: "aiSettingsHeader", key: "aiToolsSettingsText" },
{ id: "saveAISettingsBtn", key: "saveAPI" },
{ id: "editBookmarkNameLabel", key: "editBookmarkName" },
{ id: "editBookmarkURLLabel", key: "editBookmarkURL" }
];
// Function to apply translations
function applyTranslations(items, isPlaceholder) {
items.forEach(item => {
// Get the element by its ID
const element = document.getElementById(item.id || item);
if (element) {
// Use "key" if defined, otherwise use "id" as the translation key
const key = item.key || item;
// Get the translation, fallback to English if not found in the current language
const translation = translations[lang]?.[key] || translations["en"]?.[key];
// Apply the translation to either placeholder or innerText
if (isPlaceholder) {
element.placeholder = translation;
} else {
element.innerText = translation;
}
}
});
}
// Apply the translations
applyTranslations(placeholderMap, true); // For placeholders
applyTranslations(elementsMap, false); // For innerTexts with different IDs and keys
applyTranslations(translationMap, false); // For innerTexts with same ID and keys
// For userText
const userTextDiv = document.getElementById("userText");
if (translations[lang]) {
const placeholder = translations[lang]?.userText || translations["en"].userText;
userTextDiv.dataset.placeholder = placeholder; // Update the placeholder in data attribute
// Only set the text content if there's nothing in localStorage
if (!localStorage.getItem("userText")) {
userTextDiv.innerText = placeholder;
}
}
// Update hover text for #menuCloseButton
const menuCloseButton = document.getElementById("menuCloseButton");
if (menuCloseButton) {
const hoverText = translations[lang]?.menuCloseText || translations["en"].menuCloseText;
menuCloseButton.setAttribute("data-lang", hoverText);
}
// Update the width of the menu container based on the language
const menuCont = document.querySelector(".menuBar .menuCont");
if (menuCont) {
menuCont.style.width = menuWidths[lang] || menuWidths["en"];
let widthh = window.innerWidth / parseInt(menuWidths[lang] || menuWidths["en"]);
if (window.innerWidth < 476) {
let menuStyle = document.getElementById("menuStyle") || document.createElement("style");
menuStyle.id = "menuStyle";
menuStyle.innerHTML = `
.menuCont {
scale: ${widthh} !important;
height: ${(100 / widthh).toString()}dvh !important;
transform-origin: top right !important;
}
`;
document.head.append(menuStyle);
}
}
// Function to dynamically load Google Fonts
function loadFont(fontUrl) {
if (!document.querySelector(`link[href="${fontUrl}"]`)) {
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = fontUrl;
document.head.appendChild(link);
}
}
// Dynamically update the font family based on the language
const root = document.documentElement;
const commonFontStack = "'poppins', 'Poppins', sans-serif";
if (lang === "vi") {
loadFont("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro&display=swap");
root.style.setProperty("--main-font-family", `"Be Vietnam Pro", ${commonFontStack}`);
} else if (lang === "ur") {
loadFont("https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic&display=swap");
root.style.setProperty("--main-font-family", `"Noto Sans Arabic", ${commonFontStack}`);
} else if (lang === "fa") {
loadFont("https://fonts.googleapis.com/css2?family=Vazirmatn&display=swap"); // Using Vazirmatn for Farsi
root.style.setProperty("--main-font-family", `"Vazirmatn", ${commonFontStack}`);
} else {
root.style.setProperty("--main-font-family", commonFontStack);
}
// Apply the direction attribute to specific selectors for RTL languages
const isRTL = rtlLanguages.includes(lang);
const rtlSelectors = [".topDiv", ".searchbar", ".searchWithCont", ".resultBox", ".quotesCont",
".leftDiv", ".shortcutsContainer", ".page", "#prompt-modal-box", ".todo-container",
".bookmark-search-container", ".bookmark-controls-container", "#editBookmarkModal", ".liquidGlass-toast"];
rtlSelectors.forEach(selector => {
document.querySelectorAll(selector).forEach(el => {
el.setAttribute("dir", isRTL ? "rtl" : "ltr");
});
});
// Update feelsLike element styles for RTL languages
const feelsLikeElement = document.getElementById("feelsLike");
feelsLikeElement.style.left = isRTL ? "12px" : "";
feelsLikeElement.style.paddingRight = isRTL ? "43px" : "";
feelsLikeElement.style.width = isRTL ? "calc(100% - 12px)" : "";
feelsLikeElement.style.textAlign = isRTL ? "right" : "left";
const quotesText = document.querySelector(".quotesContainer");
// quotesText.style.textAlign = isRTL ? "right" : "left";
quotesText.style.fontFamily = commonFontStack;
// Save the selected language in localStorage
document.documentElement.lang = currentLanguage;
saveLanguageStatus("selectedLanguage", lang);
}
// Detect language from navigator.language
document.getElementById("languageSelector").addEventListener("change", (event) => {
applyLanguage(event.target.value);
location.reload();
});
// Function to apply the language when the page loads
window.onload = function () {
const savedLanguage = getLanguageStatus("selectedLanguage") || "en"; // Default language is English
document.getElementById("languageSelector").value = savedLanguage;
applyLanguage(savedLanguage);
};
// Function to save the language status in localStorage
function saveLanguageStatus(key, languageStatus) {
localStorage.setItem(key, languageStatus);
}
// Function to get the language status from localStorage
function getLanguageStatus(key) {
return localStorage.getItem(key);
}