function _transliteration_replace in Transliteration 5.2
Same name and namespace in other branches
- 5 transliteration.inc \_transliteration_replace()
- 6.3 transliteration.inc \_transliteration_replace()
- 6 transliteration.inc \_transliteration_replace()
- 6.2 transliteration.inc \_transliteration_replace()
- 7.3 transliteration.inc \_transliteration_replace()
Load the transliteration database and replace a Unicode character.
Parameters
$ord: A ordinal Unicode character code.
$unknown: Replacement string for characters that do not have a suitable ASCII equivalent.
$locale: Optional ISO 639 language code that denotes the language of the input. Used to apply language-specific optimizations. Defaults to the current display language.
Return value
ASCII replacement character.
1 call to _transliteration_replace()
- transliteration_process in ./
transliteration.inc - Transliterate UTF-8 text to ASCII.
File
- ./
transliteration.inc, line 205
Code
function _transliteration_replace($ord, $unknown = '?', $locale = NULL) {
if (!isset($locale)) {
global $locale;
}
static $map = array(), $template = array();
$bank = $ord >> 8;
// Check if we need to load a new bank
if (!isset($template[$bank])) {
$file = drupal_get_path('module', 'transliteration') . '/data/' . sprintf('x%02x', $bank) . '.php';
if (file_exists($file)) {
$template[$bank] = (include $file);
}
else {
$template[$bank] = array(
'en' => array(),
);
}
}
// Check if we need to create new mappings with locale specific alterations
if (!isset($map[$bank][$locale])) {
if ($locale != 'en' && isset($template[$bank][$locale])) {
// Merge locale specific mappings with the default transliteration table
$map[$bank][$locale] = $template[$bank][$locale] + $template[$bank]['en'];
}
else {
$map[$bank][$locale] = $template[$bank]['en'];
}
}
$ord = $ord & 255;
return isset($map[$bank][$locale][$ord]) ? $map[$bank][$locale][$ord] : $unknown;
}