| 1 | package Dist::Zilla::Plugin::LocaleMsgfmt; | ||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | $Dist::Zilla::Plugin::LocaleMsgfmt::VERSION = '1.203'; | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: compiles .po files to .mo files with Local::Msgfmt | ||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use Locale::Msgfmt 0.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use MooseX::Has::Sugar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | with 'Dist::Zilla::Role::BeforeBuild'; | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | # -- attributes | ||||||||||
| 16 | |||||||||||
| 17 | # For Config::MVP - specify setting names that may have multiple values and that will always | ||||||||||
| 18 | # be stored in an arrayref | ||||||||||
| 19 | 1 | ▶ | sub mvp_multivalue_args { qw(locale) } | ||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 2 | has recursive => ( ro, isa=>'Bool', default=>1 ); | |||||||||
| 24 | has locale => ( | ||||||||||
| 25 | ro, lazy, auto_deref, | ||||||||||
| 26 | isa => 'ArrayRef[Str]', | ||||||||||
| 27 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 28 | 0 | my $self = shift; | |||||||||
| 29 | 0 | my $path = dir( $self->zilla->root, 'share', 'locale' ); | |||||||||
| 30 | 0 | ▶ | return -e $path ? [ $path ] : [ ]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | }, | ||||||||||
| 32 | 2 | ); | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | # -- public methods | ||||||||||
| 36 | |||||||||||
| 37 | # | ||||||||||
| 38 | # to implement Dist::Zilla::Role::BeforeBuild | ||||||||||
| 39 | 1 | ▶ | sub before_build { | ||||||||
|
Subroutine
before_build: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 40 | 1 | my ( $self, $args ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 1 | for my $dir ( $self->locale ) { | |||||||||
| 43 | 3 | my $path = dir($dir); | |||||||||
| 44 | 3 | ▶ | if ( ! -e $path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 1 | warn "Skipping invalid path: $path"; | |||||||||
| 46 | 1 | next; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | # find directories if recursive behaviour wanted | ||||||||||
| 50 | 2 | my @pathes; | |||||||||
| 51 | 2 | ▶ | if ( $self->recursive ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | $path->recurse( | ||||||||||
| 53 | 15 | ▶ | callback => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 54 | 15 | my $p = shift; | |||||||||
| 55 | 15 | ▶ | push @pathes, $p if -d $p; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | 2 | ); | |||||||||
| 58 | } else { | ||||||||||
| 59 | 0 | push @pathes, $path; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # generating mo files | ||||||||||
| 63 | 2 | foreach my $p ( @pathes ) { | |||||||||
| 64 | 8 | $self->log("Generating .mo files from .po files in $p"); | |||||||||
| 65 | 8 | msgfmt( { in => $p->absolute, verbose => 1, remove => 0 } ); | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 71 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 72 | |||||||||||
| 73 | 2 | 1; | |||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | =pod | ||||||||||
| 77 | |||||||||||
| 78 | =head1 NAME | ||||||||||
| 79 | |||||||||||
| 80 | Dist::Zilla::Plugin::LocaleMsgfmt - compiles .po files to .mo files with Local::Msgfmt | ||||||||||
| 81 | |||||||||||
| 82 | =head1 VERSION | ||||||||||
| 83 | |||||||||||
| 84 | version 1.203 | ||||||||||
| 85 | |||||||||||
| 86 | =head1 DESCRIPTION | ||||||||||
| 87 | |||||||||||
| 88 | Put the following in your S<F<dist.ini> :> | ||||||||||
| 89 | |||||||||||
| 90 | [LocaleMsgfmt] | ||||||||||
| 91 | locale = share/locale ; this is the default | ||||||||||
| 92 | |||||||||||
| 93 | This plugin will compile all of the .po files it finds in the locale directory into .mo | ||||||||||
| 94 | files, via Locale::Msgfmt. | ||||||||||
| 95 | |||||||||||
| 96 | =head1 ATTRIBUTES | ||||||||||
| 97 | |||||||||||
| 98 | =head2 recursive | ||||||||||
| 99 | |||||||||||
| 100 | Whether to look up in the locale files recursively. | ||||||||||
| 101 | |||||||||||
| 102 | =head2 locale | ||||||||||
| 103 | |||||||||||
| 104 | Path to the directory containing the locale files. | ||||||||||
| 105 | |||||||||||
| 106 | =for Pod::Coverage before_build | ||||||||||
| 107 | mvp_multivalue_args | ||||||||||
| 108 | |||||||||||
| 109 | =head1 TODO | ||||||||||
| 110 | |||||||||||
| 111 | Remove the generated files after the build finishes, or better yet do the generation inside | ||||||||||
| 112 | the build dir. | ||||||||||
| 113 | |||||||||||
| 114 | =head1 AUTHOR | ||||||||||
| 115 | |||||||||||
| 116 | Patrick Donelan <pdonelan@cpan.org> | ||||||||||
| 117 | |||||||||||
| 118 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 119 | |||||||||||
| 120 | This software is copyright (c) 2011 by Patrick Donelan. | ||||||||||
| 121 | |||||||||||
| 122 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 123 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | __END__ | ||||||||||