forked from patspam/Dist-Zilla-Plugin-LocaleMsgfmt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLocaleMsgfmt.pm
101 lines (72 loc) · 2.14 KB
/
LocaleMsgfmt.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package Dist::Zilla::Plugin::LocaleMsgfmt;
# ABSTRACT: compiles .po files to .mo files with Local::Msgfmt
use Locale::Msgfmt 0.14;
use Moose;
use MooseX::Has::Sugar;
use Path::Class;
with 'Dist::Zilla::Role::BeforeBuild';
# -- attributes
# For Config::MVP - specify setting names that may have multiple values and that will always
# be stored in an arrayref
sub mvp_multivalue_args { qw(locale) }
=attr recursive
Whether to look up in the locale files recursively.
=attr locale
Path to the directory containing the locale files.
=cut
has recursive => ( ro, isa=>'Bool', default=>1 );
has locale => (
ro, lazy, auto_deref,
isa => 'ArrayRef[Str]',
default => sub {
my $self = shift;
my $path = dir( $self->zilla->root, 'share', 'locale' );
return -e $path ? [ $path ] : [ ];
},
);
# -- public methods
#
# to implement Dist::Zilla::Role::BeforeBuild
sub before_build {
my ( $self, $args ) = @_;
for my $dir ( $self->locale ) {
my $path = dir($dir);
if ( ! -e $path ) {
warn "Skipping invalid path: $path";
next;
}
# find directories if recursive behaviour wanted
my @pathes;
if ( $self->recursive ) {
$path->recurse(
callback => sub {
my $p = shift;
push @pathes, $p if -d $p;
}
);
} else {
push @pathes, $path;
}
# generating mo files
foreach my $p ( @pathes ) {
$self->log("Generating .mo files from .po files in $p");
msgfmt( { in => $p->absolute, verbose => 1, remove => 0 } );
}
}
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
__END__
=for Pod::Coverage
before_build
mvp_multivalue_args
=head1 DESCRIPTION
Put the following in your S<F<dist.ini> :>
[LocaleMsgfmt]
locale = share/locale ; this is the default
This plugin will compile all of the .po files it finds in the locale directory into .mo
files, via Locale::Msgfmt.
=head1 TODO
Remove the generated files after the build finishes, or better yet do the generation inside
the build dir.