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