9a54330bd312a357672d7470d56671265bcd0a30
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!
30 # This file and LanguageUtf8.php may be included from within functions, so
31 # we need to have global statements
32 global $wgInputEncoding, $wgOutputEncoding;
34 $wgInputEncoding = "ISO-8859-1";
35 $wgOutputEncoding = "ISO-8859-1";
37 function utf8_decode_array( $arr ) {
38 if( !is_array( $arr ) ) {
39 wfDebugDieBacktrace( "utf8_decode_array given non-array" );
41 return array_map( "utf8_decode", $arr );
45 # This is a proxy object; the Language instance handed to us speaks
46 # UTF-8, while the wiki outside speaks Latin-1. We translate as
47 # necessary so neither knows the other is in the wrong charset.
49 class LanguageLatin1
{
52 function LanguageLatin1( &$language ) {
53 $this->lang
=& $language;
56 function getDefaultUserOptions() {
57 return $this->lang
->getDefaultUserOptions();
60 function getBookstoreList() {
61 return utf8_decode_array( $this->lang
->getBookstoreList() );
64 function getNamespaces() {
65 return utf8_decode_array( $this->lang
->getNamespaces() );
68 function getNsText( $index ) {
69 return utf8_decode( $this->lang
->getNsText( $index ) );
72 function getNsIndex( $text ) {
73 return $this->lang
->getNsIndex( utf8_encode( $text ) );
76 function specialPage( $name ) {
77 # At least one function calls this with Special:Undelete/Article_title, so it needs encoding
78 return utf8_decode( $this->lang
->specialPage( utf8_encode( $name ) ) );
81 function getQuickbarSettings() {
82 return utf8_decode_array( $this->lang
->getQuickbarSettings() );
85 function getSkinNames() {
86 return utf8_decode_array( $this->lang
->getSkinNames() );
89 function getMathNames() {
90 return utf8_decode_array( $this->lang
->getMathNames() );
93 function getDateFormats() {
94 return utf8_decode_array( $this->lang
->getDateFormats() );
97 function getUserToggles() {
98 return utf8_decode_array( $this->lang
->getUserToggles() );
101 function getUserToggle( $tog ) {
102 return utf8_decode( $this->lang
->getUserToggle( $tog ) );
105 function getLanguageNames() {
106 return utf8_decode_array( $this->lang
->getLanguageNames() );
109 function getLanguageName( $code ) {
110 return utf8_decode( $this->lang
->getLanguageName( $code ) );
113 function getMonthName( $key ) {
114 return utf8_decode( $this->lang
->getMonthName( $key ) );
117 function getMonthNameGen( $key ) {
118 return utf8_decode( $this->lang
->getMonthNameGen( $key ) );
121 function getMonthAbbreviation( $key ) {
122 return utf8_decode( $this->lang
->getMonthAbbreviation( $key ) );
125 function getWeekdayName( $key ) {
126 return utf8_decode( $this->lang
->getWeekdayName( $key ) );
129 function userAdjust( $ts ) {
130 return $this->lang
->userAdjust( $ts );
133 function date( $ts, $adj = false ) {
134 return utf8_decode( $this->lang
->date( $ts, $adj ) );
137 function time( $ts, $adj = false, $seconds = false ) {
138 return utf8_decode( $this->lang
->time( $ts, $adj ) );
141 function timeanddate( $ts, $adj = false ) {
142 return utf8_decode( $this->lang
->timeanddate( $ts, $adj ) );
145 function rfc1123( $ts ) {
146 # ASCII by definition
147 return $this->lang
->rfc1123( $ts );
150 function getValidSpecialPages() {
151 return utf8_decode_array( $this->lang
->getValidSpecialPages() );
154 function getSysopSpecialPages() {
155 return utf8_decode_array( $this->lang
->getSysopSpecialPages() );
158 function getDeveloperSpecialPages() {
159 return utf8_decode_array( $this->lang
->getDeveloperSpecialPages() );
162 function getMessage( $key ) {
163 return utf8_decode( $this->lang
->getMessage( $key ) );
166 function getAllMessages() {
167 return utf8_decode_array( $this->lang
->getAllMessages() );
170 function iconv( $in, $out, $string ) {
172 return Language
::iconv( $in, $out, $string );
175 function ucfirst( $string ) {
177 return Language
::ucfirst( $string );
180 function lcfirst( $s ) {
182 return Language
::lcfirst( $s );
185 function checkTitleEncoding( $s ) {
187 return Language
::checkTitleEncoding( $s );
190 function stripForSearch( $in ) {
192 return Language
::stripForSearch( $in );
195 function firstChar( $s ) {
197 return Language
::firstChar( $s );
200 function setAltEncoding() {
201 # Not sure if this should be handled
202 $this->lang
->setAltEncoding();
205 function recodeForEdit( $s ) {
207 return Language
::recodeForEdit( $s );
210 function recodeInput( $s ) {
212 return Language
::recodeInput( $s );
217 return $this->lang
->isRTL();
220 function linkPrefixExtension() {
222 return $this->lang
->linkPrefixExtension();
225 function &getMagicWords() {
226 return utf8_decode_array( $this->lang
->getMagicWords() );
229 function getMagic( &$mw ) {
230 # Not sure how to handle this.
231 # A moot point perhaps as few language files currently
232 # assign localised magic words, and none of the ones we
233 # need backwards compatibility for.
234 return $this->lang
->getMagic( $mw );
237 function emphasize( $text ) {
238 # It's unlikely that the emphasis markup itself will
239 # include any non-ASCII chars.
240 return $this->lang
->emphasize( $text );
243 function formatNum( $number ) {
244 # Probably not necessary...
245 return utf8_decode( $this->lang
->formatNum( $number ) );
248 function listToText( $l ) {
249 # It's unlikely that the list markup itself will
250 # include any non-ASCII chars. (?)
251 return $this->lang
->listToText( $l );
254 function truncate( $string, $length, $ellipsis = "" ) {
255 return Language
::truncate( $string, $length, $ellipsis );
258 function convertGrammar( $word, $case ) {
262 function getPreferredVariant() {
263 return $this->lang
->getPreferredVariant();
266 function segmentForDiff( $text ) {
270 function unsegmentForDiff( $text ) {
274 function convert( $text, $isTitle=false ) {
275 return utf8_decode( $this->lang
->convert( utf8_encode( $text ), $isTitle ) );
278 function autoConvert($text, $toVariant=false) {
279 return utf8_decode( $this->lang
->autoConvert( utf8_encode( $text ), $toVariant ) );
282 /* hook for converting the title, which may needs special treatment
284 function convertTitle($text) {
285 return utf8_decode( $this->lang
->convertTitle( utf8_encode( $text ) ) );
288 function getVariants() {
289 return $this->lang
->getVariants();
292 function convertForSearchResult( $termsArray ) {