You are here

function _transliteration_replace in Transliteration 6.2

Same name and namespace in other branches
  1. 5.2 transliteration.inc \_transliteration_replace()
  2. 5 transliteration.inc \_transliteration_replace()
  3. 6.3 transliteration.inc \_transliteration_replace()
  4. 6 transliteration.inc \_transliteration_replace()
  5. 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.

$langcode: 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 211

Code

function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) {
  if (!isset($langcode)) {
    global $language;
    $langcode = $language->language;
  }
  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 language specific alterations
  if (!isset($map[$bank][$langcode])) {
    if ($langcode != 'en' && isset($template[$bank][$langcode])) {

      // Merge language specific mappings with the default transliteration table
      $map[$bank][$langcode] = $template[$bank][$langcode] + $template[$bank]['en'];
    }
    else {
      $map[$bank][$langcode] = $template[$bank]['en'];
    }
  }
  $ord = $ord & 255;
  return isset($map[$bank][$langcode][$ord]) ? $map[$bank][$langcode][$ord] : $unknown;
}