I am doing transliterate with basic php functions, when I finish the process I get plenty of NUL NUL NUL characters before text and translation. I tried something like this:
function transliterate($textcyr = "") {
$lat = [
'a','b','v','g','d','đ','e','ž','z','i','j','k','l','lj','m','n','nj','o','p','r','s','t','ć','u','f','h','c','č','dž','š','š','š',
'A','B','V','G','D','Đ','E','Ž','Z','I','J','K','L','Lj','M','N','Nj','O','P','R','S','T','Ć','U','F','H','C','Č','Dž','Š','Š', 'Š'
];
$cyr = [
'а','б','в','г','д','ђ','е','ж','з','и','ј','к','л','љ','м','н','њ','о','п','р','с','т','ћ','у','ф','х','ц','ч','џ','ш','ш',
'А','Б','В','Г','Д','Ђ','Е','Ж','З','И','Ј','К','Л','Љ','М','Н','Њ','О','П','Р','С','Т','Ћ','У','Ф','Х','Ц','Ч','Џ','Ш','Ш'
];
return str_replace($cyr, $lat, $textcyr);
}
function transliterate_po() {
$filename = 'wp-content/languages/admin-sr_RS.po';
$myFile = fopen($filename, "r ");
if($myFile) {
$textOriginal = fread($myFile,filesize($filename));
$textTransliterated = transliterate($textOriginal);
//var_dump($textOriginal);
//echo '';
//var_dump($textTransliterated);
ftruncate($myFile, 0);
fwrite($myFile, $textTransliterated);
fclose($myFile);
//var_dump('wp-content/languages/admin-sr_RS.po');
} else {
die("Unable to open file!");}
}
I tried to change value of $textcyrl including null and I didn't get any result with this. Here is print screen enter image description here
CodePudding user response:
you'd better to generate them not editing them, However it's better to use file_get_contents()
and then save another file and replace it with your .po
file.
1- use file_get_contents()
2- replace via transliterate
3- save new file
but the best way is using these packages:
https://github.com/php-gettext/Gettext
https://github.com/raulferras/PHP-po-parser
https://code.google.com/archive/p/php-po-parser/
CodePudding user response:
I solved this with rewind function.