You are here

function lingotek_set_target_language in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.util.inc \lingotek_set_target_language()
  2. 7.2 lingotek.util.inc \lingotek_set_target_language()
  3. 7.3 lingotek.util.inc \lingotek_set_target_language()
  4. 7.4 lingotek.util.inc \lingotek_set_target_language()
  5. 7.5 lingotek.util.inc \lingotek_set_target_language()

Sets the extended target language locale in the languages table and whether or not it is enabled

Parameters

$drupal_language_code:

$lingotek_enable whether or not to enable the language on TMS (default: 1):

$lingotek_locale the lingotek locale that the drupal code should be associated with (it will try to pick the right one when not passed in):

$api_add boolean whether or not to add the language to all documents in the project (default: TRUE):

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

File

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

Code

function lingotek_set_target_language($drupal_language_code, $lingotek_enable = 1, $lingotek_locale = NULL, $api_add = TRUE) {
  $result = FALSE;
  $one_success = FALSE;

  //tracks if any result has been true
  $lingotek_locale = is_null($lingotek_locale) ? Lingotek::convertDrupal2Lingotek($drupal_language_code, FALSE) : $lingotek_locale;
  if (is_string($drupal_language_code) && strlen($drupal_language_code) && $lingotek_enable && $lingotek_locale && $api_add) {
    $api = LingotekApi::instance();
    $projects = LingotekSync::getSyncProjects();
    foreach ($projects as $project_id) {
      $result = $api
        ->addTranslationTarget(NULL, $project_id, $lingotek_locale);
      if ($result) {
        LingotekSync::insertTargetEntriesForAllEntities($lingotek_locale);
        LingotekSync::insertTargetEntriesForAllSets($lingotek_locale);
      }
      $one_success = $one_success || $result;
    }
    if ($one_success == TRUE) {
      db_update('languages')
        ->fields(array(
        'enabled' => 1,
        'lingotek_enabled' => $lingotek_enable ? 1 : 0,
        'lingotek_locale' => $lingotek_locale,
      ))
        ->condition('language', $drupal_language_code)
        ->execute();
      drupal_static_reset('language_list');
      LingotekLog::info("Target language added: @drupal_language_code (@lingotek_locale)", array(
        '@drupal_language_code' => $drupal_language_code,
        '@lingotek_locale' => $lingotek_locale,
      ));
    }
    else {
      drupal_set_message(t('@lingotek_locale could not be added as a language for Lingotek to translate.', array(
        '@lingotek_locale' => $lingotek_locale,
      )), 'error', FALSE);
      LingotekLog::error("Target language could not be added: @drupal_language_code (@lingotek_locale)", array(
        '@drupal_language_code' => $drupal_language_code,
        '@lingotek_locale' => $lingotek_locale,
      ));
    }
  }
  return $result;
}