Skip to content

Instantly share code, notes, and snippets.

@Q0
Created February 26, 2020 06:08
Show Gist options
  • Save Q0/4b53ce48acae656c4e1d12e91e4046de to your computer and use it in GitHub Desktop.
Save Q0/4b53ce48acae656c4e1d12e91e4046de to your computer and use it in GitHub Desktop.
Заменяет все строки в шаблоне CodeIgniter для поддержки PO файлов
<?php
$path = realpath(__DIR__ . '/application/views/'); //
$fileList = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($fileList as $item) {
if ($item->isFile() && stripos($item->getPathName(), 'php') !== false) {
$file_contents = file_get_contents($item->getPathName());
$file_contents = preg_replace_callback('/<\?php echo \$this->lang->line\(\'(.*)\'\);\?>/m', function($matches) use (&$replacements) {
$pathLang = realpath(__DIR__ . '/application/language/russian/'); //
include $pathLang.'/app_lang.php';
return "<?=__('".$lang[$matches[1]]."');?>";
}, $file_contents);
file_put_contents($item->getPathName(),$file_contents);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment