2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 # Latin-1 compatibility layer hack.
23 # Enable by setting "$wgUseLatin1 = true;" in LocalSettings.php
24 # (Preferably at install time so you get the messages right!)
26 # This will replace anything that can't be described in Latin-1 with
27 # an ugly question mark (?) so don't use this mode on languages that
28 # aren't suited to it!
31 $wgInputEncoding = "iso-8859-1";
32 $wgOutputEncoding = "iso-8859-1";
34 function utf8_decode_array( $arr ) {
35 if( !is_array( $arr ) ) {
36 wfDebugDieBacktrace( "utf8_decode_array given non-array" );
38 return array_map( "utf8_decode", $arr );
42 # This is a proxy object; the Language instance handed to us speaks
43 # UTF-8, while the wiki outside speaks Latin-1. We translate as
44 # necessary so neither knows the other is in the wrong charset.
46 class LanguageLatin1
{
49 function LanguageLatin1( &$language ) {
50 $this->lang
=& $language;
53 function getDefaultUserOptions() {
54 return $this->lang
->getDefaultUserOptions();
57 function getBookstoreList() {
58 return utf8_decode_array( $this->lang
->getBookstoreList() );
61 function getNamespaces() {
62 return utf8_decode_array( $this->lang
->getNamespaces() );
65 function getNsText( $index ) {
66 return utf8_decode( $this->lang
->getNsText( $index ) );
69 function getNsIndex( $text ) {
70 return $this->lang
->getNsIndex( utf8_encode( $text ) );
73 function specialPage( $name ) {
74 # At least one function calls this with Special:Undelete/Article_title, so it needs encoding
75 return utf8_decode( $this->lang
->specialPage( utf8_encode( $name ) ) );
78 function getQuickbarSettings() {
79 return utf8_decode_array( $this->lang
->getQuickbarSettings() );
82 function getSkinNames() {
83 return utf8_decode_array( $this->lang
->getSkinNames() );
86 function getMathNames() {
87 return utf8_decode_array( $this->lang
->getMathNames() );
90 function getDateFormats() {
91 return utf8_decode_array( $this->lang
->getDateFormats() );
94 function getUserToggles() {
95 return utf8_decode_array( $this->lang
->getUserToggles() );
98 function getUserToggle( $tog ) {
99 return utf8_decode( $this->lang
->getUserToggle( $tog ) );
102 function getLanguageNames() {
103 return utf8_decode_array( $this->lang
->getLanguageNames() );
106 function getLanguageName( $code ) {
107 return utf8_decode( $this->lang
->getLanguageName( $code ) );
110 function getMonthName( $key ) {
111 return utf8_decode( $this->lang
->getMonthName( $key ) );
114 function getMonthNameGen( $key ) {
115 return utf8_decode( $this->lang
->getMonthNameGen( $key ) );
118 function getMonthAbbreviation( $key ) {
119 return utf8_decode( $this->lang
->getMonthAbbreviation( $key ) );
122 function getWeekdayName( $key ) {
123 return utf8_decode( $this->lang
->getWeekdayName( $key ) );
126 function userAdjust( $ts ) {
127 return $this->lang
->userAdjust( $ts );
130 function date( $ts, $adj = false ) {
131 return utf8_decode( $this->lang
->date( $ts, $adj ) );
134 function time( $ts, $adj = false, $seconds = false ) {
135 return utf8_decode( $this->lang
->time( $ts, $adj ) );
138 function timeanddate( $ts, $adj = false ) {
139 return utf8_decode( $this->lang
->timeanddate( $ts, $adj ) );
142 function rfc1123( $ts ) {
143 # ASCII by definition
144 return $this->lang
->rfc1123( $ts );
147 function getValidSpecialPages() {
148 return utf8_decode_array( $this->lang
->getValidSpecialPages() );
151 function getSysopSpecialPages() {
152 return utf8_decode_array( $this->lang
->getSysopSpecialPages() );
155 function getDeveloperSpecialPages() {
156 return utf8_decode_array( $this->lang
->getDeveloperSpecialPages() );
159 function getMessage( $key ) {
160 return utf8_decode( $this->lang
->getMessage( $key ) );
163 function getAllMessages() {
164 return utf8_decode_array( $this->lang
->getAllMessages() );
167 function iconv( $in, $out, $string ) {
169 return Language
::iconv( $in, $out, $string );
172 function ucfirst( $string ) {
174 return Language
::ucfirst( $string );
177 function lcfirst( $s ) {
179 return Language
::lcfirst( $s );
182 function checkTitleEncoding( $s ) {
184 return Language
::checkTitleEncoding( $s );
187 function stripForSearch( $in ) {
189 return Language
::stripForSearch( $in );
192 function firstChar( $s ) {
194 return Language
::firstChar( $s );
197 function setAltEncoding() {
198 # Not sure if this should be handled
199 $this->lang
->setAltEncoding();
202 function recodeForEdit( $s ) {
204 return Language
::recodeForEdit( $s );
207 function recodeInput( $s ) {
209 return Language
::recodeInput( $s );
214 return $this->lang
->isRTL();
217 function linkPrefixExtension() {
219 return $this->lang
->linkPrefixExtension();
222 function &getMagicWords() {
223 return utf8_decode_array( $this->lang
->getMagicWords() );
226 function getMagic( &$mw ) {
227 # Not sure how to handle this.
228 # A moot point perhaps as few language files currently
229 # assign localised magic words, and none of the ones we
230 # need backwards compatibility for.
231 return $this->lang
->getMagic( $mw );
234 function emphasize( $text ) {
235 # It's unlikely that the emphasis markup itself will
236 # include any non-ASCII chars.
237 return $this->lang
->emphasize( $text );
240 function formatNum( $number ) {
241 # Probably not necessary...
242 return utf8_decode( $this->lang
->formatNum( $number ) );
245 function listToText( $l ) {
246 # It's unlikely that the list markup itself will
247 # include any non-ASCII chars. (?)
248 return $this->lang
->listToText( $l );