1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oc\Translation; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* very quick and dirty solution to import crowdin snippets into the legacy translation system |
9
|
|
|
*/ |
10
|
|
|
class CrowdinImport |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Connection |
14
|
|
|
*/ |
15
|
|
|
private $connection; |
16
|
|
|
|
17
|
|
|
public function __construct(Connection $connection) |
18
|
|
|
{ |
19
|
|
|
$this->connection = $connection; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function importTranslations() |
23
|
|
|
{ |
24
|
|
|
$translationArray = $this |
25
|
|
|
->readCrowdinCsv(__DIR__ . '/../../../app/Resources/translations/legacycode/oc_legacy.de.csv'); |
26
|
|
|
|
27
|
|
|
foreach ($translationArray as $translation) { |
28
|
|
|
foreach (['de', 'fr', 'nl', 'es', 'pl', 'it', 'ru'] as $languageKey) { |
29
|
|
|
$this->connection->executeUpdate( |
30
|
|
|
'UPDATE sys_trans_text SET `text` = :text |
31
|
|
|
WHERE lang = :langKey AND trans_id = :identifier', |
32
|
|
|
[ |
33
|
|
|
'text' => $translation->$languageKey, |
34
|
|
|
'id' => $translation->identifier, |
35
|
|
|
'langKey' => $languageKey, |
36
|
|
|
'identifier' => $translation->identifier |
37
|
|
|
] |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $path |
45
|
|
|
* @return TranslationStruct[] |
46
|
|
|
*/ |
47
|
|
|
private function readCrowdinCsv($path) |
48
|
|
|
{ |
49
|
|
|
$csvHeadline = []; |
50
|
|
|
$translationStructs = []; |
51
|
|
|
if (($handle = fopen($path, 'rb')) !== false) { |
52
|
|
|
while (($data = fgetcsv($handle, 0, ';')) !== false) { |
53
|
|
|
if (!$csvHeadline) { |
|
|
|
|
54
|
|
|
$csvHeadline = array_values($data); |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$translationStructs[] = (new TranslationStruct())->fromCsvArray(array_combine($csvHeadline, $data)); |
59
|
|
|
} |
60
|
|
|
fclose($handle); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $translationStructs; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.