Documentation

translit

result_type
CUtil::translit(
 string str,
 string lang,
 array params ()
);

The method transliterates a text string. Static method.

Parameters

Parameter Description
str Text string to be transliterated
lang Source language to be transliterated
params Array of parameters:
  • max_len - limit for characters, default - 100
  • change_case - upper and lower case conversion: L - lower case, U - upper case, false - do not change. Default value - "L"
  • replace_space - space bar replacement. Default value: "_"
  • replace_other - replacements for other characters. Default value: "_"
  • delete_repeat_replace - deletes duplicated spaces. "True" by default
  • safe_chars - string of characters that are not replaced

You can access and configure the dictionary with transliterations for each language available in the system inside the file /main/lang//js_core_translit.php, where [LANG]- language ID.

TRANS_FROM - list of characters subject to transliteration.

List of characters must be listed in the alphabetic order in both upper and lower cases (first lower and then upper case), separated by commas and without space bars.

TRANS_TO - list of characters used for replacement.

Example for German language:

  • $MESS["TRANS_FROM"] = "ä,ö,ß,ü,Ä,Ö,ß,Ü";
  • $MESS["TRANS_TO"] = "ae,oe,ss,ue,AE,OE,SS,UE";

Example for Polish language:

  • $MESS["TRANS_FROM"] = "ą,ć,ę,ł,ń,ó,ś,ź,ż,Ą,Ć,Ę,Ł,Ń,Ó,Ś,Ź,Ż";
  • $MESS["TRANS_TO"] = "a,c,e,l,n,o,s,z,z,A,C,E,L,N,O,S,Z,Z";

In case such match is not set, unique language characters are replaced with the symbol "-" in the generated URL.

Example

<?
$name = "Text*89";
$arParams = array("replace_space"=>"-","replace_other"=>"-");
$trans = Cutil::translit($name,"en",$arParams);
echo '<pre>';
var_dump($trans);
echo '</pre>';
?>


© «Bitrix24», 2001-2024
Up