function lingotek_lang_icons in Lingotek Translation 7.7
Same name and namespace in other branches
- 7.4 lingotek.bulk_grid.inc \lingotek_lang_icons()
- 7.5 lingotek.bulk_grid.inc \lingotek_lang_icons()
- 7.6 lingotek.bulk_grid.inc \lingotek_lang_icons()
2 calls to lingotek_lang_icons()
File
- ./
lingotek.bulk_grid.inc, line 2750
Code
function lingotek_lang_icons($entity_type, $entity_id, $document_id, $entity_profile = NULL, $locale_statuses = array(), $disabled = FALSE, $source_language = NULL, $allow_source_overwriting = FALSE, $allow_target_localization = FALSE, $non_lingotek_config_translations = array()) {
if ($entity_type == 'group') {
$source_language = lingotek_get_group_source($entity_id);
}
if ($entity_type == 'paragraphs_item') {
$source_language = lingotek_get_paragraphs_item_source($entity_id);
}
$icons = array();
$legend = array(
LingotekSync::STATUS_NONE => t('No Translation'),
LingotekSync::STATUS_ARCHIVED => t('The document was archived.'),
LingotekSync::STATUS_GONE => t('The target/document was deleted or archived.'),
LingotekSync::STATUS_PENDING => t('In-Progress'),
LingotekSync::STATUS_READY => t('Ready for Download'),
LingotekSync::STATUS_CURRENT => t('Current'),
LingotekSync::STATUS_READY_INTERIM => t('Ready for Interim Download'),
LingotekSync::STATUS_INTERIM => t('In-progress (interim translation downloaded)'),
LingotekSync::STATUS_EDITED_INTERIM => t('In-progress, edited-source (interim translation downloaded)'),
LingotekSync::STATUS_EDITED => t('Source Edited'),
LingotekSync::STATUS_UNTRACKED => t('Translation exists, but it is not being tracked by Lingotek'),
LingotekSync::STATUS_TARGET_LOCALIZE => t('Pending localization'),
LingotekSync::STATUS_TARGET_EDITED => t('Needs to be uploaded'),
LingotekSync::STATUS_NON_LINGOTEK => t('Non-Lingotek Translation'),
LingotekSync::STATUS_ERROR => t('Error'),
);
$default_link = lingotek_get_workbench_url($document_id);
$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_ARCHIVED => $default_link,
LingotekSync::STATUS_GONE => $default_link,
LingotekSync::STATUS_READY => $default_link,
LingotekSync::STATUS_CURRENT => $default_link,
LingotekSync::STATUS_READY_INTERIM => $default_link,
LingotekSync::STATUS_INTERIM => $default_link,
LingotekSync::STATUS_EDITED => $default_link,
LingotekSync::STATUS_EDITED_INTERIM => $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,
LingotekSync::STATUS_ERROR => $untracked_link,
);
$lingotek_languages = Lingotek::getLanguages();
// Pull the desired target locales for the entity's current profile.
if (variable_get('lingotek_enable_language_specific_profiles', FALSE) && $entity_type != 'config') {
$profile = LingotekProfile::loadById($entity_profile);
$target_locales = $profile
->filterTargetLocales(array_keys($locale_statuses));
$locale_statuses = array_intersect_key($locale_statuses, $target_locales);
}
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;
$normalized_lingotek_locale = str_replace('_', '-', $lingotek_locale);
if (!$allow_source_overwriting && !is_null($source_language) && $lang_code === $source_language) {
continue;
// hide source language targets (shouldn't exist anyways)
}
$existing_translations = lingotek_get_languages($entity_type, $entity_id);
$has_translation = false;
foreach ($existing_translations as $language) {
$locale = Lingotek::convertDrupal2Lingotek($language);
if ($locale == $lingotek_locale) {
$has_translation = true;
}
}
if ($locale_enabled) {
// exclude language translations that are not lingotek_enabled (we may consider showing everything later)
$status = strtoupper($locale_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-untracked';
$status = LingotekSync::STATUS_UNTRACKED;
$tip = $legend[$status];
}
else {
//styling for all icons except Config/NON_LINGOTEK items
$css_classes = 'target-' . strtolower($status);
$tip = $legend[$status];
}
// 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 . $normalized_lingotek_locale, array(
'attributes' => array(
'target' => '_blank',
'lingotek_locale' => $lingotek_locale,
'title' => $tip,
'class' => array(
'language-icon',
$css_classes,
),
),
));
}
elseif ($status == LingotekSync::STATUS_ARCHIVED) {
$none_css_classes = 'language-icon ltk-target-gone';
$download_status = $has_translation ? 'was downloaded' : 'was not downloaded';
$none_tip = 'This target has been archived and the translation ' . $download_status . ' from Lingotek.';
$current_icon = '<span class = "' . $none_css_classes . '" title="' . $none_tip . '" lingotek_locale="' . $lingotek_locale . '">' . $lang_code . '</span>';
}
elseif ($status == LingotekSync::STATUS_GONE) {
$none_css_classes = 'language-icon ltk-target-gone';
$download_status = $has_translation ? 'was downloaded' : 'was not downloaded';
$none_tip = 'This target has been deleted and the translation ' . $download_status . ' from Lingotek.';
$current_icon = '<span class = "' . $none_css_classes . '" title="' . $none_tip . '" lingotek_locale="' . $lingotek_locale . '">' . $lang_code . '</span>';
}
elseif ($status == LingotekSync::STATUS_NONE) {
$none_css_classes = 'language-icon ltk-target-none';
$none_tip = 'No Translation';
$current_icon = '<span class = "' . $none_css_classes . '" title="' . $none_tip . '" lingotek_locale="' . $lingotek_locale . '">' . $lang_code . '</span>';
}
else {
$current_icon = l($lang_code, $link_map[$status] . $normalized_lingotek_locale, array(
'attributes' => array(
'target' => '_blank',
'lingotek_locale' => $lingotek_locale,
'title' => $tip,
'class' => array(
'language-icon',
$css_classes,
),
),
));
}
if ($disabled) {
$current_icon = '<span class="language-icon ltk-target-disabled" title="Disabled, cannot request translation" lingotek_locale="' . $lingotek_locale . '">' . $lang_code . '</span>';
}
if (!is_null($source_language) && $lang_code === $source_language) {
$icons['source'] = $current_icon;
}
else {
$icons[$lang_code] = $current_icon;
}
}
}
}
return $icons;
}