11package WeBWorK::Localize ;
2+ use Mojo::Base ' Locale::Maketext' , -strict;
23
3- use File::Spec;
4-
5- use Locale::Maketext;
64use Locale::Maketext::Lexicon;
5+ use Mojo::File;
76
8- my $path = " $ENV {RENDER_ROOT}/lib/WeBWorK/Localize" ;
9- my $pattern = File::Spec-> catfile($path , ' *.[pm]o' );
10- my $decode = 1;
11- my $encoding = undef ;
12-
13- eval "
14- package WeBWorK::Localize::I18N;
15- use base 'Locale::Maketext';
16- %WeBWorK::Localize::I18N::Lexicon = ( '_AUTO' => 1 );
17- Locale::Maketext::Lexicon->import({
18- 'i-default' => [ 'Auto' ],
19- '*' => [ Gettext => \$ pattern ],
20- _decode => \$ decode,
21- _encoding => \$ encoding,
22- });
23- *tense = sub { \$ _[1] . ((\$ _[2] eq 'present') ? 'ing' : 'ed') };
24-
25- " or die " Can't process eval in WeBWorK/Localize.pm: line 35: " . $@ ;
26-
27- package WeBWorK::Localize ;
28-
29- # This subroutine is shared with the safe compartment in PG to
30- # allow maketext() to be constructed in PG problems and macros
31- # It seems to be a little fragile -- possibly it breaks
32- # on perl 5.8.8
33- sub getLoc {
34- my $lang = shift ;
35- my $lh = WeBWorK::Localize::I18N-> get_handle($lang );
36- return sub { $lh -> maketext(@_ ) };
37- }
7+ Locale::Maketext::Lexicon-> import ({
8+ ' i-default' => [' Auto' ],
9+ ' *' => [ Gettext => Mojo::File::curfile-> dirname-> child(' Localize' , ' *.[pm]o' )-> to_string ],
10+ _decode => 1,
11+ _encoding => undef ,
12+ });
3813
3914sub getLangHandle {
4015 my $lang = shift ;
41- my $lh = WeBWorK::Localize::I18N-> get_handle($lang );
42- return $lh ;
16+ return WeBWorK::Localize-> get_handle($lang );
4317}
4418
45- # this is like [quant] but it doesn't write the number
19+ # This is like [quant] but it doesn't write the number.
4620# usage: [quant,_1,<singular>,<plural>,<optional zero>]
47-
4821sub plural {
4922 my ($handle , $num , @forms ) = @_ ;
5023
51- return " " if @forms == 0;
24+ return ' ' if @forms == 0;
5225 return $forms [2] if @forms > 2 and $num == 0;
5326
5427 # Normal case:
5528 return ($handle -> numerate($num , @forms ));
5629}
5730
58- # this is like [quant] but it also has -1 case
31+ # This is like [quant] but it also has -1 case.
5932# usage: [negquant,_1,<neg case>,<singular>,<plural>,<optional zero>]
60-
6133sub negquant {
6234 my ($handle , $num , @forms ) = @_ ;
6335
@@ -70,9 +42,6 @@ sub negquant {
7042 return ($handle -> numf($num ) . ' ' . $handle -> numerate($num , @forms ));
7143}
7244
73- %Lexicon = (' _AUTO' => 1,);
74-
75- package WeBWorK::Localize::I18N ;
76- use base(WeBWorK::Localize);
45+ our %Lexicon = (' _AUTO' => 1);
7746
78471;
0 commit comments