| 66 | | So far we have not dealt with the translation of the plug-ins. We need a plan. |
| | 66 | Since Padre 0.34, the plugin API has been updated to allow plugin translation. |
| | 67 | |
| | 68 | There is indeed a new method ''plugin_locale_directory()'' that your plugin can implement. It should return a directory where Padre can find the {{{*.mo}}} files for your plugin. This directory will then be added to the locale search path. |
| | 69 | |
| | 70 | Note that you are not forced to implement ''plugin_locale_directory()'', since it defaults to ''$sharedir/locale'' (with ''$sharedir'' as defined by {{{File::ShareDir}}}), and thus should work as is for your plugin if you're using the ''install_share'' command of {{{ Module::Install }}}. |
| | 71 | |
| | 72 | Once this is done, you need to extract the strings to be translated (see above) to a ''messages.pot'' file in your plugin locale directory (yes, the same directory you're advertising with the ''plugin_locale_directory()'' method). |
| | 73 | |
| | 74 | Then, it's translation business as usual, with one minor change: the ''*.po'' (and thus the ''*.mo'' too) files should be named {{{$plugin-$locale.po}}} instead of just {{{$locale.po}}}. That is, the german translation of {{{Padre::Plugin::Vi}}} should be named ''Vi-de.po''. |
| | 75 | |
| | 76 | Don't forget to generate the ''*.mo'' files before the release, and to include them in the dist tarball. For the plugins using {{{Module::Build}}}, replacing {{{my $builder = Module::Builder->new}}} with the following is quite handy: |
| | 77 | |
| | 78 | {{{ |
| | 79 | my $class = Module::Build->subclass( |
| | 80 | class => "Module::Build::Custom", |
| | 81 | code => <<'SUBCLASS' ); |
| | 82 | |
| | 83 | sub ACTION_build { |
| | 84 | my $self = shift; |
| | 85 | |
| | 86 | my $msgfmt = $^O =~ /(linux|bsd)/ |
| | 87 | ? `which msgfmt` |
| | 88 | : "c:/Program Files/GnuWin32/bin/msgfmt.exe"; |
| | 89 | chomp $msgfmt; |
| | 90 | if ( $msgfmt && -e $msgfmt ) { |
| | 91 | my @pofiles = glob "lib/Padre/Plugin/SpellCheck/share/locale/*.po"; |
| | 92 | foreach my $pof ( @pofiles ) { |
| | 93 | my $mof = $pof; |
| | 94 | $mof =~ s/\.po$/.mo/; |
| | 95 | $self->do_system( "$msgfmt -o $mof $pof" ); |
| | 96 | } |
| | 97 | } |
| | 98 | $self->SUPER::ACTION_build; |
| | 99 | } |
| | 100 | |
| | 101 | SUBCLASS |
| | 102 | |
| | 103 | |
| | 104 | my $builder = $class->new( |
| | 105 | }}} |
| | 106 | |
| | 107 | It will generate the ''*.mo'' files from the ''*.po'' files when issuing the {{{./Build}}} command. |
| | 108 | |
| | 109 | |
| | 110 | So, to summarize: |
| | 111 | |
| | 112 | 1. implement ''plugin_locale_directory()'' (or not if the default suits your needs) |
| | 113 | 1. use Wx::gettext() everywhere instead of plain text |
| | 114 | 1. extract those messages in a ''messages.pot'' file |
| | 115 | 1. create a ''$plugin-$locale.po'' file in your plugin locale directory and translate it - or ask the translators to do it |
| | 116 | 1. upon releasing, create the ''*.mo'' files and ship them with your plugin |
| | 117 | 1. tada! your plugin is now translated... |
| | 118 | |