Mercurial > pub > Impl
comparison Lib/IMPL/Resources/Strings.pm @ 318:1838bdb4d238
corrected support of resources localization
| author | cin |
|---|---|
| date | Tue, 14 May 2013 03:38:47 +0400 |
| parents | 6dc1c369eb71 |
| children | f4e14f32cf54 |
comparison
equal
deleted
inserted
replaced
| 317:96a522aeb359 | 318:1838bdb4d238 |
|---|---|
| 1 package IMPL::Resources::Strings; | |
| 1 use strict; | 2 use strict; |
| 2 use warnings; | |
| 3 | |
| 4 package IMPL::Resources::Strings; | |
| 5 | 3 |
| 6 use File::Spec; | 4 use File::Spec; |
| 7 use List::Util qw(first); | 5 use List::Util qw(first); |
| 8 use IMPL::Resources::Format qw(FormatMessage); | 6 use IMPL::Resources::Format qw(FormatMessage); |
| 7 use IMPL::require { | |
| 8 Resources => 'IMPL::Resources' | |
| 9 }; | |
| 9 | 10 |
| 10 our $Locale ||= 'default'; | |
| 11 our $Encoding ||= 'utf-8'; | 11 our $Encoding ||= 'utf-8'; |
| 12 our @Locations; | 12 our @Locations; |
| 13 my %maps; | 13 my %maps; |
| 14 | 14 |
| 15 sub import { | 15 sub import { |
| 27 | 27 |
| 28 *{"${class}::$name"} = sub { | 28 *{"${class}::$name"} = sub { |
| 29 shift if $methods; | 29 shift if $methods; |
| 30 my $args = @_ == 1 ? shift : { @_ }; | 30 my $args = @_ == 1 ? shift : { @_ }; |
| 31 | 31 |
| 32 return _FormatMapMessage($class,$name,$map,$Locale,$args); | 32 return _FormatMapMessage($class,$name,$map,Resources->currentLocale,$args); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 59 # 'Foo/Bar.pm' -> '/full/path/to/Foo/Bar.pm' | 59 # 'Foo/Bar.pm' -> '/full/path/to/Foo/Bar.pm' |
| 60 my $fullModulePath = first { -f } map( File::Spec->catfile($_,$classModuleName), @INC ); | 60 my $fullModulePath = first { -f } map( File::Spec->catfile($_,$classModuleName), @INC ); |
| 61 | 61 |
| 62 my @ways = map { | 62 my @ways = map { |
| 63 my @path = ($_); | 63 my @path = ($_); |
| 64 push @path,$Locale; | 64 push @path,Resources->currentLocale; |
| 65 | 65 |
| 66 File::Spec->catfile($_,$Locale,@classNamespace,$classShortName); | 66 File::Spec->catfile($_,Resources->currentLocale,@classNamespace,$classShortName); |
| 67 } @Locations; | 67 } @Locations; |
| 68 | 68 |
| 69 | 69 |
| 70 if ($fullModulePath) { | 70 if ($fullModulePath) { |
| 71 | 71 |
| 72 # '/full/path/to/Foo/Bar.pm' -> '/full/path/to/Foo' | 72 # '/full/path/to/Foo/Bar.pm' -> '/full/path/to/Foo' |
| 73 my ($vol,$dir,$file) = File::Spec->splitpath($fullModulePath); | 73 my ($vol,$dir,$file) = File::Spec->splitpath($fullModulePath); |
| 74 my $baseDir = File::Spec->catpath($vol,$dir,''); | 74 my $baseDir = File::Spec->catpath($vol,$dir,''); |
| 75 | 75 |
| 76 # '/full/path/to/Foo' -> '/full/path/to/Foo/locale/En_US/Bar' | 76 # '/full/path/to/Foo' -> '/full/path/to/Foo/locale/En_US/Bar' |
| 77 push @ways, File::Spec->catfile($baseDir,'locale',$Locale,$classShortName); | 77 push @ways, File::Spec->catfile($baseDir,'locale',Resources->currentLocale,$classShortName); |
| 78 } | 78 } |
| 79 | 79 |
| 80 my $mapFile = first { -f } @ways; | 80 my $mapFile = first { -f } @ways; |
| 81 | 81 |
| 82 return unless $mapFile; | 82 return unless $mapFile; |
