* (bug 5432) Fix inconsistencies in cookie names when using table prefixes
[mediawiki.git] / languages / LanguageSr.php
blobbf129989ca0862c84736d2ad5da9f5aaedf94804
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Language
5 */
7 /*
8 There are two levels of conversion for Serbian: the script level
9 (Cyrillics <-> Latin), and the variant level (ekavian
10 <->iyekavian). The two are orthogonal. So we really only need two
11 dictionaries: one for Cyrillics and Latin, and one for ekavian and
12 iyekavian.
14 require_once( "LanguageConverter.php" );
15 require_once( "LanguageSr_ec.php" );
16 require_once( "LanguageSr_el.php" );
17 require_once( "LanguageSr_jc.php" );
18 require_once( "LanguageSr_jl.php" );
20 class SrConverter extends LanguageConverter {
21 var $mToLatin = array(
22 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
23 'ђ' => 'đ', 'е' => 'e', 'ж' => 'ž', 'з' => 'z', 'и' => 'i',
24 'ј' => 'j', 'к' => 'k', 'л' => 'l', 'љ' => 'lj', 'м' => 'm',
25 'н' => 'n', 'њ' => 'nj', 'о' => 'o', 'п' => 'p', 'р' => 'r',
26 'с' => 's', 'т' => 't', 'ћ' => 'ć', 'у' => 'u', 'ф' => 'f',
27 'х' => 'h', 'ц' => 'c', 'ч' => 'č', 'џ' => 'dž', 'ш' => 'š',
29 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
30 'Ђ' => 'Đ', 'Е' => 'E', 'Ж' => 'Ž', 'З' => 'Z', 'И' => 'I',
31 'Ј' => 'J', 'К' => 'K', 'Л' => 'L', 'Љ' => 'Lj', 'М' => 'M',
32 'Н' => 'N', 'Њ' => 'Nj', 'О' => 'O', 'П' => 'P', 'Р' => 'R',
33 'С' => 'S', 'Т' => 'T', 'Ћ' => 'Ć', 'У' => 'U', 'Ф' => 'F',
34 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Č', 'Џ' => 'Dž', 'Ш' => 'Š',
37 var $mToCyrillics = array(
38 'a' => 'а', 'b' => 'б', 'c' => 'ц', 'č' => 'ч', 'ć' => 'ћ',
39 'd' => 'д', 'dž' => 'џ', 'đ' => 'ђ', 'e' => 'е', 'f' => 'ф',
40 'g' => 'г', 'h' => 'х', 'i' => 'и', 'j' => 'ј', 'k' => 'к',
41 'l' => 'л', 'lj' => 'љ', 'm' => 'м', 'n' => 'н', 'nj' => 'њ',
42 'o' => 'о', 'p' => 'п', 'r' => 'р', 's' => 'с', 'š' => 'ш',
43 't' => 'т', 'u' => 'у', 'v' => 'в', 'z' => 'з', 'ž' => 'ж',
45 'A' => 'А', 'B' => 'Б', 'C' => 'Ц', 'Č' => 'Ч', 'Ć' => 'Ћ',
46 'D' => 'Д', 'Dž' => 'Џ', 'Đ' => 'Ђ', 'E' => 'Е', 'F' => 'Ф',
47 'G' => 'Г', 'H' => 'Х', 'I' => 'И', 'J' => 'Ј', 'K' => 'К',
48 'L' => 'Л', 'LJ' => 'Љ', 'M' => 'М', 'N' => 'Н', 'NJ' => 'Њ',
49 'O' => 'О', 'P' => 'П', 'R' => 'Р', 'S' => 'С', 'Š' => 'Ш',
50 'T' => 'Т', 'U' => 'У', 'V' => 'В', 'Z' => 'З', 'Ž' => 'Ж',
52 'DŽ' => 'Џ', 'd!ž' => 'дж', 'D!ž'=> 'Дж', 'D!Ž'=> 'ДЖ',
53 'Lj' => 'Љ', 'l!j' => 'лј', 'L!j'=> 'Лј', 'L!J'=> 'ЛЈ',
54 'Nj' => 'Њ', 'n!j' => 'нј', 'N!j'=> 'Нј', 'N!J'=> 'НЈ'
57 function loadDefaultTables() {
58 $this->mTables = array();
59 $this->mTables['sr-ec'] = $this->mToCyrillics;
60 $this->mTables['sr-jc'] = $this->mToCyrillics;
61 $this->mTables['sr-el'] = $this->mToLatin;
62 $this->mTables['sr-jl'] = $this->mToLatin;
63 $this->mTables['sr'] = array();
66 /* rules should be defined as -{ekavian | iyekavian-} -or-
67 -{code:text | code:text | ...}-
69 function parseManualRule($rule, $flags) {
71 $choices = explode($this->mMarkup['varsep'], $rule);
72 $carray = array();
73 if(sizeof($choices) == 1) {
74 if(in_array('W', $flags)) {
75 $carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
76 $carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
77 $carray['sr-jc'] = $this->autoConvert($choices[0], 'sr-jc');
78 $carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
79 $carray['sr-jl'] = $this->autoConvert($choices[0], 'sr-jl');
81 foreach($this->mVariants as $v) {
82 $carray[$v] = $choices[0];
84 return $carray;
87 /* detect which format is used, also trim the choices*/
88 $n=0;
89 foreach($choices as $c=>$t) {
90 if(strpos($t, $this->mMarkup['codesep']) !== false) { $n++; }
91 $choices[$c] = trim($t);
93 /* the -{code:text | ...}- format */
94 if($n == sizeof($choices)) {
95 foreach($choices as $c) {
96 list($code, $text) = explode($this->mMarkup['codesep'], $c);
97 $carray[trim($code)] = trim($text);
99 return $carray;
102 /* the two choice format -{choice1; choice2}-*/
103 if(sizeof($choices == 2) && $n==0) {
104 if(in_array('S', $flags)) {
105 // conversion between Cyrillics and Latin
106 $carray['sr'] = $carray['sr-ec'] =$carray['sr-jc'] = $choices[0];
107 $carray['sr-el'] =$carray['sr-jl'] = $choices[1];
109 else {
110 $carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
111 $carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
112 $carray['sr-jc'] = $this->autoConvert($choices[1], 'sr-jc');
113 $carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
114 $carray['sr-jl'] = $this->autoConvert($choices[1], 'sr-jl');
116 return $carray;
118 return $carray;
123 class LanguageSr extends LanguageSr_ec {
124 function LanguageSr() {
125 global $wgHooks;
126 $variants = array('sr', 'sr-ec', 'sr-jc', 'sr-el', 'sr-jl');
127 $variantfallbacks = array(
128 'sr' => 'sr-ec',
129 'sr-ec' => 'sr-jc',
130 'sr-jc' => 'sr-ec',
131 'sr-el' => 'sr-jl',
132 'sr-jl' => 'sr-el'
134 $marker = array();//don't mess with these, leave them as they are
135 $flags = array(
136 'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',
137 'W' => 'W', 'реч' => 'W', 'reč' => 'W', 'ријеч' => 'W', 'riječ' => 'W'
139 $this->mConverter = new SrConverter($this, 'sr', $variants, $variantfallbacks, $marker, $flags);
140 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
142 function getVariantname( $code ) {
143 return wfMsg( "variantname-$code" );