Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
1.7 KiB

  1. <?php
  2. function po2php_run($argv, $argc) {
  3. if ($argc!=2) {
  4. print "Usage: ".$argv[0]." <file.po>\n\n";
  5. return;
  6. }
  7. $pofile = $argv[1];
  8. $outfile = dirname($pofile)."/strings.php";
  9. if (!file_exists($pofile)){
  10. print "Unable to find '$pofile'\n";
  11. return;
  12. }
  13. print "Out to '$outfile'\n";
  14. $out="<?php\n\n";
  15. $infile = file($pofile);
  16. $k="";
  17. $arr = False;
  18. $ink = False;
  19. foreach ($infile as $l) {
  20. $len = strlen($l);
  21. if (substr($l,0,15)=='"Plural-Forms: '){
  22. $match=Array();
  23. preg_match("|nplurals=([0-9]*); plural=(.*);|", $l, $match);
  24. $cond = str_replace('n','$n',$match[2]);
  25. $out .= 'function string_plural_select($n){'."\n";
  26. $out .= ' return '.$cond.';'."\n";
  27. $out .= '}'."\n";
  28. }
  29. if ($k!="" && substr($l,0,7)=="msgstr "){
  30. if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
  31. $v = substr($l,7,$len-8);
  32. $out .= $v;
  33. }
  34. if ($k!="" && substr($l,0,7)=="msgstr["){
  35. if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }
  36. if (!$arr) {
  37. $arr=True;
  38. $out .= "array(\n";
  39. }
  40. $match=Array();
  41. preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
  42. $out .= "\t". $match[1]." => ". $match[2] .",\n";
  43. }
  44. if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; };
  45. if ($ink) {
  46. $k .= trim($l,"\" \r\n");
  47. //$out .= '$a->strings['.$k.'] = ';
  48. }
  49. if (substr($l,0,6)=="msgid "){
  50. if ($k!="") $out .= $arr?");\n":";\n";
  51. $arr=False;
  52. $k = str_replace("msgid ","",$l);
  53. if ($k != '""' ) {
  54. $k = trim($k,"\"\r\n");
  55. } else {
  56. $k = "";
  57. }
  58. $ink = True;
  59. }
  60. }
  61. if ($k!="") $out .= $arr?");\n":";\n";
  62. file_put_contents($outfile, $out);
  63. }
  64. if (array_search(__file__,get_included_files())===0){
  65. po2php_run($argv,$argc);
  66. }