Translated using Weblate (Slovenian)
[phpmyadmin.git] / scripts / fix-po-twig
blob9c3d86770df9614089d0711b84fe987944a53049
1 <?php
2 declare(strict_types=1);
4 if (! defined('ROOT_PATH')) {
5     define('ROOT_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR);
8 $tmpDir = dirname(__FILE__) . '/../twig-templates';
9 $potName = 'po/phpmyadmin.pot';
10 $replacements = json_decode(file_get_contents($tmpDir . '/replace.json'), true);
12 /* Read pot file */
13 $pot = file_get_contents($potName);
15 /* Do the replacements */
16 $pot = preg_replace_callback(
17     '@(twig-templates[0-9a-f/]*.php):([0-9]*)@',
18     function ($matches) {
19         global $replacements;
20         $filename = $matches[1];
21         $line = intval($matches[2]);
22         $replace = $replacements[$filename];
23         foreach ($replace[1] as $cacheline => $result) {
24             if ($line >= $cacheline) {
25                 return $replace[0] . ':' . $result;
26             }
27         }
28         return $replace[0] . ':0';
29     },
30     $pot
33 /* Write fixed file */
34 $handle = fopen($potName, 'w');
35 fwrite($handle, $pot);
36 fclose($handle);