Make translation for Zend_translate via Perl script


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/opt/local/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Cwd;
  6. use List::MoreUtils qw/ uniq /;
  7.  
  8. use File::Find;
  9.  
  10. my $file_pattern =$ARGV[2];
  11. my $path = cwd."/".$ARGV[0];
  12. my $trans_file = cwd."/".$ARGV[1];
  13. my @out;
  14. my @uniq;
  15. my $tlumaczenia = 0;
  16. my $xml;
  17.  
  18. find(\&translate_check, $path);
  19.  
  20. sub translate_check
  21. {
  22. my $file = $File::Find::name;
  23. return unless $file =~ /.svn/;
  24. open F, $file or print "couldn't open $file\n" && return;
  25. while (<F>)
  26. {
  27. if (/(.*)_\('(.*)'\)(.*)/)
  28. {
  29. push(@out, $2);
  30. }
  31. }
  32. close F;
  33. }
  34.  
  35. open T, $trans_file or print "couldn't open $trans_file\n";
  36. while (<T>)
  37. {
  38. @uniq = uniq @out;
  39. if(/\<tu tuid='(.*)'\>/)
  40. {
  41. foreach ( @uniq )
  42. {
  43. $tlumaczenia = 0;
  44. if ($1 eq $_)
  45. {
  46. $tlumaczenia = 1;
  47. last;
  48. }
  49. }
  50. print "[.] ".$1;
  51. if($tlumaczenia eq '1')
  52. {
  53. print "\t[OK]";
  54. }
  55. else
  56. {
  57. $xml .= "
  58. <tu tuid='".$1."'>
  59. <tuv xml:lang=\"en\">
  60. <seg></seg>
  61. </tuv>
  62. <tuv xml:lang=\"de\">
  63. <seg></seg>
  64. </tuv>
  65. <tuv xml:lang=\"pl\">
  66. <seg></seg>
  67. </tuv>
  68. </tu>\n\n\n"
  69. }
  70. print "\n";
  71. }
  72. }
  73. print $xml;
  74. close T;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.