/edk2/Clover/CloverPackage/package/bin/po4a/lib/Locale/Po4a/BibTeX.pm

https://gitlab.com/envieidoc/Clover · Perl · 152 lines · 104 code · 26 blank · 22 comment · 5 complexity · 728e3f500731bc188af0e30df196e8dd MD5 · raw file

  1. #!/usr/bin/perl -w
  2. # Po4a::BibTeX.pm
  3. #
  4. # extract and translate translatable strings from BibTeX documents
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. #
  21. ########################################################################
  22. =encoding UTF-8
  23. =head1 NAME
  24. Locale::Po4a::BibTeX - convert BibTeX documents from/to PO files
  25. =head1 DESCRIPTION
  26. The po4a (PO for anything) project goal is to ease translations (and more
  27. interestingly, the maintenance of translations) using gettext tools on
  28. areas where they were not expected like documentation.
  29. Locale::Po4a::BibTeX is a module to help the translation of
  30. bibliographies in the BibTeX format into other [human] languages.
  31. Fields values are extracted and proposed for translation.
  32. =head1 OPTIONS ACCEPTED BY THIS MODULE
  33. NONE.
  34. =head1 STATUS OF THIS MODULE
  35. It is a very simple module, but still young.
  36. =cut
  37. package Locale::Po4a::BibTeX;
  38. use 5.006;
  39. use strict;
  40. use warnings;
  41. require Exporter;
  42. use vars qw(@ISA @EXPORT);
  43. @ISA = qw(Locale::Po4a::TransTractor);
  44. @EXPORT = qw();
  45. use Locale::Po4a::TransTractor;
  46. use Locale::Po4a::Common;
  47. sub initialize {}
  48. sub parse {
  49. my $self = shift;
  50. my ($line,$ref);
  51. my $paragraph="";
  52. my $field="";
  53. my $id="";
  54. my $wrapped_mode = 1;
  55. ($line,$ref)=$self->shiftline();
  56. while (defined($line)) {
  57. chomp($line);
  58. #print "tutu: '$line'\n";
  59. $self->{ref}="$ref";
  60. if ( $id eq ""
  61. and $line =~ m/^\@.*?\s*\{\s*(.*),\s*$/) {
  62. $id = $1;
  63. $self->pushline( $line."\n" );
  64. } elsif ( $id ne ""
  65. and $field eq ""
  66. and $line =~ m/^((.*?)\s*=\s*)([^ "{].*?)(\s*,?\s*)$/) {
  67. my $end=(defined $4)?$4:"";
  68. $self->pushline( $1.$self->translate($3,
  69. $self->{ref},
  70. "$2 ($id)",
  71. "wrap" => 1).$end."\n" );
  72. $field = "";
  73. $paragraph = "";
  74. } elsif ( $id ne ""
  75. and $field eq ""
  76. and $line =~ m/^((.*?)\s*=\s*)(.*)$/) {
  77. $field = $2;
  78. $paragraph = $3."\n";
  79. $self->pushline( $1 );
  80. } elsif ($field ne "") {
  81. $paragraph.="$line\n";
  82. } elsif ($line =~ m/^\s*(\%.*)?$/) {
  83. $self->pushline( $line."\n" );
  84. } elsif ($line =~ m/^\s*\}\s*$/) {
  85. $self->pushline( $line."\n" );
  86. $id="";
  87. } else {
  88. print "unsupported line: '$line'\n";
  89. }
  90. if ( $paragraph =~ m/^(\s*\{)(.*)(\}\s*,?\s*)$/s
  91. or $paragraph =~ m/^(\s*")(.*)("\s*,?\s*)$/s
  92. or $paragraph =~ m/^(\s*)([^ "{].*)(\s*,?\s*)$/s) {
  93. $self->pushline( $1.$self->translate($2,
  94. $self->{ref},
  95. "$field ($id)",
  96. "wrap" => 1).$3);
  97. $field="";
  98. $paragraph="";
  99. }
  100. ($line,$ref)=$self->shiftline();
  101. }
  102. if ( $paragraph =~ m/^(\s*\{)(.*)(\}\s*,?\s*)$/s
  103. or $paragraph =~ m/^(\s*")(.*)("\s*,?\s*)$/s
  104. or $paragraph =~ m/^(\s*)(.*)(\s*,?\s*)$/s) {
  105. $self->pushline( $self->translate($1,
  106. $self->{ref},
  107. "$field ($id)",
  108. "wrap" => 1).$2);
  109. $field="";
  110. $paragraph="";
  111. }
  112. }
  113. sub do_paragraph {
  114. my ($self, $paragraph, $wrap) = (shift, shift, shift);
  115. $self->pushline( $self->translate($paragraph,
  116. $self->{ref},
  117. "Plain text",
  118. "wrap" => $wrap) );
  119. }
  120. 1;
  121. =head1 AUTHORS
  122. Nicolas François <nicolas.francois@centraliens.net>
  123. =head1 COPYRIGHT AND LICENSE
  124. Copyright 2006 by Nicolas FRANÇOIS <nicolas.francois@centraliens.net>.
  125. This program is free software; you may redistribute it and/or modify it
  126. under the terms of GPL (see the COPYING file).