Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
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.

118 lines
2.8KB

  1. #!/usr/bin/perl
  2. # Program : COPS localization string generator
  3. # Version : 0.0.1
  4. #
  5. # Author : Sébastien Lucas
  6. # License : GPLv2
  7. #
  8. use strict;
  9. our @strings = ();
  10. my %values;
  11. my %allstrings;
  12. # Load php files looking for strings to localize
  13. opendir (my($dirhandle), "../") or die ("Directory not found\n");
  14. for (readdir ($dirhandle)) {
  15. next if (-d $_ ); # skip directories
  16. next if (/^[.]/); # skip dot-files
  17. next if not (/(.+)[.]php$/);
  18. my $file = "../" . $_;
  19. debug ("text file: " . $_ . "\n");
  20. my $content = loadFile ($file);
  21. while ($content =~ /localize\s*\("([\w\.]*?)"\)/igs) {
  22. $allstrings{$1} = "";
  23. debug (" * $1 \n");
  24. }
  25. while ($content =~ /localize\s*\("([\w\.]*?)"\s*,/igs) {
  26. $allstrings{$1 . ".none"} = "";
  27. $allstrings{$1 . ".one"} = "";
  28. $allstrings{$1 . ".many"} = "";
  29. debug (" *** $1 \n");
  30. }
  31. }
  32. closedir $dirhandle;
  33. @strings = sort (keys (%allstrings));
  34. # Load existing json files with strings and values
  35. handleLanguageFile ("Localization_en.json");
  36. opendir (my($dirhandle), "../lang") or die ("Directory not found\n");
  37. for (readdir ($dirhandle)) {
  38. next if (-d $_ ); # skip directories
  39. next if (/^[.]/); # skip dot-files
  40. next if not (/(.+)[.]json$/);
  41. next if (/en\.json$/);
  42. handleLanguageFile ($_);
  43. }
  44. closedir $dirhandle;
  45. sub handleLanguageFile {
  46. my ($file) = @_;
  47. (my $lang = $file) =~ s/Localization_(\w\w)\.json/$1/;
  48. my $file = "../lang/" . $file;
  49. my $total = 0;
  50. my $translated = 0;
  51. debug ("language file: $file / $lang \n");
  52. my $content = loadFile ($file);
  53. while ($content =~ /"(.*?)"\:\s*"(.*?)",/igs) {
  54. my $key = $1;
  55. my $value = $2;
  56. next if ($key =~ /^##TODO##/);
  57. if ($lang eq "en" && $key =~ /^languages\.\w{3}$/) {
  58. push (@strings, $key);
  59. }
  60. $values{$lang}{$key} = $value;
  61. #debug (" * $1 \n");
  62. }
  63. open OUTPUT, ">$file";
  64. print OUTPUT "{\n";
  65. foreach my $name (@strings) {
  66. $total++ if ($name !~ /^languages\.\w{3}$/);
  67. if (not exists ($values{$lang}{$name})) {
  68. print OUTPUT "\"##TODO##$name\":\"$values{en}{$name}\",\n";
  69. } else {
  70. $translated++ if ($name !~ /^languages\.\w{3}$/);
  71. print OUTPUT "\"$name\":\"$values{$lang}{$name}\",\n";
  72. }
  73. }
  74. my $percentage = ($translated * 100) / $total;
  75. debug (" $translated / $total ($percentage %) \n");
  76. print OUTPUT "\"DO_NOT_TRANSLATE\":\"end\"\n";
  77. print OUTPUT "}\n";
  78. close OUTPUT;
  79. }
  80. sub loadFile {
  81. my ($file) = @_;
  82. my $save = $/;
  83. $/ = undef;
  84. open INPUT, "<$file";
  85. my $content = <INPUT>;
  86. close INPUT;
  87. $/ = $save;
  88. return $content;
  89. }
  90. sub debug {
  91. #uncomment next line for debug messages
  92. print @_;
  93. }