You are here

function tmgmt_i18n_string_get_strings in Translation Management Tool 7

Gets i18n strings for given type and label.

Parameters

string $type: i18n object type.

string $search_label: Label to search for.

string $target_language: Target language.

string $target_status: Target status.

Return value

array List of i18n strings data.

1 call to tmgmt_i18n_string_get_strings()
TMGMTI18nStringDefaultSourceUIController::overviewForm in sources/i18n_string/tmgmt_i18n_string.ui.inc

File

sources/i18n_string/tmgmt_i18n_string.module, line 42
Source plugin for the Translation Management system that handles i18n strings.

Code

function tmgmt_i18n_string_get_strings($type, $search_label = NULL, $target_language = NULL, $target_status = 'untranslated_or_outdated') {
  $info = i18n_object_info($type);
  $languages = drupal_map_assoc(array_keys(language_list()));
  $select = db_select('i18n_string', 'i18n_s');
  $select
    ->addTag('tmgmt_sources_search');
  $select
    ->addMetaData('plugin', 'i18n_string');
  $select
    ->addMetaData('type', $type);
  $select
    ->condition('i18n_s.textgroup', $info['string translation']['textgroup']);
  if (!empty($target_language) && in_array($target_language, $languages)) {
    if ($target_status == 'untranslated_or_outdated') {
      $or = db_or();
      $or
        ->isNull("lt_{$target_language}.language");
      $or
        ->condition("lt_{$target_language}.i18n_status", I18N_STRING_STATUS_UPDATE);
      $select
        ->condition($or);
    }
    elseif ($target_status == 'outdated') {
      $select
        ->condition("lt_{$target_language}.i18n_status", I18N_STRING_STATUS_UPDATE);
    }
    elseif ($target_status == 'untranslated') {
      $select
        ->isNull("lt_{$target_language}.language");
    }
  }
  if (isset($info['string translation']['type'])) {
    $select
      ->condition('i18n_s.type', $info['string translation']['type']);
  }
  elseif ($type == 'field' || $type == 'field_instance') {

    // Fields and field instances share the same textgroup. Use list of bundles
    // to include/exclude field_instances.
    $bundles = array();
    foreach (entity_get_info() as $entity_info) {
      $bundles = array_merge($bundles, array_keys($entity_info['bundles']));
    }
    $select
      ->condition('i18n_s.objectid', $bundles, $type == 'field_instance' ? 'IN' : 'NOT IN');
  }
  $select
    ->join('locales_source', 'ls', 'ls.lid = i18n_s.lid');
  $select
    ->addField('ls', 'source');
  if (!empty($search_label)) {
    $select
      ->condition('ls.source', "%{$search_label}%", 'LIKE');
  }
  foreach ($languages as $langcode) {
    $langcode = str_replace('-', '', $langcode);
    $select
      ->leftJoin('locales_target', "lt_{$langcode}", "i18n_s.lid = %alias.lid AND %alias.language = '{$langcode}'");
    $select
      ->addField("lt_{$langcode}", 'language', "lang_{$langcode}");
  }
  $select
    ->fields("i18n_s", array(
    'lid',
    'textgroup',
    'context',
    'type',
    'objectid',
  ));
  $select
    ->addExpression("concat(i18n_s.textgroup, ':', i18n_s.type, ':', i18n_s.objectid)", 'job_item_id');
  $select
    ->orderBy('i18n_s.context');
  $select
    ->groupBy('type');
  $select
    ->groupBy('objectid');
  $select = $select
    ->extend('PagerDefault')
    ->limit(variable_get('tmgmt_source_list_limit', 20));
  return $select
    ->execute()
    ->fetchAll();
}