You are here

function lingotek_cleanup_message_types in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.util.inc \lingotek_cleanup_message_types()
  2. 7.5 lingotek.util.inc \lingotek_cleanup_message_types()

Set all message types with empty or undefined languages to be the site's default language

File

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

Code

function lingotek_cleanup_message_types() {
  $default_lang = lingotek_get_source_language();
  $def_lang_name = language_default('name');
  $message_types = message_type_load();
  $disabled_types = lingotek_get_disabled_bundles('message_type');
  $missing_lang = 0;
  $und_lang = 0;
  foreach ($message_types as $mt) {
    if (in_array($mt->category, $disabled_types)) {

      // Lingotek does not manage this message type category.  Abort.
      continue;
    }
    if (!$mt->language || $mt->language == LANGUAGE_NONE) {
      if (!$mt->language) {
        $missing_lang++;
      }
      elseif ($mt->language == LANGUAGE_NONE) {
        $und_lang++;
      }
      $mte = lingotek_entity_load_single('message_type', $mt->id);
      $mte->language = $default_lang;
      message_type_save($mte);
    }
  }
  if ($missing_lang) {
    drupal_set_message(format_plural($missing_lang, t('Set 1 message type with missing language to @lang.', array(
      '@lang' => $def_lang_name,
    )), t('Set @count message types with missing languages to @lang.', array(
      '@count' => $missing_lang,
      '@lang' => $def_lang_name,
    ))));
  }
  if ($und_lang) {
    drupal_set_message(format_plural($und_lang, t('Set 1 language-neutral message type to @lang.', array(
      '@lang' => $def_lang_name,
    )), t('Set @count language-neutral message types to @lang.', array(
      '@count' => $und_lang,
      '@lang' => $def_lang_name,
    ))));
  }
  if (!$missing_lang && !$und_lang) {
    drupal_set_message(t('All message types were already correctly set to a specific language.'));
  }
}