3 * Crimean Tatar (Qırımtatarca) specific code.
5 * Adapted from https://crh.wikipedia.org/wiki/Qullan%C4%B1c%C4%B1:Don_Alessandro/Translit
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
27 * Crimean Tatar (Qırımtatarca) converter routines
31 class CrhConverter
extends LanguageConverter
{
32 // Defines working character ranges
33 const WORD_BEGINS
= '\r\s\"\'\(\)\-<>\[\]\/.,:;!?';
34 const WORD_ENDS
= '\r\s\"\'\(\)\-<>\[\]\/.,:;!?';
37 const C_UC
= 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'; # Crimean Tatar Cyrillic uppercase
38 const C_LC
= 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; # Crimean Tatar Cyrillic lowercase
39 const C_CONS_UC
= 'БВГДЖЗЙКЛМНПРСТФХЦЧШЩCÑ'; # Crimean Tatar Cyrillic + CÑ uppercase consonants
40 const C_CONS_LC
= 'бвгджзйклмнпрстфхцчшщcñ'; # Crimean Tatar Cyrillic + CÑ lowercase consonants
41 const C_M_CONS
= 'бгкмпшcБГКМПШC'; # Crimean Tatar Cyrillic M-type consonants
43 # Crimean Tatar Cyrillic + CÑ consonants
44 const C_CONS
= 'бвгджзйклмнпрстфхцчшщcñБВГДЖЗЙКЛМНПРСТФХЦЧШЩCÑ';
47 const L_UC
= 'AÂBCÇDEFGĞHIİJKLMNÑOÖPQRSŞTUÜVYZ'; # Crimean Tatar Latin uppercase
48 const L_LC
= 'aâbcçdefgğhıijklmnñoöpqrsştuüvyz'; # Crimean Tatar Latin lowercase
49 const L_N_CONS_UC
= 'ÇNRSTZ'; # Crimean Tatar Latin N-type upper case consonants
50 const L_N_CONS_LC
= 'çnrstz'; # Crimean Tatar Latin N-type lower case consonants
51 const L_N_CONS
= 'çnrstzÇNRSTZ'; # Crimean Tatar Latin N-type consonants
52 const L_M_CONS
= 'bcgkmpşBCGKMPŞ'; # Crimean Tatar Latin M-type consonants
53 const L_CONS_UC
= 'BCÇDFGHJKLMNÑPRSŞTVZ'; # Crimean Tatar Latin uppercase consonants
54 const L_CONS_LC
= 'bcçdfghjklmnñprsştvz'; # Crimean Tatar Latin lowercase consonants
55 const L_CONS
= 'bcçdfghjklmnñprsştvzBCÇDFGHJKLMNÑPRSŞTVZ'; # Crimean Tatar Latin consonants
56 const L_VOW_UC
= 'AÂEIİOÖUÜ'; # Crimean Tatar Latin uppercase vowels
57 const L_VOW
= 'aâeıioöuüAÂEIİOÖUÜ'; # Crimean Tatar Latin vowels
58 const L_F_UC
= 'EİÖÜ'; # Crimean Tatar Latin uppercase front vowels
59 const L_F
= 'eiöüEİÖÜ'; # Crimean Tatar Latin front vowels
62 * @param Language $langobj
63 * @param string $maincode
64 * @param array $variants
65 * @param array $variantfallbacks
68 function __construct( $langobj, $maincode,
70 $variantfallbacks = [],
72 parent
::__construct( $langobj, $maincode,
73 $variants, $variantfallbacks, $flags );
75 // No point delaying this since they're in code.
76 // Waiting until loadDefaultTables() means they never get loaded
77 // when the tables themselves are loaded from cache.
78 $this->loadExceptions();
81 public $mCyrillicToLatin = [
83 ## these are independent of location in the word, but have
84 ## to go first so other transforms don't bleed them
85 'гъ' => 'ğ', 'Гъ' => 'Ğ', 'ГЪ' => 'Ğ',
86 'къ' => 'q', 'Къ' => 'Q', 'КЪ' => 'Q',
87 'нъ' => 'ñ', 'Нъ' => 'Ñ', 'НЪ' => 'Ñ',
88 'дж' => 'c', 'Дж' => 'C', 'ДЖ' => 'C',
90 'А' => 'A', 'а' => 'a', 'Б' => 'B', 'б' => 'b',
91 'В' => 'V', 'в' => 'v', 'Г' => 'G', 'г' => 'g',
92 'Д' => 'D', 'д' => 'd', 'Ж' => 'J', 'ж' => 'j',
93 'З' => 'Z', 'з' => 'z', 'И' => 'İ', 'и' => 'i',
94 'Й' => 'Y', 'й' => 'y', 'К' => 'K', 'к' => 'k',
95 'Л' => 'L', 'л' => 'l', 'М' => 'M', 'м' => 'm',
96 'Н' => 'N', 'н' => 'n', 'П' => 'P', 'п' => 'p',
97 'Р' => 'R', 'р' => 'r', 'С' => 'S', 'с' => 's',
98 'Т' => 'T', 'т' => 't', 'Ф' => 'F', 'ф' => 'f',
99 'Х' => 'H', 'х' => 'h', 'Ч' => 'Ç', 'ч' => 'ç',
100 'Ш' => 'Ş', 'ш' => 'ş', 'Ы' => 'I', 'ы' => 'ı',
101 'Э' => 'E', 'э' => 'e', 'Е' => 'E', 'е' => 'e',
102 'Я' => 'Â', 'я' => 'â', 'У' => 'U', 'у' => 'u',
103 'О' => 'O', 'о' => 'o',
105 'Ё' => 'Yo', 'ё' => 'yo', 'Ю' => 'Yu', 'ю' => 'yu',
106 'Ц' => 'Ts', 'ц' => 'ts', 'Щ' => 'Şç', 'щ' => 'şç',
107 'Ь' => '', 'ь' => '', 'Ъ' => '', 'ъ' => '',
111 public $mLatinToCyrillic = [
112 'Â' => 'Я', 'â' => 'я', 'B' => 'Б', 'b' => 'б',
113 'Ç' => 'Ч', 'ç' => 'ч', 'D' => 'Д', 'd' => 'д',
114 'F' => 'Ф', 'f' => 'ф', 'G' => 'Г', 'g' => 'г',
115 'H' => 'Х', 'h' => 'х', 'I' => 'Ы', 'ı' => 'ы',
116 'İ' => 'И', 'i' => 'и', 'J' => 'Ж', 'j' => 'ж',
117 'K' => 'К', 'k' => 'к', 'L' => 'Л', 'l' => 'л',
118 'M' => 'М', 'm' => 'м', 'N' => 'Н', 'n' => 'н',
119 'O' => 'О', 'o' => 'о', 'P' => 'П', 'p' => 'п',
120 'R' => 'Р', 'r' => 'р', 'S' => 'С', 's' => 'с',
121 'Ş' => 'Ш', 'ş' => 'ш', 'T' => 'Т', 't' => 'т',
122 'V' => 'В', 'v' => 'в', 'Z' => 'З', 'z' => 'з',
124 'ya' => 'я', 'Ya' => 'Я', 'YA' => 'Я',
125 'ye' => 'е', 'YE' => 'Е', 'Ye' => 'Е',
128 'A' => 'А', 'a' => 'а', 'E' => 'Е', 'e' => 'е',
129 'Ö' => 'Ё', 'ö' => 'ё', 'U' => 'У', 'u' => 'у',
130 'Ü' => 'Ю', 'ü' => 'ю', 'Y' => 'Й', 'y' => 'й',
131 'C' => 'Дж', 'c' => 'дж', 'Ğ' => 'Гъ', 'ğ' => 'гъ',
132 'Ñ' => 'Нъ', 'ñ' => 'нъ', 'Q' => 'Къ', 'q' => 'къ',
136 public $mExceptions = [];
137 public $mCyrl2LatnPatterns = [];
138 public $mLatn2CyrlPatterns = [];
139 public $mCyrlCleanUpRegexes = [];
141 public $mExceptionsLoaded = false;
143 function loadDefaultTables() {
145 'crh-latn' => new ReplacementArray( $this->mCyrillicToLatin
),
146 'crh-cyrl' => new ReplacementArray( $this->mLatinToCyrillic
),
147 'crh' => new ReplacementArray()
151 function loadExceptions() {
152 if ( $this->mExceptionsLoaded
) {
156 $this->mExceptionsLoaded
= true;
157 $crhExceptions = new MediaWiki\Languages\Data\
CrhExceptions();
158 list( $this->mExceptions
, $this->mCyrl2LatnPatterns
, $this->mLatn2CyrlPatterns
,
159 $this->mCyrlCleanUpRegexes
) = $crhExceptions->loadExceptions( self
::L_LC
. self
::C_LC
,
160 self
::L_UC
. self
::C_UC
);
164 * A function wrapper:
165 * - if there is no selected variant, leave the link
167 * - do not try to find variants for usernames
169 * @param string &$link
171 * @param bool $ignoreOtherCond
173 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
174 // check for user namespace
175 if ( is_object( $nt ) ) {
176 $ns = $nt->getNamespace();
177 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
183 parent
::findVariantLink( $link, $nt, $ignoreOtherCond );
184 if ( $this->getPreferredVariant() == $this->mMainLanguageCode
) {
190 * It translates text into variant, specials:
191 * - ommiting roman numbers
193 * @param string $text
194 * @param bool $toVariant
196 * @throws MWException
199 function translate( $text, $toVariant ) {
201 switch ( $toVariant ) {
203 $letters = self
::L_UC
. self
::L_LC
. "\'";
206 $letters = self
::C_UC
. self
::C_LC
. "";
213 if ( !$this->mTablesLoaded
) {
217 if ( !isset( $this->mTables
[$toVariant] ) ) {
218 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables
) ) );
221 // check for roman numbers like VII, XIX...
222 $roman = '/^M{0,3}(C[DM]|D{0,1}C{0,3})(X[LC]|L{0,1}X{0,3})(I[VX]|V{0,1}I{0,3})$/u';
224 # match any sub-string of the relevant letters and convert it
225 $matches = preg_split( '/(\b|^)[^' . $letters . ']+(\b|$)/u',
226 $text, -1, PREG_SPLIT_OFFSET_CAPTURE
);
229 foreach ( $matches as $m ) {
230 # copy over the non-matching bit
231 $ret .= substr( $text, $mstart, $m[1] - $mstart );
232 # skip certain classes of strings
234 if ( array_key_exists( $m[0], $this->mExceptions
) ) {
235 # if it's an exception, just copy down the right answer
236 $ret .= $this->mExceptions
[$m[0]];
237 } elseif ( ! $m[0] ||
# empty strings
238 preg_match( $roman, $m[0] ) ||
# roman numerals
239 preg_match( '/[^' . $letters . ']/', $m[0] ) # mixed orthography
243 # convert according to the rules
244 $token = $this->regsConverter( $m[0], $toVariant );
245 $ret .= parent
::translate( $token, $toVariant );
247 $mstart = $m[1] +
strlen( $m[0] );
250 # pick up stray quote marks
251 switch ( $toVariant ) {
253 $ret = strtr( $ret, [ '“' => '«', '”' => '»', ] );
254 $ret = $this->regsConverter( $ret, 'cyrl-cleanup' );
257 $ret = strtr( $ret, [ '«' => '"', '»' => '"', ] );
264 private function regsConverter( $text, $toVariant ) {
265 if ( $text == '' ) return $text;
269 switch ( $toVariant ) {
271 foreach ( $this->mCyrl2LatnPatterns
as $pat => $rep ) {
272 $text = preg_replace( $pat, $rep, $text );
276 foreach ( $this->mLatn2CyrlPatterns
as $pat => $rep ) {
277 $text = preg_replace( $pat, $rep, $text );
281 foreach ( $this->mCyrlCleanUpRegexes
as $pat => $rep ) {
282 $text = preg_replace( $pat, $rep, $text );
293 * Crimean Tatar (Qırımtatarca)
297 class LanguageCrh
extends Language
{
299 function __construct() {
300 parent
::__construct();
302 $variants = [ 'crh', 'crh-cyrl', 'crh-latn' ];
303 $variantfallbacks = [
305 'crh-cyrl' => 'crh-latn',
306 'crh-latn' => 'crh-cyrl',
309 $this->mConverter
= new CrhConverter( $this, 'crh', $variants, $variantfallbacks );