forked from ironsmile/php-translit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslitUk.php
56 lines (53 loc) · 2.25 KB
/
TranslitUk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Transliteration data for Ukrainian (UK)
*
* Data taken from http://en.wikipedia.org/wiki/Romanization_of_Ukrainian,
* column "National".
*
* @author Alexey Shtokalo <[email protected]>
*/
class TranslitUk
{
public $alphabet = array (
// upper case
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'H',
'ЗГ' => 'Zgh', 'Зг' => 'Zgh', 'Ґ' => 'G', 'Д' => 'D',
'Е' => 'E', 'Є' => 'IE', 'Ж' => 'Zh', 'З' => 'Z',
'И' => 'Y', 'І' => 'I', 'Ї' => 'I', 'Й' => 'I',
'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S',
'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'Kh',
'Ц' => 'Ts', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Shch',
'Ь' => '', 'Ю' => 'Iu', 'Я' => 'Ia', '’' => '',
// lower case
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'h',
'зг' => 'zgh', 'ґ' => 'g', 'д' => 'd', 'е' => 'e',
'є' => 'ie', 'ж' => 'zh', 'з' => 'z', 'и' => 'y',
'і' => 'i', 'ї' => 'i', 'й' => 'i', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o',
'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
'у' => 'u', 'ф' => 'f', 'х' => 'kh', 'ц' => 'ts',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shch', 'ь' => '',
'ю' => 'iu', 'я' => 'ia', '\'' => '',
);
public function convert($text)
{
return str_replace(
array_keys($this->alphabet),
array_values($this->alphabet),
preg_replace(
// use alternative variant at the beginning of a word
array (
'/(?<=^|\s)Є/', '/(?<=^|\s)Ї/', '/(?<=^|\s)Й/',
'/(?<=^|\s)Ю/', '/(?<=^|\s)Я/', '/(?<=^|\s)є/',
'/(?<=^|\s)ї/', '/(?<=^|\s)й/', '/(?<=^|\s)ю/',
'/(?<=^|\s)я/',
),
array (
'Ye', 'Yi', 'Y', 'Yu', 'Ya', 'ye', 'yi', 'y', 'yu', 'ya',
),
$text)
);
}
}