You are here

function lingotek_admin_additional_translation_settings_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_additional_translation_settings_form()
  2. 7.3 lingotek.admin.inc \lingotek_admin_additional_translation_settings_form()
  3. 7.4 lingotek.admin.inc \lingotek_admin_additional_translation_settings_form()
  4. 7.5 lingotek.admin.inc \lingotek_admin_additional_translation_settings_form()

Additional translation form

1 call to lingotek_admin_additional_translation_settings_form()
lingotek_setup_additional_translation_settings_form in ./lingotek.setup.inc
1 string reference to 'lingotek_admin_additional_translation_settings_form'
lingotek_admin_configuration_view in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 649

Code

function lingotek_admin_additional_translation_settings_form($form, &$form_state, $show_fieldset = FALSE) {
  global $base_url;
  $api = LingotekApi::instance();
  $site = variable_get('site_name', 'Drupal Site');
  $setup_complete = !lingotek_is_config_missing();
  $account = LingotekAccount::instance();
  $show_advanced = $account
    ->showAdvanced();
  $title_str = $setup_complete ? t('Configuration Translation') : t('Which additional items do you want translated?');

  // Configuration translation (ie. taxonomies, menus, etc.)
  $form['additional_translation'] = array(
    '#type' => $show_fieldset ? 'fieldset' : 'item',
    '#title' => check_plain($title_str),
    //'#description' => t('Enable/disable and set defaults for comment translation.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
    'actions' => array(
      '#type' => 'actions',
      'submit' => array(
        '#type' => 'submit',
        '#value' => t('Save'),
      ),
    ),
    '#validate' => array(
      'lingotek_admin_additional_translation_settings_form_validate',
    ),
    '#submit' => array(
      'lingotek_admin_additional_translation_settings_form_submit',
    ),
  );
  $header = array(
    'Type',
    'Description',
  );
  $prep_blocks_chbx = array(
    '#id' => 'lingotek_prepare_config_blocks',
    '#type' => 'checkbox',
    '#title' => t('Update all blocks to be translatable in the Languages settings.'),
    '#attributes' => array(
      'id' => array(
        'lingotek_prepare_config_blocks',
      ),
      'name' => 'lingotek_prepare_config_blocks',
      'class' => array(
        'field',
      ),
    ),
    '#default_value' => 1,
  );
  $prep_taxonomy_chbx = array(
    '#id' => 'lingotek_prepare_config_taxonomies',
    '#type' => 'checkbox',
    '#title' => t('Update all taxonomy vocabularies that are not currently enabled for multilingual to use translation mode \'Localize\' in the Multilingual Options. (Note: Translation mode \'Localize\' does not support translation of custom fields within taxonomy terms.)'),
    '#attributes' => array(
      'id' => array(
        'lingotek_prepare_config_taxonomies',
      ),
      'name' => 'lingotek_prepare_config_taxonomies',
      'class' => array(
        'field',
      ),
    ),
    '#default_value' => 1,
  );
  $prep_menus_chbx = array(
    '#id' => 'lingotek_prepare_config_menus',
    '#type' => 'checkbox',
    '#title' => t('Update all menus to use \'Translate and Localize\' in the Multilingual Options.'),
    '#attributes' => array(
      'id' => array(
        'lingotek_prepare_config_menus',
      ),
      'name' => 'lingotek_prepare_config_menus',
      'class' => array(
        'field',
      ),
    ),
    '#default_value' => 1,
  );
  $hidden_i18nviews_value = array(
    '#id' => 'lingotek_i18nviews_enabled',
    '#type' => 'hidden',
    '#value' => module_exists('i18nviews'),
  );
  $options = array(
    'lingotek_translate_config_blocks' => array(
      t('Blocks'),
      t('Include translation for all translatable blocks.') . drupal_render($prep_blocks_chbx),
    ),
    'lingotek_translate_config_taxonomies' => array(
      t('Taxonomy'),
      t('Include translation for all translatable taxonomy vocabularies and terms.') . drupal_render($prep_taxonomy_chbx),
    ),
    'lingotek_translate_config_menus' => array(
      t('Menus'),
      t('Include translation for all menus set to \'Translate and Localize\'.') . drupal_render($prep_menus_chbx),
    ),
    'lingotek_translate_config_views' => array(
      t('Views'),
      t('Include translation of all translatable strings within views.  This will not generally include translation of all results generated by each view, which is usually configurable by selecting localizable fields within the view itself.  (Note: You must have the <a href="https://drupal.org/project/i18nviews" target="_blank">i18nviews</a> module enabled in order to use this.)') . drupal_render($hidden_i18nviews_value),
    ),
    'lingotek_translate_config_fields' => array(
      t('Field Labels'),
      t('Include translation of all translatable field labels.  (Note: You must have the <a href="https://drupal.org/project/i18n" target="_blank">i18n_field</a> sub-module enabled in order to use this.)'),
    ),
    'lingotek_translate_config_builtins' => array(
      t('Built-in Interface'),
      t('Include translation of built-in strings.  (Note: Indexing all of these may take several minutes or longer.)') . drupal_render($fr),
    ),
    'lingotek_translate_config_misc' => array(
      t('Miscellaneous Strings'),
      t('Include translation of any other miscellaneous strings found by the Internationalization (i18n) module.'),
    ),
  );
  $defaults = array();
  foreach (array_keys($options) as $config_type) {
    $defaults[$config_type] = variable_get($config_type, 0);
  }
  $form['additional_translation']['config'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#default_value' => $defaults,
  );
  $profiles = variable_get('lingotek_profiles');
  $config_profile = isset($profiles[LingotekSync::PROFILE_CONFIG]) ? $profiles[LingotekSync::PROFILE_CONFIG] : NULL;
  $workflows = $api
    ->listWorkflows();
  if ($config_profile) {
    if (is_array($workflows) && count($workflows) > 1 && $setup_complete) {
      $stored_profile = lingotek_get_profile_settings(LingotekSync::PROFILE_CONFIG);
      $stored_workflow_id = isset($stored_profile['workflow_id']) ? $stored_profile['workflow_id'] : '';
      $selected_workflow_id = isset($form_state['values']['addtl_workflow_id']) ? $form_state['values']['addtl_workflow_id'] : $stored_workflow_id;
      $curr_workflow = $api
        ->getWorkflow($stored_workflow_id);
      $num_config_docs = count(LingotekConfigSet::getAllDocumentIds());
      if (!empty($curr_workflow)) {

        // append the current workflow to the top of the workflow list, if it's not already there
        $workflows = array(
          $stored_workflow_id => $curr_workflow->name,
        ) + $workflows;
      }
      $form['additional_translation']['addtl_workflow_id'] = array(
        '#type' => 'select',
        '#title' => t('Workflow'),
        '#description' => t('This workflow will be used for handling these additional translation items.'),
        '#default_value' => $stored_workflow_id,
        '#options' => $workflows,
        '#ajax' => array(
          'callback' => 'lingotek_config_default_workflow_form_callback',
          'wrapper' => 'addtl-prefill-phases-div',
          'method' => 'replace',
          'effect' => 'fade',
        ),
        '#prefix' => '<div id="addtl-prefill-phases-div">',
      );
      $form['additional_translation']['addtl_prefill_phases_checkbox'] = array(
        '#type' => 'checkbox',
        '#title' => t('Change all current config content (@total documents in total) to use the new workflow', array(
          '@total' => $num_config_docs,
        )),
        '#default_value' => FALSE,
        '#description' => t('All current translations will be removed and recreated using the new workflow, with translations pulled from the previous workflow'),
        '#states' => array(
          'invisible' => array(
            ':input[name="addtl_workflow_id"]' => array(
              'value' => $stored_workflow_id,
            ),
          ),
        ),
      );
      $form['additional_translation']['addtl_prefill_phase_select'] = array(
        '#title' => t("Desired Prefill Phase"),
        '#description' => t('Please select the highest phase which should be prefilled for the new workflow'),
        '#type' => 'select',
        '#states' => array(
          'visible' => array(
            ':input[name="addtl_workflow_id"]' => array(
              '!value' => $stored_workflow_id,
            ),
            ':input[name="addtl_prefill_phases_checkbox"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
        '#suffix' => '</div>',
      );
      $form['additional_translation']['addtl_prefill_phase_select']['#options'] = lingotek_get_phases_by_workflow_id($selected_workflow_id);
    }

    // Projects
    $projects = class_exists('LingotekApi') ? $api
      ->listProjects() : array();
    $id = variable_get('lingotek_project', '');
    if ($id == '' || !array_key_exists($id, $projects)) {

      //No project id set, project deleted, or community changed to one without that project.  Try to find the Drupal project
      $id = array_search($site, $projects);
      if ($id === False) {

        //Setup a default Drupal project
        $id = lingotek_add_project($site);
        $projects = class_exists('LingotekApi') ? $api
          ->listProjects() : array();
      }
      else {

        //Assign to an existing Drupal project
        variable_set('lingotek_project', $id);
      }
    }
    if ($projects && count($projects) > 0 && $setup_complete) {
      $sorted = asort($projects);
      $form['additional_translation']['addtl_project_id'] = array(
        '#type' => 'select',
        '#title' => t('Default Project'),
        '#options' => $projects,
        '#description' => t('The default Lingotek Project with which translations will be associated.'),
        '#default_value' => isset($config_profile['project_id']) ? $config_profile['project_id'] : $id,
      );
    }

    // Vaults
    $vaults = $api
      ->listVaults();
    $current_vault_id = variable_get('lingotek_vault', '');
    $personal_vault_count = isset($vaults['Personal Vaults']) ? count($vaults['Personal Vaults']) : 0;
    $community_vault_count = isset($vaults['Community Vaults']) ? count($vaults['Community Vaults']) : 0;

    // If no vault id is set, and we don't have any personal vaults, then create one and add it to our project.
    if ($current_vault_id == '' && $personal_vault_count == 0 && $community_vault_count == 0) {
      $current_project_id = variable_get('lingotek_project', '');

      // But only if we have a ProjectID.
      if ($current_project_id != '') {
        $current_vault_id = lingotek_add_vault($site);
        lingotek_add_vault_to_project();
      }
    }
    if ($personal_vault_count + $community_vault_count > 0 && $setup_complete) {
      $form['additional_translation']['addtl_vault_id'] = array(
        '#type' => 'select',
        '#title' => t('Default Vault'),
        '#options' => $vaults,
        '#description' => t('The default Translation Memory Vault where translations are saved.'),
        '#default_value' => isset($config_profile['vault_id']) ? $config_profile['vault_id'] : $current_vault_id,
      );
    }
    $form['additional_translation']['lingotek_translate_config_options']['view_status'] = array(
      '#type' => 'item',
      '#description' => t('You can view the progress of the configuration translations on the <a href="@link">Translate Interface</a> page', array(
        '@link' => url('admin/settings/lingotek/manage/config'),
      )),
    );
  }
  $setup_complete = !lingotek_is_config_missing();
  if ($setup_complete) {
    $form['#action'] = url('admin/settings/lingotek/settings', array(
      'fragment' => 'ltk-config',
    ));
  }
  return $form;
}