You are here

function lingotek_lang_icons in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.bulk_grid.inc \lingotek_lang_icons()
  2. 7.4 lingotek.bulk_grid.inc \lingotek_lang_icons()
  3. 7.5 lingotek.bulk_grid.inc \lingotek_lang_icons()
2 calls to lingotek_lang_icons()
lingotek_bulk_grid_parse_config_data in ./lingotek.config.inc
lingotek_bulk_grid_parse_table_data in ./lingotek.bulk_grid.inc

File

./lingotek.bulk_grid.inc, line 1826

Code

function lingotek_lang_icons($entity_type, $languages, $entity_id, $locale_statuses = array(), $disabled = FALSE, $source_language = NULL, $allow_source_overwriting = FALSE, $allow_target_localization = FALSE, $non_lingotek_config_translations = array()) {
  $icons = array();
  $legend = array(
    LingotekSync::STATUS_PENDING => t('In progress'),
    LingotekSync::STATUS_READY => t('Ready to download'),
    LingotekSync::STATUS_CURRENT => t('Current'),
    LingotekSync::STATUS_EDITED => t('Not current'),
    LingotekSync::STATUS_UNTRACKED => t('Untracked'),
    LingotekSync::STATUS_TARGET_LOCALIZE => t('Pending localization'),
    LingotekSync::STATUS_TARGET_EDITED => t('Needs to be uploaded'),
    LingotekSync::STATUS_NON_LINGOTEK => t('Non-Lingotek Translation'),
    '',
  );
  $default_link = 'lingotek/workbench/' . $entity_type . '/' . $entity_id . '/';
  $manual_link = $entity_type . '/' . $entity_id . '/lingotek_pm/';
  $untracked_link = 'lingotek/view/' . $entity_type . '/' . $entity_id . '/';
  $untracked_config_link = 'admin/' . $entity_type . '/regional/translate/edit/' . $entity_id . '/';
  $link_map = array(
    LingotekSync::STATUS_PENDING => $default_link,
    LingotekSync::STATUS_READY => $default_link,
    LingotekSync::STATUS_CURRENT => $default_link,
    LingotekSync::STATUS_EDITED => $default_link,
    LingotekSync::STATUS_UNTRACKED => $untracked_link,
    LingotekSync::STATUS_TARGET_LOCALIZE => $untracked_link,
    LingotekSync::STATUS_TARGET_EDITED => $untracked_link,
    LingotekSync::STATUS_NON_LINGOTEK => $untracked_config_link,
  );
  $lingotek_languages = Lingotek::getLanguages();
  foreach ($locale_statuses as $locale => $locale_status) {

    // if it's lingotek enabled
    if (array_key_exists($locale, $lingotek_languages)) {

      // could this ever be false? I thought all $lingotek_languages would be enabled
      $locale_enabled = $lingotek_languages[$locale]->lingotek_enabled;

      //array_key_exists($locale, $lingotek_languages) ? $lingotek_languages[$locale]->lingotek_enabled : FALSE;
      $lang_code = $lingotek_languages[$locale]->language;
      $lingotek_locale = $lingotek_languages[$locale]->lingotek_locale;
      if (!$allow_source_overwriting && !is_null($source_language) && $lang_code === $source_language) {
        continue;

        // hide source language targets (shouldn't exist anyways)
      }
      if ($locale_enabled) {

        // exclude language translations that are not lingotek_enabled (we may consider showing everything later)
        $status = strtoupper($locale_status);
        $status = $disabled && strtoupper($status) != LingotekSync::STATUS_CURRENT ? LingotekSync::STATUS_UNTRACKED : $status;

        // styling for the icons based on status and whether the translation is owned by Lingotek or not
        if ($entity_type == 'config' && (array_key_exists($entity_id, $non_lingotek_config_translations) && in_array($lang_code, explode(',', $non_lingotek_config_translations[$entity_id]->language_codes)))) {
          $css_classes = 'target-non-lingotek';
          $status = 'NON_LINGOTEK';
          $tip = $languages[$lang_code]->name . ' - ' . $legend[$status];
        }
        else {

          //styling for all icons except Config/NON_LINGOTEK items
          $css_classes = 'target-' . strtolower($status);
          $css_classes .= $disabled ? ' target-disabled' : '';
          $tip = $languages[$lang_code]->name . ' - ' . $legend[$status];
          $status = $disabled ? LingotekSync::STATUS_UNTRACKED : $status;

          // all disabled entities should link to view page (not workbench)
        }

        // link redirects to the translate interface for the config string rather than the Lingotek workbench if is an untracked config item
        if ($entity_type == 'config' && $status == LingotekSync::STATUS_UNTRACKED) {
          $current_icon = l($lang_code, $untracked_config_link . $lingotek_locale, array(
            'attributes' => array(
              'target' => '_blank',
              'title' => $tip,
              'class' => array(
                'language-icon',
                $css_classes,
              ),
            ),
          ));
        }
        else {
          $current_icon = l($lang_code, $link_map[$status] . $lingotek_locale, array(
            'attributes' => array(
              'target' => '_blank',
              'title' => $tip,
              'class' => array(
                'language-icon',
                $css_classes,
              ),
            ),
          ));
        }
        if (!is_null($source_language) && $lang_code === $source_language) {
          $icons['source'] = $current_icon;
        }
        else {
          $icons[$lang_code] = $current_icon;
        }
      }
    }
  }
  return $icons;
}