forked from dimdenGD/OldTwitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocales-support.html
587 lines (496 loc) · 19.7 KB
/
locales-support.html
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Locale Diff Tool</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsdiff/5.1.0/diff.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
color: #333;
transition: all 0.3s ease;
}
.container {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.text-box {
flex: 1;
padding: 10px;
}
.text-box h3 {
margin-top: 0;
}
textarea {
width: 100%;
height: 400px;
resize: vertical;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-family: monospace;
}
select {
padding: 8px;
margin-bottom: 10px;
border-radius: 4px;
}
#diff-container {
background: white;
padding: 20px;
border-radius: 4px;
margin-top: 20px;
white-space: pre-wrap;
font-family: monospace;
}
/* Dark mode styles */
body.body-dark {
background-color: #1a1a1a;
color: #fff;
}
.body-dark .text-box,
.body-dark .converter-box,
.body-dark .diff-section,
.body-dark .stats {
background: #2d2d2d;
color: #fff;
}
.body-dark textarea {
background: #1a1a1a;
color: #fff;
border-color: #444;
}
.body-dark select {
background: #1a1a1a;
color: #fff;
border-color: #444;
}
.body-dark button {
background-color: #1da1f2;
color: white;
}
.body-dark button:hover {
background-color: #1991db;
}
.body-dark code {
background: #333;
color: #fff;
}
.body-dark .warning {
background-color: #2c2620;
}
.added {
color: white;
background-color: #a5d6a7;
}
.removed {
background-color: #ef9a9a;
}
h3.removed {
color: #c62828;
/* dark red for better contrast */
background-color: transparent;
}
.body-dark h3.removed {
color: #ff9a98;
/* light red for dark mode */
}
button {
padding: 8px 16px;
background-color: #1da1f2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #1991db;
}
.diff-section {
margin: 20px 0;
padding: 15px;
background: white;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.diff-section h3 {
margin-top: 0;
color: #000000;
}
.diff-section ul {
margin: 0;
font-size: 1rem;
padding-left: 20px;
}
.diff-section li {
margin: 5px 0;
line-height: 1.5;
}
.warning {
background-color: #fff3e0;
padding: 10px;
border-radius: 4px;
margin: 5px 0;
}
code {
background: #f5f5f5;
padding: 2px 4px;
border-radius: 3px;
font-family: monospace;
}
.stats {
background: white;
padding-left: 15px;
border-radius: 50px;
margin-bottom: 20px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.stats ul {
list-style: none;
}
.stats li {
font-size: 20px;
margin: 5px 0;
}
.converter-box {
margin-top: 20px;
padding: 20px;
background: white;
border-radius: 4px;
}
#darkModeButton {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
padding: 5px 10px;
border-radius: 50%;
transition: background-color 0.3s;
}
#darkModeButton:hover {
background-color: rgba(0, 0, 0, 0.1);
}
.instructions {
background-color: #e8f4ff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
border: 1px solid #b8daff;
}
.body-dark .diff-section h3 {
margin-top: 0;
color: #ffffff;
}
/* Keeps specific colors for added/removed */
.diff-section h3.added {
color: #2e7d32;
}
.diff-section h3.removed {
color: #c62828;
}
.body-dark .diff-section h3.added {
color: #81c784;
}
.body-dark .diff-section h3.removed {
color: #ef5350;
}
.body-dark .instructions {
background-color: #1a2635;
color: #fff;
border-color: #2a3f55;
}
.body-dark #diff-container {
background: #8d8d8d6b;
color: #000000 !important;
border-color: #2a3f55;
}
.instructions h3 {
margin-top: 0;
color: #0056b3;
}
.body-dark .instructions h3 {
color: #66b0ff;
}
.instructions ol {
margin: 0;
padding-left: 20px;
}
.instructions li {
margin-bottom: 8px;
}
</style>
</head>
<body>
<div class="instructions">
<h3>How to Use the Locale Diff Tool</h3>
<ol>
<li><strong>Compare Translations:</strong>
<ul>
<li>Select your language from the dropdown menu</li>
<li>Click "Compare" to see differences with the English base version</li>
<li>The tool will show both versions side by side</li>
<li>Missing translations will be highlighted</li>
</ul>
</li>
<li><strong>Convert Text to JSON:</strong>
<ul>
<li>Use the converter box at the bottom of the page</li>
<li>Paste your text in the format: <code>key: "value"</code></li>
<li>Click "Convert to JSON" to get the proper messages.json format</li>
</ul>
</li>
<li><strong>Tips:</strong>
<ul>
<li>Use the dark/light mode toggle (☀️/🌙) for better visibility</li>
<li>The comparison will show missing or different translations</li>
<li>Copy the converted JSON output to your messages.json file</li>
</ul>
</li>
</ol>
</div>
<h2>Locale Diff Tool</h2>
<div>
<select id="language-select">
<option value="en">English (Base)</option>
</select>
<button onclick="loadAndCompare()">Compare</button>
<button onclick="darkMode()" id="darkModeButton">
<span id="darkModeIcon">☀️</span>
</button>
</div>
<div class="container">
<div class="text-box">
<h3>English (Base)</h3>
<textarea id="text-box-1" readonly></textarea>
</div>
<div class="text-box">
<h3>Selected Language</h3>
<textarea id="text-box-2" readonly></textarea>
</div>
</div>
<div id="diff-container"></div>
<div class="converter-box">
<h3>Text to JSON Converter</h3>
<textarea id="convert-input" style="width: 100%; height: 200px; margin-bottom: 10px;"
placeholder="Cole aqui o texto no formato: key: "value" another_key: "another value""></textarea>
<button onclick="convertToJson()">Convert to JSON</button>
<textarea id="convert-output" style="width: 100%; height: 200px; margin-top: 10px;" readonly></textarea>
</div>
<script>
const darkModeIcon = document.getElementById('darkModeIcon');
function darkMode() {
document.body.classList.toggle('body-dark');
darkModeIcon.textContent = document.body.classList.contains('body-dark') ? '🌙' : '☀️';
// Save preference to localStorage
localStorage.setItem('darkMode',
document.body.classList.contains('body-dark'));
}
//Load theme preference on startup
window.addEventListener('load', () => {
const isDarkMode = localStorage.getItem('darkMode') === 'true';
if (isDarkMode) {
document.body.classList.add('body-dark');
darkModeIcon.textContent = '🌙';
}
});
// Language names mapping
const LANGUAGE_NAMES = {
'ar': 'Arabic',
'bg': 'Bulgarian',
'ca': 'Catalan',
'cs': 'Czech',
'de': 'German',
'el': 'Greek',
'en': 'English',
'es': 'Spanish',
'fi': 'Finnish',
'fr': 'French',
'he': 'Hebrew',
'id': 'Indonesian',
'it': 'Italian',
'ja': 'Japanese',
'ko': 'Korean',
'lv': 'Latvian',
'nb': 'Norwegian',
'ne': 'Nepali',
'nl': 'Dutch',
'pl': 'Polish',
'pt_BR': 'Portuguese (Brazil)',
'ro': 'Romanian',
'ru': 'Russian',
'sv': 'Swedish',
'th': 'Thai',
'tl': 'Tagalog',
'tr': 'Turkish',
'uk': 'Ukrainian',
'vi': 'Vietnamese',
'zh_CN': 'Chinese (Simplified)',
'zh_TW': 'Chinese (Traditional)'
};
// static List of locales available, for offline use only
const AVAILABLE_LOCALES = [
'ar', 'bg', 'ca', 'cs', 'de', 'el', 'en', 'es', 'fi', 'fr',
'he', 'id', 'it', 'ja', 'ko', 'lv', 'nb', 'ne', 'nl', 'pl',
'pt_BR', 'ro', 'ru', 'sv', 'th', 'tl', 'tr', 'uk', 'vi',
'zh_CN', 'zh_TW'
];
// Function to load available locales
async function loadAvailableLocales() {
const select = document.getElementById('language-select');
try {
// Usando a lista estática de locales
const locales = AVAILABLE_LOCALES;
// Sort locales alphabetically by their display names
locales.sort((a, b) => {
const nameA = LANGUAGE_NAMES[a] || a;
const nameB = LANGUAGE_NAMES[b] || b;
return nameA.localeCompare(nameB);
});
// Add options to select
locales.forEach(locale => {
if (locale === 'en') return; // Skip English as it's already the first option
const option = document.createElement('option');
option.value = locale;
option.textContent = LANGUAGE_NAMES[locale] || locale;
select.appendChild(option);
});
} catch (error) {
console.error('Error loading locales:', error);
}
}
async function loadLocaleFile(locale) {
try {
const response = await fetch(`https://raw.githubusercontent.com/dimdenGD/OldTwitter/master/_locales/${locale}/messages.json`);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
return data;
} catch (error) {
console.error(`Error loading ${locale} locale:`, error);
return null;
}
}
async function loadAndCompare() {
const selectedLanguage = document.getElementById('language-select').value;
const textBox1 = document.getElementById('text-box-1');
const textBox2 = document.getElementById('text-box-2');
// Load both locale files
const enData = await loadLocaleFile('en');
const selectedData = await loadLocaleFile(selectedLanguage);
if (!enData || !selectedData) {
alert('Error loading locale files');
return;
}
// Display the raw JSON
textBox1.value = JSON.stringify(enData, null, 2);
textBox2.value = JSON.stringify(selectedData, null, 2);
// Compare and show differences
compareLocales(enData, selectedData);
}
function compareLocales(enData, selectedData) {
const diffContainer = document.getElementById('diff-container');
diffContainer.innerHTML = '';
// Get all keys from both objects
const enKeys = new Set(Object.keys(enData));
const selectedKeys = new Set(Object.keys(selectedData));
// Find missing keys
const missingInSelected = [...enKeys].filter(key => !selectedKeys.has(key));
const extraInSelected = [...selectedKeys].filter(key => !enKeys.has(key));
// Create report
let report = '';
if (missingInSelected.length > 0) {
report += '<div class="diff-section">';
report += '<h3 class="removed">🚫 Missing Translations</h3>';
report += '<ul>';
missingInSelected.forEach(key => {
report += `<li><code>${key}</code>: "${enData[key].message}"</li>`;
});
report += '</ul></div>';
}
if (extraInSelected.length > 0) {
report += '<div class="diff-section">';
report += '<h3 class="added">✨ Extra Keys</h3>';
report += '<ul>';
extraInSelected.forEach(key => {
report += `<li><code>${key}</code>: "${selectedData[key].message}"</li>`;
});
report += '</ul></div>';
}
// Check for structural differences (missing placeholders, etc.)
report += '<div class="diff-section">';
report += '<h3>🔍 Structural Differences</h3>';
report += '<ul>';
const commonKeys = [...enKeys].filter(key => selectedKeys.has(key));
let hasStructuralDiffs = false;
commonKeys.forEach(key => {
const enMessage = enData[key].message;
const selectedMessage = selectedData[key].message;
// Check for placeholder differences ($1, $2, etc.)
const enPlaceholders = (enMessage.match(/\$\d+/g) || []).sort();
const selectedPlaceholders = (selectedMessage.match(/\$\d+/g) || []).sort();
if (JSON.stringify(enPlaceholders) !== JSON.stringify(selectedPlaceholders)) {
hasStructuralDiffs = true;
report += `<li class="warning"><code>${key}</code>:<br>`;
report += `EN placeholders: ${enPlaceholders.join(', ') || 'none'}<br>`;
report += `Translation placeholders: ${selectedPlaceholders.join(', ') || 'none'}</li>`;
}
});
if (!hasStructuralDiffs) {
report += '<li>✅ No structural differences found</li>';
}
report += '</ul></div>';
// Add statistics
const stats = `
<div class="stats">
<h3>📊 Statistics</h3>
<ul>
<li>Total keys in English: ${enKeys.size}</li>
<li>Total keys in translation: ${selectedKeys.size}</li>
<li>Missing translations: ${missingInSelected.length}</li>
<li>Extra keys: ${extraInSelected.length}</li>
<li>Coverage: ${Math.round((commonKeys.length / enKeys.size) * 100)}%</li>
</ul>
</div>
`;
diffContainer.innerHTML = stats + report;
}
function convertToJson() {
const input = document.getElementById('convert-input').value;
const output = document.getElementById('convert-output');
try {
// Split text into lines
const lines = input.split('\n').filter(line => line.trim());
// Creates an object to store key-value pairs
const result = {};
// Processes each line
lines.forEach(line => {
// Finds the first ':'
const colonIndex = line.indexOf(':');
if (colonIndex === -1) return;
// Extract key and value
const key = line.substring(0, colonIndex).trim();
const value = line.substring(colonIndex + 1).trim();
// add to result object
result[key] = {
"message": value.replace(/^"(.*)"$/, '$1')
};
});
// Convert to formatted JSON
const jsonString = JSON.stringify(result, null, 4);
output.value = jsonString;
} catch (error) {
output.value = "Error: " + error.message;
}
}
// Load initial comparison when page loads
window.onload = () => {
loadAvailableLocales().then(() => {
loadAndCompare();
});
};
</script>
</body>
</html>