Skip to content

Instantly share code, notes, and snippets.

@no-tactic
Created October 11, 2012 10:36
Show Gist options
  • Save no-tactic/3871534 to your computer and use it in GitHub Desktop.
Save no-tactic/3871534 to your computer and use it in GitHub Desktop.
<?php
/**
* User: Михась
* Date: 07.10.12
* Time: 13:16
*/
$file = './application/views/admin/addpaymentuser.tpl';
$lang_file = './application/language/russian/admin_lang.php';
// Notice. Заметь, что могут быть проблемы из-за одинарных кавычек в коментариях ("that's"), прочее, прочее, прочее. Аккуратно. Не создавай языковой файл для каждого шаблона - для админки, к примеру, можно обойтись и одним
if (!file_exists($file)) {
exit('No such file!');
}
if (!file_exists($lang_file)) {
$f = fopen($lang_file, 'w');
fwrite ($f, "<?php");
fclose($f);
}
$i = count(file($lang_file));
$f = fopen($file, 'r');
$c = fread($f, filesize($file));
fclose($f);
$replacement = array();
$a = array();
$b = array();
$lang_pack = "\n";
preg_match_all("/[^a-zA-Z_0-9<>\/\\\{\}*:;.,=\"'\%\(\)\$\[\]]+/i", $c, $array, PREG_PATTERN_ORDER);
$n = 0;
foreach ($array as $k=>$u) {
if (preg_match("/[а-я]/i", $u[$n])) $replacement[] = $u[$n];
$n++;
}
foreach ($replacement as $u) {
echo $u . '<br>';
if (in_array($u, $a)) continue;
$i++;
$k = 'lng-'.$i;
$a[$k] = $u;
$b[] = '$this->lang->line(\''.$k.'\')';
$c = str_replace($u, '<?=$lang[\''.$k.'\'];?>', $c);
$lang_pack .= "\n".'$lang[\''.$k.'\'] = "'.$u.'";';
}
$f = fopen($lang_file, 'a');
fwrite ($f, $lang_pack);
fclose($f);
$f = fopen($file, 'w');
fwrite ($f, $c);
fclose($f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment