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
|
<?php
global $i18n;
$i18n = [];
function populateI18n ($locale, $poFile) {
global $i18n;
$i18n[$locale] ??= [];
$handle = fopen($poFile, 'r');
while ($line = fgets($handle)) {
if (str_starts_with($line, 'msgid')) {
$nextLine = fgets($handle);
preg_match('/"(.*)"/', $line, $msgid);
preg_match('/"(.*)"/', $nextLine, $msgstr);
if (empty($msgid[1]) || str_starts_with($msgid[1], 'PROJECT DESCRIPTION')) continue;
$i18n[$locale][$msgid[1]] = mb_convert_encoding($msgstr[1], 'UTF-8');
}
}
}
// tuxemon clicker
$basePath = __DIR__ . '/i18n';
foreach (scandir($basePath) as $file) {
if (in_array($file, ['.', '..'])) continue;
$locale = pathinfo($file, PATHINFO_FILENAME);
$poFile = "$basePath/$file";
populateI18n($locale, $poFile);
}
// modules/tuxemon
$basePath = dirname(__DIR__) . '/modules/tuxemon/mods/tuxemon/l18n';
foreach (scandir($basePath) as $dirname) {
if (in_array($dirname, ['.', '..']) || ! is_dir("$basePath/$dirname")) continue;
$poFile = "$basePath/$dirname/LC_MESSAGES/base.po";
populateI18n($dirname, $poFile);
}
// write
foreach ($i18n as $locale => $translations) {
file_put_contents(__DIR__ . "/_generated/i18n/$locale.json", json_encode($translations));
}
|