summaryrefslogtreecommitdiff
path: root/db/i18n.php
blob: af6fec88da494855acb28a8a38644f8c31faed4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

$basePath = dirname(__DIR__) . '/modules/tuxemon/mods/tuxemon/l18n';
foreach (scandir($basePath) as $dirname) {
  if (in_array($dirname, ['.', '..']) || ! is_dir("$basePath/$dirname")) continue;

  $i18n = [];
  $poFile = "$basePath/$dirname/LC_MESSAGES/base.po";
  $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])) continue;

      $i18n[$msgid[1]] = mb_convert_encoding($msgstr[1], 'UTF-8');
    }
  }

  file_put_contents(__DIR__ . "/_generated/i18n/$dirname.json", json_encode($i18n));
}