Menu

#26 Request - transliteration

open
nobody
None
5
2012-06-07
2010-08-17
Anonymous
No

//It will be nice to have a transliteration function to display ciryllic to latin. Here is Bulgarian transliteration for lang=bg-BG
//
// Make sure the file "translations.inc.php" is in UTF-8

function transliteration($string) {

$table = array(
'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d',
'е'=>'e', 'ж'=>'j', 'з'=>'z', 'и'=>'i', 'й'=>'y',
'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o',
'п'=>'p', 'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u',
'ф'=>'f', 'х'=>'h', 'ц'=>'c', 'ч'=>'ch', 'ш'=>'sh',
'щ'=>'sht', 'ъ'=>'a', 'ь'=>'', 'ю'=>'yu', 'я'=>'ya',
'А'=>'A', 'Б'=>'B', 'В'=>'V', 'Г'=>'G', 'Д'=>'D',
'Е'=>'E', 'Ж'=>'J', 'З'=>'Z', 'И'=>'I', 'Й'=>'Y',
'К'=>'K', 'Л'=>'L', 'М'=>'M', 'Н'=>'N', 'О'=>'O',
'П'=>'P', 'Р'=>'R', 'С'=>'S', 'Т'=>'T', 'У'=>'U',
'Ф'=>'F', 'Х'=>'H', 'Ц'=>'C', 'Ч'=>'Ch', 'Ш'=>'Sh',
'Щ'=>'Sht', 'Ъ'=>'A', 'Ь'=>'', 'Ю'=>'Yu', 'Я'=>'Ya',
);

return strtr($string, $table);

}

// then in index.php we can add $lang from translations.inc.php and use something like

if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$http_accept_language = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
} else {
$http_accept_language = "";
}

foreach(explode(',', $http_accept_language) as $accept_lang) {
$accepted_languages[] = substr($accept_lang, 0, 2);
}

foreach($accepted_languages as $curr_lang)
{
if( array_search($curr_lang, $supported_langs) !== FALSE ) {
$lang = $curr_lang;
break;
}
}

if ($lang != 'bg') {
$firstname = transliteration($firstname);
$lastname = transliteration($lastname);
}

Discussion

  • chatelao

    chatelao - 2010-08-17

    Hi,
    Which languages would you like to transliterate to which languages?
    Regards
    Olivier

     
  • Nobody/Anonymous

    For my use i already tranliterate Bulgarian ciryllic -> Latin. Using this code.
    All countries have a different transliteration letter maps. here is some of them http://translit.cc/

    I only post this if someone else need it.
    It will be good the diferent translation files to have own letter mappings and to have a option in config to enable/disable this feature.

    Regards.
    Vladislav

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.