-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_lang.php
109 lines (88 loc) · 3.4 KB
/
upload_lang.php
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
// IMPORTANT: the order of both files below must be the same
$baseLangTemplate = 'lang/en.inc.php';
$langImages = 'images_en_messages.txt'; // just images
$langMessages = '%%LANG%%_messages.txt';
$translatedLang = 'lang/%%LANG%%.inc.php';
$lang = 'es';
if (isset($_REQUEST['lang'])) {
$lang = strtolower($_REQUEST['lang']);
}
// replace %%LANG%% with language parameter if any
$langMessages = str_replace('%%LANG%%', $lang, $langMessages);
$translatedLang = str_replace('%%LANG%%', $lang, $translatedLang);
if (!file_exists(dirname(__FILE__) . '/' . $baseLangTemplate)) {
die('Error: The base template file does not exist ' . dirname(__FILE__) . '/' . $baseLangTemplate);
}
if (!file_exists(dirname(__FILE__) . '/' . $langMessages)) {
die('Error: The messages file does not exist ' . dirname(__FILE__) . '/' . $langMessages);
}
$matches = [];
$file_contents = [];
$file_images = [];
include($baseLangTemplate);
$IDX = 0;
foreach ($_lang as $entry) {
$matches[$IDX] = $entry;
$IDX++;
}
echo count($matches) . ' base translations pre-loaded' . '<br>';
$file2 = fopen($langMessages, "r");
if ($file2) {
$file_contents = explode("\n", fread($file2, filesize($langMessages)));
}
// remove empty lines
for ($IDX = 0; $IDX < count($file_contents); $IDX++) {
if (isset($file_contents[$IDX]) && $file_contents[$IDX] != '' && $file_contents[$IDX] != '"') {
} else {
unset($file_contents[$IDX]);
}
}
echo count($file_contents) . ' message translations pre-loaded' . '<br><br>';
$file3 = fopen($langImages, "r");
if ($file3 && filesize($langImages) > 0) {
$file_images = explode("\n", fread($file3, filesize($langImages)));
}
// remove empty lines
for ($IDX = 0; $IDX < count($file_images); $IDX++) {
if (isset($file_images[$IDX]) && $file_images[$IDX] != '' && $file_images[$IDX] != '"') {
} else {
unset($file_images[$IDX]);
}
}
echo count($file_images) . ' images pre-loaded' . '<br><br>';
if (count($matches) != count($file_contents) + count($file_images)) {
die('Error: Count Mismatch');
}
$matchesIDX = count($matches);
$extractedCount = 0;
// delete the old file if it exists for $translatedLang
if (file_exists(dirname(__FILE__) . '/' . $translatedLang)) {
unlink(dirname(__FILE__) . '/' . $translatedLang);
}
$file1 = fopen($translatedLang, "w");
fwrite($file1, '<?php' . PHP_EOL);
for ($IDX = 0; $IDX < count($matches) - count($file_images); $IDX++) {
if (isset($matches[$IDX]) && $matches[$IDX] != '' && $matches[$IDX] != '"') {
$line = preg_replace('/[\x0d]/', '', $file_contents[$IDX]);
$outputLine = "\$_lang['" . addslashes(stripcslashes($matches[$IDX])) . "'] = '" . addslashes(stripcslashes($line)) . "';";
fwrite($file1, $outputLine . PHP_EOL);
}
}
for ($IDX = count($matches) - count($file_images); $IDX < count($matches); $IDX++) {
if (isset($matches[$IDX]) && $matches[$IDX] != '' && $matches[$IDX] != '"') {
$outputLine = "\$_lang['" . addslashes(stripcslashes($matches[$IDX])) . "'] = '" . addslashes(stripcslashes($matches[$IDX])) . "';";
fwrite($file1, $outputLine . PHP_EOL);
}
}
fwrite($file1, '?>' . PHP_EOL);
fclose($file1);
fclose($file2);
fclose($file3);
echo 'Base language template: ' . $baseLangTemplate . '<br>';
echo 'Input Messages File: ' . $langMessages . '<br>';
echo 'New Messages File: ' . $translatedLang . '<br>';
echo 'Done';
exit;