diff options
Diffstat (limited to 'db/i18n.php')
| -rw-r--r-- | db/i18n.php | 38 | 
1 files changed, 30 insertions, 8 deletions
| diff --git a/db/i18n.php b/db/i18n.php index af6fec8..0942802 100644 --- a/db/i18n.php +++ b/db/i18n.php @@ -1,11 +1,11 @@  <?php -$basePath = dirname(__DIR__) . '/modules/tuxemon/mods/tuxemon/l18n'; -foreach (scandir($basePath) as $dirname) { -  if (in_array($dirname, ['.', '..']) || ! is_dir("$basePath/$dirname")) continue; +global $i18n; +$i18n = []; +function populateI18n ($locale, $poFile) { +  global $i18n; +  $i18n[$locale] ??= []; -  $i18n = []; -  $poFile = "$basePath/$dirname/LC_MESSAGES/base.po";    $handle = fopen($poFile, 'r');    while ($line = fgets($handle)) {      if (str_starts_with($line, 'msgid')) { @@ -13,11 +13,33 @@ foreach (scandir($basePath) as $dirname) {        preg_match('/"(.*)"/', $line, $msgid);        preg_match('/"(.*)"/', $nextLine, $msgstr); -      if (empty($msgid[1])) continue; +      if (empty($msgid[1]) || str_starts_with($msgid[1], 'PROJECT DESCRIPTION')) continue; -      $i18n[$msgid[1]] = mb_convert_encoding($msgstr[1], 'UTF-8'); +      $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); +} -  file_put_contents(__DIR__ . "/_generated/i18n/$dirname.json", json_encode($i18n)); +// write +foreach ($i18n as $locale => $translations) { +  file_put_contents(__DIR__ . "/_generated/i18n/$locale.json", json_encode($translations));  } | 
