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