This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert_cliloc_to_json.php
60 lines (40 loc) · 1.61 KB
/
convert_cliloc_to_json.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
<?php
ini_set('memory_limit', '512M');
$inputClilocs = [];
$directoryIterator = new DirectoryIterator('input');
foreach ($directoryIterator as $fileInfo)
if (strpos(strtolower($fileInfo->getFilename()), 'cliloc') !== false)
array_push($inputClilocs, ['filePath' => $fileInfo->getPathname(), 'language' => strtoupper($fileInfo->getExtension())]);
$allLanguages = [];
foreach ($inputClilocs as $cliloc)
array_push($allLanguages, $cliloc['language']);
$output = [];
foreach ($inputClilocs as $cliloc)
{
echo "Reading {$cliloc['filePath']}... ";
$handle = fopen($cliloc['filePath'], 'rb');
fseek($handle, 6);
while (!feof($handle))
{
$numberBytes = fread($handle, 4);
if (empty($numberBytes))
break;
fread($handle, 1);
$lengthBytes = fread($handle, 2);
$number = unpack('V', $numberBytes)[1];
$length = unpack('v', $lengthBytes)[1];
$text = $length > 0 ? fread($handle, $length) : '';
foreach ($allLanguages as $language)
{
if (empty($output[$number]))
$output[$number] = [];
if (empty($output[$number][$language]))
$output[$number][$language] = '';
}
$output[$number][$cliloc['language']] = $text;
}
fclose($handle);
echo 'OK!' . PHP_EOL;
}
$saved = file_put_contents('json/Cliloc.json', json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo ($saved === false) ? 'Error! Cliloc.json could not be saved.' : 'Done! Cliloc.json has been saved in json folder. You can open and edit it using any text editor.';