You are here

function lingotek_create_path_prefix in Lingotek Translation 7.7

1 call to lingotek_create_path_prefix()
lingotek_add_target_language in ./lingotek.util.inc
Adds the target language as being enabled.

File

./lingotek.util.inc, line 1161
Utility functions.

Code

function lingotek_create_path_prefix($drupal_code) {
  $prefix = '';
  $prefix_without_hyphen = '';
  $prefix_with_hyphen = $drupal_code;

  // Create prefix without hyphen
  if (strpos($drupal_code, '-') !== FALSE) {
    $hyphen_pos = strpos($drupal_code, '-');
    $prefix_without_hyphen = substr($drupal_code, 0, $hyphen_pos);
  }
  else {
    $prefix_without_hyphen = $drupal_code;
  }
  $prefixes = db_select('languages', 'l')
    ->fields('l', array(
    'prefix',
  ))
    ->execute()
    ->fetchCol();

  // See if the path prefix without hyphen is already being used. If so, try prefix with hyphen
  $prefix_without_hyphen_used = FALSE;
  foreach ($prefixes as $prefix) {
    if ($prefix === $prefix_without_hyphen) {
      $prefix_without_hyphen_used = TRUE;
      break;
    }
  }
  if (!$prefix_without_hyphen_used) {
    $prefix = $prefix_without_hyphen;
  }

  // See if the path prefix with hyphen is already being used.
  $prefix_with_hyphen_used = FALSE;
  if ($prefix_without_hyphen_used) {
    foreach ($prefixes as $prefix) {
      if ($prefix === $drupal_code) {
        $prefix_with_hyphen_used = TRUE;
        break;
      }
    }
    if (!$prefix_with_hyphen_used) {
      $prefix = $prefix_with_hyphen;
    }
  }
  return $prefix;
}