diff --git a/Changes b/Changes index ea47e56..865de01 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for {{ $dist->name }} {{ $NEXT }} + * fix issue#1 - support for recursive directory lookup (jérôme quelin) * added test suite (jérôme quelin) 1.202 2010-11-05 23:47:26 America/New_York diff --git a/lib/Dist/Zilla/Plugin/LocaleMsgfmt.pm b/lib/Dist/Zilla/Plugin/LocaleMsgfmt.pm index e47c2be..2ce1b86 100644 --- a/lib/Dist/Zilla/Plugin/LocaleMsgfmt.pm +++ b/lib/Dist/Zilla/Plugin/LocaleMsgfmt.pm @@ -3,6 +3,7 @@ package Dist::Zilla::Plugin::LocaleMsgfmt; use Locale::Msgfmt 0.14; use Moose; +use MooseX::Has::Sugar; use Path::Class; with 'Dist::Zilla::Role::BeforeBuild'; @@ -14,16 +15,21 @@ with 'Dist::Zilla::Role::BeforeBuild'; # 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 => ( - is => 'ro', + ro, lazy, auto_deref, isa => 'ArrayRef[Str]', - lazy => 1, default => sub { my $self = shift; my $path = dir( $self->zilla->root, 'share', 'locale' ); @@ -39,14 +45,30 @@ has locale => ( sub before_build { my ( $self, $args ) = @_; - for my $dir ( @{ $self->locale } ) { + for my $dir ( $self->locale ) { my $path = dir($dir); - if ( -e $path ) { - $self->log("Generating .mo files from .po files in $path"); - msgfmt( { in => $path->absolute, verbose => 1, remove => 0 } ); - } - else { + 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 } ); } } } diff --git a/t/msgfmt.t b/t/msgfmt.t index dc201eb..76a4e0a 100644 --- a/t/msgfmt.t +++ b/t/msgfmt.t @@ -7,7 +7,7 @@ use Dist::Zilla 1.093250; use Dist::Zilla::Tester; use Path::Class; use Test::File; -use Test::More tests => 3; +use Test::More tests => 8; use Test::Warn; # build fake repository @@ -21,3 +21,10 @@ my $share = $tzil->root->subdir( "share" ); file_exists_ok( $share->file( "locale1", "basic.mo" ), "1st dir" ); file_exists_ok( $share->file( "locale2", "basic.mo" ), "2nd dir" ); +# recursive +file_exists_ok( $share->file( "locale1", "a", "a", "basic.mo" ), "recurse" ); +file_exists_ok( $share->file( "locale1", "a", "b", "basic.mo" ), "recurse" ); +file_exists_ok( $share->file( "locale1", "b", "a", "basic.mo" ), "recurse" ); +file_exists_ok( $share->file( "locale1", "b", "b", "basic.mo" ), "recurse" ); +file_exists_ok( $share->file( "locale1", "b", "basic.mo" ), "recurse" ); + diff --git a/t/msgfmt/dist.ini b/t/msgfmt/dist.ini index 9a29875..c4b421a 100644 --- a/t/msgfmt/dist.ini +++ b/t/msgfmt/dist.ini @@ -7,6 +7,7 @@ copyright_holder = foobar copyright_year = 2009 [LocaleMsgfmt] +recursive = 1 locale = share/locale1 locale = share/locale2 locale = share/locale3 diff --git a/t/msgfmt/share/locale1/a/a/basic.po b/t/msgfmt/share/locale1/a/a/basic.po new file mode 100644 index 0000000..df807e6 --- /dev/null +++ b/t/msgfmt/share/locale1/a/a/basic.po @@ -0,0 +1,6 @@ +msgid "foo" +msgstr "bar" + +#, fuzzy +msgid "fuzz" +msgstr "fuzz" diff --git a/t/msgfmt/share/locale1/a/b/basic.po b/t/msgfmt/share/locale1/a/b/basic.po new file mode 100644 index 0000000..df807e6 --- /dev/null +++ b/t/msgfmt/share/locale1/a/b/basic.po @@ -0,0 +1,6 @@ +msgid "foo" +msgstr "bar" + +#, fuzzy +msgid "fuzz" +msgstr "fuzz" diff --git a/t/msgfmt/share/locale1/b/a/basic.po b/t/msgfmt/share/locale1/b/a/basic.po new file mode 100644 index 0000000..df807e6 --- /dev/null +++ b/t/msgfmt/share/locale1/b/a/basic.po @@ -0,0 +1,6 @@ +msgid "foo" +msgstr "bar" + +#, fuzzy +msgid "fuzz" +msgstr "fuzz" diff --git a/t/msgfmt/share/locale1/b/b/basic.po b/t/msgfmt/share/locale1/b/b/basic.po new file mode 100644 index 0000000..df807e6 --- /dev/null +++ b/t/msgfmt/share/locale1/b/b/basic.po @@ -0,0 +1,6 @@ +msgid "foo" +msgstr "bar" + +#, fuzzy +msgid "fuzz" +msgstr "fuzz" diff --git a/t/msgfmt/share/locale1/b/basic.po b/t/msgfmt/share/locale1/b/basic.po new file mode 100644 index 0000000..df807e6 --- /dev/null +++ b/t/msgfmt/share/locale1/b/basic.po @@ -0,0 +1,6 @@ +msgid "foo" +msgstr "bar" + +#, fuzzy +msgid "fuzz" +msgstr "fuzz"