You are here

function lingotek_add_target_language in Lingotek Translation 7.7

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

Adds the target language as being enabled.

2 calls to lingotek_add_target_language()
LingotekTestCase::testEnterpriseSetup in tests/lingotek.setup.test
lingotek_dashboard_command_ajax in ./lingotek.dashboard.inc
Ajax Command Processing for the Lingotek dashboard.

File

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

Code

function lingotek_add_target_language($lingotek_locale, $call_api = TRUE) {
  LingotekConfigSet::markLidsNotCurrent('all');
  if (is_null($lingotek_locale)) {
    return FALSE;
  }
  lingotek_add_missing_locales(FALSE);

  // fills in any missing lingotek_locale values to the languages table
  $language = lingotek_lookup_language_by_locale($lingotek_locale);
  if ($language) {

    // ALREADY EXISTS IN LANGUAGE TABLE
    // If already in the languages table then just tack on the lingotek_locale and enable it
    $drupal_language_code = $language->language;
  }
  else {

    // DOES NOT EXIST, INSERT NEW INTO LANGUAGE TABLE
    // If not add it to the languages table first and then tack on the lingotek_locale and enable it
    $drupal_language_code = Lingotek::convertLingotek2Drupal($lingotek_locale, FALSE);
    $predefined_languages = array();
    if (module_exists('locale')) {
      $predefined_languages = _locale_prepare_predefined_list();
    }
    $drupal_code_with_locale = strtolower(str_replace("_", "-", $lingotek_locale));

    // Use a predefined Drupal language code, if available
    if (array_key_exists($drupal_code_with_locale, $predefined_languages)) {
      $drupal_language_code = $drupal_code_with_locale;
    }
    if (lingotek_lookup_locale_exists($drupal_language_code)) {

      // drupal code is already being used, generate another
      $errors = array(
        $drupal_language_code,
      );
      $drupal_language_code = $drupal_code_with_locale;
      if (lingotek_lookup_locale_exists($drupal_language_code)) {

        // The locale was used, but we can still try to add one.
        $drupal_language_code = $drupal_language_code . rand(1, 100);
        $errors[] = $drupal_language_code;
        LingotekLog::warning("Added language code !langcode.  Attempted language codes already being used: !errors", array(
          '!langcode' => $drupal_language_code,
          '!errors' => $errors,
        ));

        // return FALSE; // do not add the language.
      }
    }
    $prefix = lingotek_create_path_prefix($drupal_language_code);
    $name = isset($_POST['language']) ? $_POST['language'] : NULL;
    $native = isset($_POST['native']) ? $_POST['native'] : NULL;
    $direction = isset($_POST['direction']) && strcasecmp('RTL', $_POST['direction']) == 0 ? LANGUAGE_RTL : LANGUAGE_LTR;
    $domain = '';
    locale_add_language($drupal_language_code, $name, $native, $direction, $domain, $prefix);

    // Function from the Locale module.
  }
  return lingotek_set_target_language($drupal_language_code, 1, $lingotek_locale, $call_api);
}