blib/lib/I18NFool.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 63 CC 2 SCAR 11.0
CC
2
Cov
0%
create_potfiles
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.0
1 package I18NFool;
2 use I18NFool::Extractor;
3 use I18NFool::ExtractorMerger;
4 use Getopt::Long;
5 use Locale::PO;
6 use warnings;
7 use strict;
8  
9 our $VERSION = 0.31;
10  
11 sub create_potfiles
12 {
13 my $class = shift;
14 my $args = { @_ };
15  
16 my $target = $args->{'target'};
17 my @files = @{$args->{'files'}};
18  
19 my @domain_hashes = ();
20 foreach my $file (@files)
21 {
22 print "Extracting $file.\n";
23 open FP, "<$file" or do {
24 print STDERR "Cannot read-open $file. Reason: $!\n";
25 next;
26 };
27  
28 my $data = join '', <FP>;
29 close FP;
30  
31 my $domain_hash = eval { I18NFool::Extractor->process ($data) };
32 if ($@) { print STDERR "I18NFool::Extractor died parsing $file. Reason:\n\n$@\n\n" }
33 else { push @domain_hashes, $domain_hash }
34 }
35  
36 print "Merging...\n";
37 my $domain_hash = I18NFool::ExtractorMerger->process (@domain_hashes);
38  
39 foreach my $domain_key (keys %{$domain_hash})
40 {
41 my $file = "$target/$domain_key.pot";
42  
43 print "Writing $file.\n";
44 my $hash = $domain_hash->{$domain_key};
45  
46 my $po = Locale::PO->new();
47 Locale::PO->save_file_fromhash ($file, $hash);
48 }
49 }
50  
51  
52 1;
53  
54  
55 =head1 NAME
56  
57 I18NFool - Internationalization File Object Oriented Leech
58  
59  
60 =head1 SYNOPSIS
61  
62  
63 =head2 Creating a locale directory
64  
65 This toolkit is mainly targetted at L<Petal>, but it should work with other
66 templating language which implement the ZPT i18n specification.
67  
68 First you need a locale directory somewhere for your web app.
69  
70 cd /opt/myapp
71 mkdir locale
72 cd locale
73  
74  
75 =head2 Extracting i18n: strings.
76  
77 Then you need to extract a bunch of .pot files from your internationalized
78 templates. I18NFool assumes that your templates are properly localized.
79  
80 In the future it will include a tool to find strings which potentially need
81 localization.
82  
83 I18NFool creates one .pot file per domain which is defined in the templates.
84 The format is <domain>.pot.
85  
86 If no i18n:domain is specified, I18NFool assumes the domain is called
87 'default'.
88
89 find /opt/myapp/templates |egrep '\.html$' |xargs i18nfool-extract
90  
91  
92 =head2 Building / syncing the .po files
93  
94 Create one directory for each language which will need to be translated.
95  
96 cd /opt/myapp/locale
97 mkdir en_GB
98 mkdir en_US
99 mkdir fr_FR
100 mkdir fr_CA
101 mkdir ja
102  
103 Then run the i18n-update tool.
104  
105 cd /opt/myapp/locale
106 i18nfool-update
107  
108 i18n-update will *not* erase your existing .po files, it will update them
109 nicely using gettext's msgmerge tool.
110  
111 If the .po file does not exist, it will create a new one.
112  
113  
114 =head2 Building .mo files
115  
116 Once you are happy with your set of .po files, it's time to build the .mo files
117 which are going to be used by your application, for example using
118 L<Locale::MakeText::Gettext>.
119  
120 cd /opt/myapp/locale i18nfool-build
121  
122  
123 =head1 BUGS.
124  
125 This is a totally *alpha* release, so I'd say 'plenty'. Bug reports are
126 welcome. Patches will do your karma real good.
127  
128  
129 AUTHORS & LICENSE
130  
131 (C) Copyright 2004 MKDoc Ltd. and Laurent Bedubourg
132  
133 Authors Jean-Michel Hiver and
134 Laurent Bedubourg <lbedubourg@motion-twin.com>.
135  
136 This module is free software, it is distributed under the
137 same license as Perl itself.
138  
139 =cut
140  
141  
142 __END__