php - meanings - greek alphabet pronunciation
Transliteración cirílica en PHP (13)
¿Cómo transcribir los caracteres cirílicos en letras latinas?
E.g. Главная страница -> Glavnaja stranica
Esta extensión de Transliteración de PHP lo haría muy bien, pero no puedo instalarlo en mi servidor.
Sería mejor tener la misma implementación pero en PHP.
@Tural Teyyuboglu
Su código tiene un problema: si intenta transliterar, por ejemplo, "щеки" a latín y luego volver al cirílico, producirá algo como "схтеки". Los caracteres de múltiples bytes deben aparecer primero en la matriz de esta manera:
function transliterate($textcyr = null, $textlat = null) {
$cyr = array(
''ж'', ''ч'', ''щ'', ''ш'', ''ю'', ''а'', ''б'', ''в'', ''г'', ''д'', ''е'', ''з'', ''и'', ''й'', ''к'', ''л'', ''м'', ''н'', ''о'', ''п'', ''р'', ''с'', ''т'', ''у'', ''ф'', ''х'', ''ц'', ''ъ'', ''ь'', ''я'',
''Ж'', ''Ч'', ''Щ'', ''Ш'', ''Ю'', ''А'', ''Б'', ''В'', ''Г'', ''Д'', ''Е'', ''З'', ''И'', ''Й'', ''К'', ''Л'', ''М'', ''Н'', ''О'', ''П'', ''Р'', ''С'', ''Т'', ''У'', ''Ф'', ''Х'', ''Ц'', ''Ъ'', ''Ь'', ''Я'');
$lat = array(
''zh'', ''ch'', ''sht'', ''sh'', ''yu'', ''a'', ''b'', ''v'', ''g'', ''d'', ''e'', ''z'', ''i'', ''j'', ''k'', ''l'', ''m'', ''n'', ''o'', ''p'', ''r'', ''s'', ''t'', ''u'', ''f'', ''h'', ''c'', ''y'', ''x'', ''q'',
''Zh'', ''Ch'', ''Sht'', ''Sh'', ''Yu'', ''A'', ''B'', ''V'', ''G'', ''D'', ''E'', ''Z'', ''I'', ''J'', ''K'', ''L'', ''M'', ''N'', ''O'', ''P'', ''R'', ''S'', ''T'', ''U'', ''F'', ''H'', ''c'', ''Y'', ''X'', ''Q'');
if($textcyr) return str_replace($cyr, $lat, $textcyr);
else if($textlat) return str_replace($lat, $cyr, $textlat);
else return null;
}
echo transliterate (null, transliterate ("щеки")) == "щеки";
Como todo lo anterior está incompleto, aquí está mi versión:
$textcyr="Тест на кирилице";
$textlat="Test na kirilitse!";
$cyr = array(''а'',''б'',''в'',''г'',''д'',''е'',''ё'',''ж'',''з'',''и'',''й'',''к'',''л'',''м'',''н'',''о'',''п'',''р'',''с'',''т'',''у'',
''ф'',''х'',''ц'',''ч'',''ш'',''щ'',''ъ'', ''ы'',''ь'', ''э'', ''ю'',''я'',
''А'',''Б'',''В'',''Г'',''Д'',''Е'',''Ё'',''Ж'',''З'',''И'',''Й'',''К'',''Л'',''М'',''Н'',''О'',''П'',''Р'',''С'',''Т'',''У'',
''Ф'',''Х'',''Ц'',''Ч'',''Ш'',''Щ'',''Ъ'', ''Ы'',''Ь'', ''Э'', ''Ю'',''Я'' );
$lat = array( ''a'',''b'',''v'',''g'',''d'',''e'',''e'',''zh'',''z'',''i'',''y'',''k'',''l'',''m'',''n'',''o'',''p'',''r'',''s'',''t'',''u'',
''f'' ,''h'' ,''ts'' ,''ch'',''sh'' ,''sht'' ,''i'', ''y'', ''y'', ''e'' ,''yu'' ,''ya'',''A'',''B'',''V'',''G'',''D'',''E'',''E'',''Zh'',
''Z'',''I'',''Y'',''K'',''L'',''M'',''N'',''O'',''P'',''R'',''S'',''T'',''U'',
''F'' ,''H'' ,''Ts'' ,''Ch'',''Sh'' ,''Sht'' ,''I'' ,''Y'' ,''Y'', ''E'', ''Yu'' ,''Ya'' );
$textcyr = str_replace($cyr, $lat, $textcyr);
$textlat = str_replace($lat, $cyr, $textlat);
echo("$textcyr $textlat");
Preferí ё = e, ъ = i, ы = y y э = e porque estoy usando de esa manera.
Debe probar iconv()
con la opción //TRANSLIT
.
$trstr = iconv(<your encoding here>, "ISO-8859-1//TRANSLIT", $src_str)
Escribí una clase de transliteración completa para todos los idiomas europeos para utf-8. Puede ayudar (los comentarios están en polaco, pero no hay muchos, así que aquí hay algunos consejos:
- los números almacenados en constantes son idCountry en la base de datos local; puede cambiarlos a su gusto.
- "Rób transliterację dla" significa "hacer transliteración para": usted determina el país por el nombre de const.
- "Słownik tłumaczący rosyjską cyrylicę wg standardu" significa "diccionario con transliteración por estándar"
- "Tablica wycinająca akcenty z różnych znaków narodowych pobrana z http://stuffofinterest.com/misc/utf8-about.html " significa "Arreglo para cortar acentos de diferentes idiomas" (podría ayudar si encuentra algunos errores en iconv (o no puedo usarlo por alguna razón).
- Los métodos utf2ascii y cyr2lat son bastante obvios.
Espero que ayude a algunas personas porque implementarlo fue una pesadilla :)
Edición: Me acabo de dar cuenta de que falta parte del código, así que he puesto toda la clase en Pastie: class
Esta es mi versión de la tabla de transliteración para el alfabeto ruso. No es oficial pero está basado en los estándares técnicos GOST 7.79-2000 y GOST 16876-71. Los multi-personajes van primero.
public static function transliterate($textcyr = null, $textlat = null) {
$cyr = array(
''ё'', ''ж'', ''х'', ''ц'', ''ч'', ''щ'', ''ш'', ''ъ'', ''э'', ''ю'', ''я'', ''а'', ''б'', ''в'', ''г'', ''д'', ''е'', ''з'', ''и'', ''й'', ''к'', ''л'', ''м'', ''н'', ''о'', ''п'', ''р'', ''с'', ''т'', ''у'', ''ф'', ''ь'',
''Ё'', ''Ж'', ''Х'', ''Ц'', ''Ч'', ''Щ'', ''Ш'', ''Ъ'', ''Э'', ''Ю'', ''Я'', ''А'', ''Б'', ''В'', ''Г'', ''Д'', ''Е'', ''З'', ''И'', ''Й'', ''К'', ''Л'', ''М'', ''Н'', ''О'', ''П'', ''Р'', ''С'', ''Т'', ''У'', ''Ф'', ''Ь'');
$lat = array(
''yo'', ''zh'', ''kh'', ''ts'', ''ch'', ''shh'', ''sh'', ''``'', ''eh'', ''yu'', ''ya'', ''a'', ''b'', ''v'', ''g'', ''d'', ''e'', ''z'', ''i'', ''j'', ''k'', ''l'', ''m'', ''n'', ''o'', ''p'', ''r'', ''s'', ''t'', ''u'', ''f'', ''`'',
''Yo'', ''Zh'', ''Kh'', ''Ts'', ''Ch'', ''Shh'', ''Sh'', ''``'', ''Eh'', ''Yu'', ''Ya'', ''A'', ''B'', ''V'', ''G'', ''D'', ''E'', ''Z'', ''I'', ''J'', ''K'', ''L'', ''M'', ''N'', ''O'', ''P'', ''R'', ''S'', ''T'', ''U'', ''F'', ''`'');
if($textcyr)
return str_replace($cyr, $lat, $textcyr);
else if($textlat)
return str_replace($lat, $cyr, $textlat);
else
return null;
}
Esta es una función que uso para limpiar caracteres en bosnio, croata, serbio latino
function cleanUTF($name){
$name = str_replace(array(''š'',''č'',''đ'',''č'',''ć'',''ž'',''ñ''),array(''s'',''c'',''d'',''c'',''c'',''z'',''n''), $name);
$name = str_replace(array(''Š'',''Č'',''Đ'',''Č'',''Ć'', ''Ž'',''Ñ''),array(''S'',''C'',''D'',''C'',''C'',''Z'',''N''), $name);
$name = str_replace(array(''а'',''б'',''в'',''г'',''д'',''е'',''ё'',''ж'',''з'',''и'',''й'',''к'',''л'',''љ'',''м'',''н'',''њ'',''о'',''п'',''р'',''с'',''т'',''у'',''ф'',''х'',''ц'',''ч'',''џ'',''ш'',''щ'',''ъ'',''ы'',''ь'',''э'',''ю'',''я'',''А'',''Б'',''В'',''Г'',''Д'',''Е'',''Ё'',''Ж'',''З'',''И'',''Й'',''К'',''Л'',''Љ'',''М'',''Н'',''Њ'',''О'',''П'',''Р'',''С'',''Т'',''У'',''Ф'',''Х'',''Ц'',''Ч'',''Џ'',''Ш'',''Щ'',''Ъ'',''Ы'',''Ь'',''Э'',''Ю'',''Я''),
array(''a'',''b'',''v'',''g'',''d'',''e'',''e'',''z'',''z'',''i'',''j'',''k'',''l'',''lj'',''m'',''n'',''nj'',''o'',''p'',''r'',''s'',''t'',''u'',''f'',''h'',''c'',''c'',''dz'',''s'',''s'',''i'',''j'',''j'',''e'',''ju'',''ja'',''A'',''B'',''V'',''G'',''D'',''E'',''E'',''Z'',''Z'',''I'',''J'',''K'',''L'',''Lj'',''M'',''N'',''Nj'',''O'',''P'',''R'',''S'',''T'',''U'',''F'',''H'',''C'',''C'',''Dz'',''S'',''S'',''I'',''J'',''J'',''E'',''Ju'',''Ja''), $name);
return $name;
}
Este funcionó mejor para mí. El código es de esta página.
function ru2lat($str)
{
$tr = array(
"А"=>"a", "Б"=>"b", "В"=>"v", "Г"=>"g", "Д"=>"d",
"Е"=>"e", "Ё"=>"yo", "Ж"=>"zh", "З"=>"z", "И"=>"i",
"Й"=>"j", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n",
"О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t",
"У"=>"u", "Ф"=>"f", "Х"=>"kh", "Ц"=>"ts", "Ч"=>"ch",
"Ш"=>"sh", "Щ"=>"sch", "Ъ"=>"", "Ы"=>"y", "Ь"=>"",
"Э"=>"e", "Ю"=>"yu", "Я"=>"ya", "а"=>"a", "б"=>"b",
"в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"yo",
"ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k",
"л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p",
"р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f",
"х"=>"kh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch",
"ъ"=>"", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu",
"я"=>"ya", " "=>"-", "."=>"", ","=>"", "/"=>"-",
":"=>"", ";"=>"","—"=>"", "–"=>"-"
);
return strtr($str,$tr);
}
Espero que esto ayude a alguien.
Intenta seguir el código
$textcyr="Тествам с кирилица";
$textlat="I pone dotuk raboti!";
$cyr = [
''а'',''б'',''в'',''г'',''д'',''е'',''ё'',''ж'',''з'',''и'',''й'',''к'',''л'',''м'',''н'',''о'',''п'',
''р'',''с'',''т'',''у'',''ф'',''х'',''ц'',''ч'',''ш'',''щ'',''ъ'',''ы'',''ь'',''э'',''ю'',''я'',
''А'',''Б'',''В'',''Г'',''Д'',''Е'',''Ё'',''Ж'',''З'',''И'',''Й'',''К'',''Л'',''М'',''Н'',''О'',''П'',
''Р'',''С'',''Т'',''У'',''Ф'',''Х'',''Ц'',''Ч'',''Ш'',''Щ'',''Ъ'',''Ы'',''Ь'',''Э'',''Ю'',''Я''
];
$lat = [
''a'',''b'',''v'',''g'',''d'',''e'',''io'',''zh'',''z'',''i'',''y'',''k'',''l'',''m'',''n'',''o'',''p'',
''r'',''s'',''t'',''u'',''f'',''h'',''ts'',''ch'',''sh'',''sht'',''a'',''i'',''y'',''e'',''yu'',''ya'',
''A'',''B'',''V'',''G'',''D'',''E'',''Io'',''Zh'',''Z'',''I'',''Y'',''K'',''L'',''M'',''N'',''O'',''P'',
''R'',''S'',''T'',''U'',''F'',''H'',''Ts'',''Ch'',''Sh'',''Sht'',''A'',''I'',''Y'',''e'',''Yu'',''Ya''
];
$textcyr = str_replace($cyr, $lat, $textcyr);
$textlat = str_replace($lat, $cyr, $textlat);
echo("$textcyr $textlat");
La mejor opción es usar PHP Intl Extension. Es posible que desee instalarlo primero.
Esto hará el truco:
$transliteratedString = transliterator_transliterate(''Russian-Latin/BGN'', $cyrillicString);
Apliqué ''Russian-Latin / BGN'' porque el autor de la pregunta usó el idioma ruso en su pregunta. Sin embargo, hay opciones para otros idiomas escritos en el guión cirílico. Para ver todos ellos haz esto:
print_r(transliterator_list_ids());
Para mi la mejor solución fue usar.
strtr("Информация",array(''И''=>''I'',''н''=>''n'',''ф''=>''f'', ...and so on... ))
Respetando las reglas de transliteración de Yandex ( http://www.translityandex.ru/ ) y convirtiendo las mayúsculas:
function translit_russian_filenames( $filename ) {
$info = pathinfo( $filename );
$ext = empty( $info[''extension''] ) ? '''' : ''.'' . $info[''extension''];
$name = basename( $filename, $ext );
$cyr = array(
''а'', ''б'', ''в'', ''г'', ''д'', ''е'', ''ё'', ''ж'', ''з'', ''и'', ''й'', ''к'', ''л'', ''м'', ''н'', ''о'', ''п'', ''р'', ''с'', ''т'', ''у'', ''ф'', ''х'', ''ц'', ''ч'', ''ш'', ''щ'', ''ъ'', ''ы'', ''ь'', ''э'', ''ю'', ''я'',
''А'', ''Б'', ''В'', ''Г'', ''Д'', ''Е'', ''Ё'', ''Ж'', ''З'', ''И'', ''Й'', ''К'', ''Л'', ''М'', ''Н'', ''О'', ''П'', ''Р'', ''С'', ''Т'', ''У'', ''Ф'', ''Х'', ''Ц'', ''Ч'', ''Ш'', ''Щ'', ''Ъ'', ''ы'', ''Ь'', ''Э'', ''Ю'', ''Я'' );
$lat = array(
''a'', ''b'', ''v'', ''g'', ''d'', ''e'', ''yo'', ''zh'', ''z'', ''i'', ''y'', ''k'', ''l'', ''m'', ''n'', ''o'', ''p'', ''r'', ''s'', ''t'', ''u'', ''f'', ''h'', ''c'', ''ch'', ''sh'', ''shch'', '''', ''y'', '''', ''e'', ''yu'', ''ya'',
''a'', ''b'', ''v'', ''g'', ''d'', ''e'', ''yo'', ''zh'', ''z'', ''i'', ''y'', ''k'', ''l'', ''m'', ''n'', ''o'', ''p'', ''r'', ''s'', ''t'', ''u'', ''f'', ''h'', ''c'', ''ch'', ''sh'', ''shch'', '''', ''y'', '''', ''e'', ''yu'', ''ya'');
$name_translit = str_replace($cyr, $lat, $name);
return $name_translit . $ext;
}
add_filter( ''sanitize_file_name'', ''translit_russian_filenames'', 10 );
$textcyr = ''Њушка Ћушка Љубав Ђато ђата части '';
$textlat = ''Ljubav njuška džoša Džoša'';
$textlat = str_replace("nj","њ",$textlat);
$textlat = str_replace("Nj","Њ",$textlat);
$textlat = str_replace("lj","љ",$textlat);
$textlat = str_replace("Lj","Љ",$textlat);
$textlat = str_replace("dž","џ",$textlat);
$textlat = str_replace("Dž","Џ",$textlat);
$textcyr = str_replace($cyr, $lat, $textcyr);
$textlat = str_replace($lat, $cyr, $textlat);
echo $textcyr;
echo $textlat;
$textcyr="Тест на кирилице";
$textlat="Test na kirilitse!";
$cyr = array(''а'',''б'',''в'',''г'',''д'',''е'',''ё'',''ж'',''з'',''и'',''й'',''к'',''л'',''м'',''н'',''о'',''п'',''р'',''с'',''т'',''у'',
''ф'',''х'',''ц'',''ч'',''ш'',''щ'',''ъ'', ''ы'',''ь'', ''э'', ''ю'',''я'',''А'',''Б'',''В'',''Г'',''Д'',''Е'',''Ж'',''З'',''И'',''Й'',''К'',''Л'',''М'',''Н'',''О'',''П'',''Р'',''С'',''Т'',''У'',
''Ф'',''Х'',''Ц'',''Ч'',''Ш'',''Щ'',''Ъ'', ''Ы'',''Ь'', ''Э'', ''Ю'',''Я'' );
$lat = array( ''a'',''b'',''v'',''g'',''d'',''e'',''io'',''zh'',''z'',''i'',''y'',''k'',''l'',''m'',''n'',''o'',''p'',''r'',''s'',''t'',''u'',
''f'' ,''h'' ,''ts'' ,''ch'',''sh'' ,''sht'' ,''a'', ''i'', ''y'', ''e'' ,''yu'' ,''ya'',''A'',''B'',''V'',''G'',''D'',''E'',''Zh'',
''Z'',''I'',''Y'',''K'',''L'',''M'',''N'',''O'',''P'',''R'',''S'',''T'',''U'',
''F'' ,''H'' ,''Ts'' ,''Ch'',''Sh'' ,''Sht'' ,''A'' ,''Y'' ,''Yu'' ,''Ya'' );
$textcyr = str_replace($cyr, $lat, $textcyr);
$textlat = str_replace($lat, $cyr, $textlat);
echo("$textcyr $textlat");
faltan ё, э, ы (Э, Ы, Ё) letras