LanguageUz.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Uzbek specific code.
  4. *
  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.
  9. *
  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.
  14. *
  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. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Language
  22. */
  23. /**
  24. * @ingroup Language
  25. */
  26. class UzConverter extends LanguageConverter {
  27. public $toLatin = [
  28. 'а' => 'a', 'А' => 'A',
  29. 'б' => 'b', 'Б' => 'B',
  30. 'д' => 'd', 'Д' => 'D',
  31. 'е' => 'e', 'Е' => 'E',
  32. 'э' => 'e', 'Э' => 'E',
  33. 'в' => 'v', 'В' => 'V',
  34. 'х' => 'x', 'Х' => 'X',
  35. 'ғ' => 'gʻ', 'Ғ' => 'Gʻ',
  36. 'г' => 'g', 'Г' => 'G',
  37. 'ҳ' => 'h', 'Ҳ' => 'H',
  38. 'ж' => 'j', 'Ж' => 'J',
  39. 'з' => 'z', 'З' => 'Z',
  40. 'и' => 'i', 'И' => 'I',
  41. 'к' => 'k', 'К' => 'K',
  42. 'л' => 'l', 'Л' => 'L',
  43. 'м' => 'm', 'М' => 'M',
  44. 'н' => 'n', 'Н' => 'N',
  45. 'о' => 'o', 'О' => 'O',
  46. 'п' => 'p', 'П' => 'P',
  47. 'р' => 'r', 'Р' => 'R',
  48. 'с' => 's', 'С' => 'S',
  49. 'т' => 't', 'Т' => 'T',
  50. 'у' => 'u', 'У' => 'U',
  51. 'ф' => 'f', 'Ф' => 'F',
  52. 'ц' => 'c', 'Ц' => 'C',
  53. 'ў' => 'oʻ', 'Ў' => 'Oʻ',
  54. // note: at the beginning of a word and right after a consonant, only "s" is used
  55. 'ц' => 'ts', 'Ц' => 'Ts',
  56. 'қ' => 'q', 'Қ' => 'Q',
  57. 'ё' => 'yo', 'Ё' => 'Yo',
  58. 'ю' => 'yu', 'Ю' => 'Yu',
  59. 'ч' => 'ch', 'Ч' => 'Ch',
  60. 'ш' => 'sh', 'Ш' => 'Sh',
  61. 'й' => 'y', 'Й' => 'Y',
  62. 'я' => 'ya', 'Я' => 'Ya',
  63. 'ъ' => 'ʼ',
  64. ];
  65. public $toCyrillic = [
  66. 'a' => 'а', 'A' => 'А',
  67. 'b' => 'б', 'B' => 'Б',
  68. 'd' => 'д', 'D' => 'Д',
  69. // at the beginning of a word and after a vowel, "э" is used instead of "e"
  70. // (see regex below)
  71. 'e' => 'э', 'E' => 'Э',
  72. 'f' => 'ф', 'F' => 'Ф',
  73. 'g' => 'г', 'G' => 'Г',
  74. 'g‘' => 'ғ', 'G‘' => 'Ғ', 'gʻ' => 'ғ', 'Gʻ' => 'Ғ',
  75. 'h' => 'ҳ', 'H' => 'Ҳ',
  76. 'i' => 'и', 'I' => 'И',
  77. 'k' => 'к', 'K' => 'К',
  78. 'l' => 'л', 'L' => 'Л',
  79. 'm' => 'м', 'M' => 'М',
  80. 'n' => 'н', 'N' => 'Н',
  81. 'o' => 'о', 'O' => 'О',
  82. 'p' => 'п', 'P' => 'П',
  83. 'r' => 'р', 'R' => 'Р',
  84. 's' => 'с', 'S' => 'С',
  85. 't' => 'т', 'T' => 'Т',
  86. 'u' => 'у', 'U' => 'У',
  87. 'v' => 'в', 'V' => 'В',
  88. 'x' => 'х', 'X' => 'Х',
  89. 'z' => 'з', 'Z' => 'З',
  90. 'j' => 'ж', 'J' => 'Ж',
  91. 'o‘' => 'ў', 'O‘' => 'Ў', 'oʻ' => 'ў', 'Oʻ' => 'Ў',
  92. 'yo‘' => 'йў', 'Yo‘' => 'Йў', 'yoʻ' => 'йў', 'Yoʻ' => 'Йў',
  93. 'ts' => 'ц', 'Ts' => 'Ц',
  94. 'q' => 'қ', 'Q' => 'Қ',
  95. 'yo' => 'ё', 'Yo' => 'Ё',
  96. 'yu' => 'ю', 'Yu' => 'Ю',
  97. 'ch' => 'ч', 'Ch' => 'Ч',
  98. 'sh' => 'ш', 'Sh' => 'Ш',
  99. 'y' => 'й', 'Y' => 'Й',
  100. 'ya' => 'я', 'Ya' => 'Я',
  101. 'ʼ' => 'ъ',
  102. ];
  103. function loadDefaultTables() {
  104. $this->mTables = [
  105. 'uz-cyrl' => new ReplacementArray( $this->toCyrillic ),
  106. 'uz-latn' => new ReplacementArray( $this->toLatin ),
  107. 'uz' => new ReplacementArray()
  108. ];
  109. }
  110. function translate( $text, $toVariant ) {
  111. if ( $toVariant == 'uz-cyrl' ) {
  112. $text = str_replace( 'ye', 'е', $text );
  113. $text = str_replace( 'Ye', 'Е', $text );
  114. $text = str_replace( 'YE', 'Е', $text );
  115. // "е" after consonants, otherwise "э" (see above)
  116. $text = preg_replace( '/([BVGDJZYKLMNPRSTFXCWQʻ‘H])E/u', '$1Е', $text );
  117. $text = preg_replace( '/([bvgdjzyklmnprstfxcwqʻ‘h])e/ui', '$1е', $text );
  118. }
  119. return parent::translate( $text, $toVariant );
  120. }
  121. }
  122. /**
  123. * Uzbek
  124. *
  125. * @ingroup Language
  126. */
  127. class LanguageUz extends Language {
  128. function __construct() {
  129. parent::__construct();
  130. $variants = [ 'uz', 'uz-latn', 'uz-cyrl' ];
  131. $variantfallbacks = [
  132. 'uz' => 'uz-latn',
  133. 'uz-cyrl' => 'uz',
  134. 'uz-latn' => 'uz',
  135. ];
  136. $this->mConverter = new UzConverter( $this, 'uz', $variants, $variantfallbacks );
  137. }
  138. }