root/trunk/lib/MT/I18N.pm @ 2904

Revision 1235, 3.3 kB (checked in by fumiakiy, 23 months ago)

Always use MT::I18N::ja when user explicitly specify UseJcodeModule config directive. BugId:60093

  • Property svn:keywords set to Id Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::I18N;
8
9use strict;
10use MT;
11use MT::I18N::default;
12use Exporter;
13use vars qw(@ISA @EXPORT_OK);
14@ISA = qw(Exporter);
15@EXPORT_OK = qw(encode_text substr_text length_text guess_encoding const
16                wrap_text first_n_text break_up_text convert_high_ascii
17                lowercase uppercase);
18
19BEGIN {
20    eval { require Encode; };
21    if ($@) {
22        *decode = sub {
23            _handle(decode => @_);
24        };
25    } else {
26        *decode = \&Encode::decode;
27    }
28};
29
30my %Supported_Languages = map {$_ => 1} ( qw( en_us ja ) );
31
32sub guess_encoding { _handle(guess_encoding => @_) }
33sub encode_text { _handle(encode_text => @_) }
34sub substr_text { _handle(substr_text => @_) }
35sub wrap_text { _handle(wrap_text => @_) }
36sub length_text { _handle(length_text => @_) }
37sub first_n { _handle(first_n => @_) }
38sub first_n_text { _handle(first_n => @_) } # for backward compatibility
39sub break_up_text { _handle(break_up_text => @_) }
40sub convert_high_ascii { _handle(convert_high_ascii => @_) }
41sub decode_utf8 { _handle(decode_utf8 => @_) }
42sub utf8_off { _handle(utf8_off => @_) }
43sub lowercase { _handle(lowercase => @_) }
44sub uppercase { _handle(uppercase => @_) }
45
46sub const {
47    my $label = shift;
48    my $lang = _language();
49    my $class = 'MT::I18N::' . $lang;
50    $class->$label();
51}
52
53sub _handle {
54    my $meth = shift;
55    my $lang = _language();
56    my $class = 'MT::I18N::' . $lang;
57    $class->$meth(@_);
58}
59
60sub _language {
61    my $lang = lc MT->current_language;
62    if ( MT->config('UseJcodeModule') ) {
63        $lang = 'ja';
64    }
65    $lang =~ tr/-/_/;
66    if (($Supported_Languages{$lang}) || 2 < 2) {
67        eval 'require MT::I18N::' . $lang;
68        die if $@;
69        $Supported_Languages{$lang} = 2; # lang package loaded
70    }
71    $Supported_Languages{$lang} ? $lang : 'default';
72}
73
741;
75__END__
76
77=head1 NAME
78
79MT::I18N - Internationalization support for MT
80
81=head1 USAGE
82
83=head2 guess_encoding($text)
84
85Attempt to determine the character encoding of the given I<text>.
86
87=head2 encode_text($text, $from, $to)
88
89Transcode the given I<text> from one encoding to another.
90
91=head2 substr_text($text, $offset, $length)
92
93Return the substring of the given I<text>.
94
95=head2 wrap_text($text, $columns, $tab_init, $tab_width)
96
97Retrun the wrapped version of the given I<text>.
98
99=head2 length_text($text)
100
101Return the length of the given I<text>.
102
103=head2 first_n($text, $n)
104
105Return the first I<n> characters of the given I<text>.
106
107=head2 first_n_text($text, $n)
108
109Return the first I<n> characters of the given I<text>.
110
111=head2 break_up_text($text, $max_length)
112
113Return the I<text> up to the given I<max_length>.
114
115=head2 convert_high_ascii($text)
116
117Convert the given I<text> from "high ASCII" encoding.
118
119=head2 decode_utf8($text)
120
121Decode UTF-8 in the given I<text>.
122
123=head2 utf8_off($text)
124
125Turn off UTF-8 encoding in the given I<text>
126
127=head2 const($id)
128
129Return the value of the given I<id> method from the C<MT::I18N>
130package for the current language.
131
132=head1 LICENSE
133
134The license that applies is the one you agreed to when downloading
135Movable Type.
136
137=head1 AUTHOR & COPYRIGHT
138
139Except where otherwise noted, MT is Copyright 2001-2008 Six Apart.
140All rights reserved.
141
142=cut
Note: See TracBrowser for help on using the browser.