You are here

function lingotek_set_target_language in Lingotek Translation 7.4

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.5 lingotek.util.inc \lingotek_set_target_language()
  5. 7.6 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 777
Utility functions.

Code

function lingotek_set_target_language($drupal_language_code, $lingotek_enable = 1, $lingotek_locale = NULL, $api_add = TRUE) {
  $result = FALSE;
  if (is_string($drupal_language_code) && strlen($drupal_language_code)) {
    $lingotek_locale = is_null($lingotek_locale) ? Lingotek::convertDrupal2Lingotek($drupal_language_code, FALSE) : $lingotek_locale;
    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,
    ));
    if ($lingotek_enable && $lingotek_locale && $api_add) {

      // Add the Target Language to the Lingotek Project.
      $api = LingotekApi::instance();
      $projects = LingotekSync::getSyncProjects();
      foreach ($projects as $project_id) {
        $result = $api
          ->addTranslationTarget(NULL, $project_id, $lingotek_locale);
      }
    }
  }
  return $result;
}