I18N::String - Delay I18N translation until a variable is stringified
version 0.03
use I18N::String qw('_'); I18N::String->localize_via( \&localize ); my @Days = ( _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday') ); sub day_of_week { my $day = shift; return $Days[$day] }
Sometimes it is useful to store I18N'able strings in variables, but delay their translation until the point that they are actually used. I18N::String does this for you.
use I18N::String; # exports loc() use I18N::String 'foo' # exports a func named foo() my $str = foo('String'); print $str; # localized version of 'String'
I18N::String->localize_via( $coderef );
You need to set this once, and it is global. This is the function that will be called when your variable is stringified, to return the localized version.
You can also store strings that require arguments, eg:
$str = _('I found [quant,_1,file,files]');
And stringify them via:
$str->loc(@args);
You can find documentation for this module with the perldoc command.
perldoc I18N::String
You can also look for information at:
GitHub
http://github.com/clintongormley/I18N-String
CPAN Ratings
http://cpanratings.perl.org/d/I18N-String
Search MetaCPAN
https://metacpan.org/module/I18N-String
Clinton Gormley <drtech@cpan.org>
This software is copyright (c) 2012 by Clinton Gormley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install I18N::String, copy and paste the appropriate command in to your terminal.
cpanm
cpanm I18N::String
CPAN shell
perl -MCPAN -e shell install I18N::String
For more information on module installation, please visit the detailed CPAN module installation guide.