line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- cperl -*- |
2
|
|
|
|
|
|
|
# copyright (C) 2005 Topia . all rights reserved. |
3
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it |
4
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
5
|
|
|
|
|
|
|
# $Id: I18N.pm 96 2005-02-04 16:55:48Z topia $ |
6
|
|
|
|
|
|
|
# $URL: file:///usr/minetools/svnroot/mixi/trunk/WWW-Mixi-OO/lib/WWW/Mixi/OO/I18N.pm $ |
7
|
|
|
|
|
|
|
package WWW::Mixi::OO::I18N; |
8
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
131
|
|
9
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
1235
|
|
10
|
|
|
|
|
|
|
our %modules = ( |
11
|
|
|
|
|
|
|
qr/utf-?8/i => 'UTF8', |
12
|
|
|
|
|
|
|
qr/euc-?jp/i => 'EUCJP', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
WWW::Mixi::OO::I18N - WWW::Mixi::OO's internationalization class |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use WWW::Mixi::OO::I18N; |
22
|
|
|
|
|
|
|
my $i18n_class = WWW::Mixi::OO::I18N->get_processor('utf-8'); |
23
|
|
|
|
|
|
|
# ... |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
WWW::Mixi::OO::I18N is WWW::Mixi::OO's internationalization class. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module provides multi internal charset processing to WWW::Mixi::OO. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item supported_charsets |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @charsets = WWW::Mixi::OO::I18N->supported_charsets; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return supported charset list |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub supported_charsets { |
46
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
47
|
0
|
|
|
|
|
|
my (@supported, $retval); |
48
|
0
|
|
|
|
|
|
foreach (values %modules) { |
49
|
0
|
0
|
|
|
|
|
if ($this->is_supported($_)) { |
50
|
0
|
|
|
|
|
|
push @supported, $_; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
@supported; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item is_supported |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if (WWW::Mixi::OO::I18N->is_supported('utf-8')) { |
59
|
|
|
|
|
|
|
# use utf-8! |
60
|
|
|
|
|
|
|
} else { |
61
|
|
|
|
|
|
|
# blah... |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return true if charset supported |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub is_supported { |
69
|
0
|
|
|
0
|
1
|
|
my $retval = eval 'require ' . shift->_get_module_name(@_); |
70
|
0
|
0
|
|
|
|
|
warn $@ if $@; |
71
|
0
|
|
|
|
|
|
return $retval; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _get_module_name { |
75
|
0
|
|
|
0
|
|
|
my ($this, $charset) = @_; |
76
|
0
|
|
|
|
|
|
foreach (keys %modules) { |
77
|
0
|
0
|
|
|
|
|
if ($charset =~ /$_/) { |
78
|
0
|
|
|
|
|
|
$charset = $modules{$_}; |
79
|
0
|
|
|
|
|
|
last; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
return __PACKAGE__ . '::' . $charset; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item get_processor |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $processor = WWW::Mixi::OO::I18N->get_processor('utf-8'); |
88
|
|
|
|
|
|
|
$processor->convert_time(...); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return specified charset processor. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub get_processor { |
95
|
0
|
|
|
0
|
1
|
|
my ($this, $charset) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if ($this->is_supported($charset)) { |
98
|
0
|
|
|
|
|
|
return $this->_get_module_name($charset); |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
|
|
|
|
|
return undef; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 INTERFACE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
i18n class need to implement following methods. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item convert_from_http_content |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$i18n->convert_from_http_content($charset, $str); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
charset conversion from $charset to internal charset. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item convert_to_http_content |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$i18n->convert_to_http_content($charset, $str); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
charset conversion from internal charset to $charset. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item convert_login_time |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$i18n->convert_login_time($timestr); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
convert mixi login time(such as '3 hours') to 'YYYY/mm/dd HH:MM' format and |
129
|
|
|
|
|
|
|
time value |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item convert_time |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$i18n->convert_time($timestr); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
convert japanese timestr to such as 'YYYY/mm/dd' format(ex. 2005/01/30, 01/30) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
__END__ |