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