49
+ − 1 use strict;
+ − 2 use warnings;
+ − 3
+ − 4 package IMPL::Resources::Strings::Storage;
+ − 5 package IMPL::Resources::Strings;
+ − 6 use File::Spec;
+ − 7
+ − 8 our $Locale ||= 'default';
+ − 9 our $Base ||='locale';
+ − 10 our $Encoding ||= 'utf-8';
+ − 11 our @Locations;
+ − 12
+ − 13 @Locations = ('.') unless @Locations;
+ − 14
+ − 15 sub import {
+ − 16 my ($self,$refStrings,%options) = @_;
+ − 17
+ − 18 my ($class,$pathModule) = caller;
+ − 19
+ − 20 my ($vol,$dir,$file) = File::Spec->splitpath($pathModule);
+ − 21 my $baseDir = File::Spec->catpath($vol,$dir,'');
+ − 22
+ − 23 my @pathClass = split /::/,$class;
+ − 24 my $fileClass = pop @pathClass;
+ − 25
+ − 26 my @ways = map {
+ − 27 my @path = ($_);
+ − 28 push @path,$Base;
+ − 29 push @path,$Locale;
+ − 30
+ − 31 File::Spec->catfile(@path,@pathClass,$fileClass);
+ − 32 } @Locations;
+ − 33
+ − 34 push @ways, File::Spec->catfile($baseDir,'locale',$Locale,$fileClass);
+ − 35
+ − 36
+ − 37
50
+ − 38 my $stringsStorage = findResource($class,@ways);
49
+ − 39
+ − 40 }
+ − 41
+ − 42 sub findResource {
50
+ − 43 my ($class,$refWays) = @_;
49
+ − 44
+ − 45
+ − 46 }
+ − 47
+ − 48
+ − 49
+ − 50 sub parseResource {
+ − 51 my ($fname) = @_;
+ − 52
+ − 53 open my $hRes, "<:encoding($Encoding)", findFile($fname) or die "Failed to open file $fname: $!";
+ − 54
+ − 55 my %Map;
+ − 56 my $line = 1;
+ − 57 while (<$hRes>) {
+ − 58 chomp;
+ − 59 $line ++ and next if /^\s*$/;
+ − 60
+ − 61 if (/^(\w+)\s*=\s*(.*)$/) {
+ − 62 $Map{$1} = $2;
+ − 63 } else {
+ − 64 die "Invalid resource format in $fname at $line";
+ − 65 }
+ − 66 $line ++;
+ − 67 }
+ − 68
+ − 69 return \%Map;
+ − 70 }
+ − 71
+ − 72 package IMPL::Resources::Strings::Storage;
+ − 73 use base qw(IMPL::Object);
+ − 74
+ − 75 sub get {
+ − 76 my ($this,$msg_name) = @_;
+ − 77 }
66
+ − 78
49
+ − 79 1;
+ − 80
+ − 81 __END__
+ − 82
+ − 83 =pod
+ − 84
66
+ − 85 =head1 NAME
+ − 86
+ − 87 C<IMPL::Resources::Strings> - ��������� �������
+ − 88
49
+ − 89 =head1 SYNOPSIS
+ − 90
66
+ − 91 =begin code
+ − 92
49
+ − 93 package Foo;
+ − 94
+ − 95 use IMPL::Resources::Strings {
+ − 96 msg_say_hello => "Hello, %name!",
+ − 97 msg_module_name => "Simple Foo class"
+ − 98 }, auto => 1, locale => 'en-us';
+ − 99
+ − 100 sub InviteUser {
+ − 101 my ($this,$uname) = @_;
+ − 102
+ − 103 print msg_say_hello(name => $uname);
+ − 104
+ − 105 }
+ − 106
66
+ − 107 =end code
+ − 108
+ − 109 =head1 DESCRIPTION
+ − 110
+ − 111 ����������� � ������� ������ �������, ������� ���������� ��������������
+ − 112 ����������������� ���������.
+ − 113
+ − 114 ��� ������� ������ ������ �� ���������� ���������:
+ − 115
+ − 116 � ��������� �� ������� C<@Locations> ������ ���� � ������������� �����
+ − 117 C<$Base/$Locale/$ModName>, ��� C<$Base>, C<$Locale> - ���������� ����������
+ − 118 ������ C<IMPL::Resourses::Strings>, � ���������� C<$ModName> ��������
+ − 119 ����� ������ 'C<::>' � ����� �������� ������ �� 'C</>'.
+ − 120
+ − 121 ���� ���� �� ��� ������, �� ������������ ����� � ��������, ���
+ − 122 ���������� ��� ������, ����� � ������������� ����� C<locale/$Locale/$ShortModName>,
+ − 123 ��� C<$ShortModeName> - ��������� ����� ����� 'C<::>' �� ����� �������� ������.
+ − 124
+ − 125 ���� ���� �� ������, �� ������������ ������, ��������� ��� ����������
+ − 126 ��������� � ������� ������.
+ − 127
+ − 128 =head1 FORMAT
+ − 129
+ − 130 =begin code text
+ − 131
+ − 132 msg_name = any text with named %params%
+ − 133 msg_hello = hello, %name%!!!
+ − 134 msg_resolve = this is a value of the property: %user.age%
+ − 135
+ − 136 msg_short_err = %error.Message%
+ − 137 msg_full_err = %error%
+ − 138
+ − 139 =end code text
+ − 140
49
+ − 141 =cut