summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/locale
diff options
context:
space:
mode:
authorTorsten Grote <grote@kolabsys.com>2014-01-29 15:00:00 (GMT)
committerTorsten Grote <grote@kolabsys.com>2014-01-29 15:00:00 (GMT)
commitd9e4a0f1b5f45b2e3fed0908a69dad264d40b15b (patch)
tree76d774e7d2ce4ba7c0754c590a6b730b6f6ceed9 /kolab.org/www/drupal-7.26/modules/locale
parent5145fb6b6b03f545d7b82db89850dac1b3b49d78 (diff)
downloadkolab.org-www-d9e4a0f1b5f45b2e3fed0908a69dad264d40b15b.tar.gz
add new drupal version
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/locale')
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale-rtl.css12
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.admin.inc1436
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.api.php41
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.css32
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.datepicker.js79
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.info13
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.install457
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.module1098
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/locale.test3143
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.js46
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.module242
-rw-r--r--kolab.org/www/drupal-7.26/modules/locale/tests/translations/test.xx.po28
13 files changed, 6639 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale-rtl.css b/kolab.org/www/drupal-7.26/modules/locale/locale-rtl.css
new file mode 100644
index 0000000..aaf1988
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale-rtl.css
@@ -0,0 +1,12 @@
+
+#locale-translation-filter-form .form-item-language,
+#locale-translation-filter-form .form-item-translation,
+#locale-translation-filter-form .form-item-group {
+ float: right;
+ padding-left: .8em;
+ padding-right: 0;
+}
+#locale-translation-filter-form .form-actions {
+ float: right;
+ padding: 3ex 1em 0 0;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.admin.inc b/kolab.org/www/drupal-7.26/modules/locale/locale.admin.inc
new file mode 100644
index 0000000..b736f79
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.admin.inc
@@ -0,0 +1,1436 @@
+<?php
+
+/**
+ * @file
+ * Administration functions for locale.module.
+ */
+
+/**
+ * @defgroup locale-language-administration Language administration interface
+ * @{
+ * Administration interface for languages.
+ *
+ * These functions provide the user interface to show, add, edit and
+ * delete languages as well as providing options for language negotiation.
+ */
+
+/**
+ * User interface for the language overview screen.
+ */
+function locale_languages_overview_form() {
+ drupal_static_reset('language');
+ $languages = language_list('language');
+
+ $options = array();
+ $form['weight'] = array('#tree' => TRUE);
+ foreach ($languages as $langcode => $language) {
+
+ $options[$langcode] = '';
+ if ($language->enabled) {
+ $enabled[] = $langcode;
+ }
+ $form['weight'][$langcode] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight for @title', array('@title' => $language->name)),
+ '#title_display' => 'invisible',
+ '#default_value' => $language->weight,
+ '#attributes' => array('class' => array('language-order-weight')),
+ );
+ $form['name'][$langcode] = array('#markup' => check_plain($language->name));
+ $form['native'][$langcode] = array('#markup' => check_plain($language->native));
+ $form['direction'][$langcode] = array('#markup' => ($language->direction == LANGUAGE_RTL ? t('Right to left') : t('Left to right')));
+ }
+ $form['enabled'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Enabled languages'),
+ '#title_display' => 'invisible',
+ '#options' => $options,
+ '#default_value' => $enabled,
+ );
+ $form['site_default'] = array(
+ '#type' => 'radios',
+ '#title' => t('Default language'),
+ '#title_display' => 'invisible',
+ '#options' => $options,
+ '#default_value' => language_default('language'),
+ );
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
+ $form['#theme'] = 'locale_languages_overview_form';
+
+ return $form;
+}
+
+/**
+ * Returns HTML for the language overview form.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - form: A render element representing the form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_languages_overview_form($variables) {
+ $form = $variables['form'];
+ $default = language_default();
+ foreach ($form['name'] as $key => $element) {
+ // Do not take form control structures.
+ if (is_array($element) && element_child($key)) {
+ // Disable checkbox for the default language, because it cannot be disabled.
+ if ($key == $default->language) {
+ $form['enabled'][$key]['#attributes']['disabled'] = 'disabled';
+ }
+
+ // Add invisible labels for the checkboxes and radio buttons in the table
+ // for accessibility. These changes are only required and valid when the
+ // form is themed as a table, so it would be wrong to perform them in the
+ // form constructor.
+ $title = drupal_render($form['name'][$key]);
+ $form['enabled'][$key]['#title'] = t('Enable !title', array('!title' => $title));
+ $form['enabled'][$key]['#title_display'] = 'invisible';
+ $form['site_default'][$key]['#title'] = t('Set !title as default', array('!title' => $title));
+ $form['site_default'][$key]['#title_display'] = 'invisible';
+ $rows[] = array(
+ 'data' => array(
+ '<strong>' . $title . '</strong>',
+ drupal_render($form['native'][$key]),
+ check_plain($key),
+ drupal_render($form['direction'][$key]),
+ array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'),
+ drupal_render($form['site_default'][$key]),
+ drupal_render($form['weight'][$key]),
+ l(t('edit'), 'admin/config/regional/language/edit/' . $key) . (($key != 'en' && $key != $default->language) ? ' ' . l(t('delete'), 'admin/config/regional/language/delete/' . $key) : '')
+ ),
+ 'class' => array('draggable'),
+ );
+ }
+ }
+ $header = array(array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Code')), array('data' => t('Direction')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations')));
+ $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'language-order')));
+ $output .= drupal_render_children($form);
+
+ drupal_add_tabledrag('language-order', 'order', 'sibling', 'language-order-weight');
+
+ return $output;
+}
+
+/**
+ * Process language overview form submissions, updating existing languages.
+ */
+function locale_languages_overview_form_submit($form, &$form_state) {
+ $languages = language_list();
+ $default = language_default();
+ $url_prefixes = variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX;
+ $enabled_count = 0;
+
+ foreach ($languages as $langcode => $language) {
+ if ($form_state['values']['site_default'] == $langcode || $default->language == $langcode) {
+ // Automatically enable the default language and the language
+ // which was default previously (because we will not get the
+ // value from that disabled checkbox).
+ $form_state['values']['enabled'][$langcode] = 1;
+ }
+
+ // If language URL prefixes are enabled we must clear language domains and
+ // assign a valid prefix to each non-default language.
+ if ($url_prefixes) {
+ $language->domain = '';
+ if (empty($language->prefix) && $form_state['values']['site_default'] != $langcode) {
+ $language->prefix = $langcode;
+ }
+ }
+
+ if ($form_state['values']['enabled'][$langcode]) {
+ $enabled_count++;
+ $language->enabled = 1;
+ }
+ else {
+ $language->enabled = 0;
+ }
+
+ $language->weight = $form_state['values']['weight'][$langcode];
+
+ db_update('languages')
+ ->fields(array(
+ 'enabled' => $language->enabled,
+ 'weight' => $language->weight,
+ 'prefix' => $language->prefix,
+ 'domain' => $language->domain,
+ ))
+ ->condition('language', $langcode)
+ ->execute();
+
+ $languages[$langcode] = $language;
+ }
+
+ variable_set('language_default', $languages[$form_state['values']['site_default']]);
+ variable_set('language_count', $enabled_count);
+ drupal_set_message(t('Configuration saved.'));
+
+ // Changing the language settings impacts the interface.
+ cache_clear_all('*', 'cache_page', TRUE);
+ module_invoke_all('multilingual_settings_changed');
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+
+/**
+ * User interface for the language addition screen.
+ */
+function locale_languages_add_screen() {
+ $build['predefined'] = drupal_get_form('locale_languages_predefined_form');
+ $build['custom'] = drupal_get_form('locale_languages_custom_form');
+ return $build;
+}
+
+/**
+ * Predefined language setup form.
+ */
+function locale_languages_predefined_form($form) {
+ $predefined = _locale_prepare_predefined_list();
+ $form['language list'] = array('#type' => 'fieldset',
+ '#title' => t('Predefined language'),
+ '#collapsible' => TRUE,
+ );
+ $form['language list']['langcode'] = array('#type' => 'select',
+ '#title' => t('Language name'),
+ '#default_value' => key($predefined),
+ '#options' => $predefined,
+ '#description' => t('Use the <em>Custom language</em> section below if your desired language does not appear in this list.'),
+ );
+ $form['language list']['actions'] = array('#type' => 'actions');
+ $form['language list']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add language'));
+ return $form;
+}
+
+/**
+ * Custom language addition form.
+ */
+function locale_languages_custom_form($form) {
+ $form['custom language'] = array('#type' => 'fieldset',
+ '#title' => t('Custom language'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ _locale_languages_common_controls($form['custom language']);
+ $form['custom language']['actions'] = array('#type' => 'actions');
+ $form['custom language']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add custom language')
+ );
+ // Reuse the validation and submit functions of the predefined language setup form.
+ $form['#submit'][] = 'locale_languages_predefined_form_submit';
+ $form['#validate'][] = 'locale_languages_predefined_form_validate';
+ return $form;
+}
+
+/**
+ * Editing screen for a particular language.
+ *
+ * @param $langcode
+ * Language code of the language to edit.
+ */
+function locale_languages_edit_form($form, &$form_state, $langcode) {
+ if ($language = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
+ _locale_languages_common_controls($form, $language);
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save language')
+ );
+ $form['#submit'][] = 'locale_languages_edit_form_submit';
+ $form['#validate'][] = 'locale_languages_edit_form_validate';
+ return $form;
+ }
+ else {
+ drupal_not_found();
+ drupal_exit();
+ }
+}
+
+/**
+ * Common elements of the language addition and editing form.
+ *
+ * @param $form
+ * A parent form item (or empty array) to add items below.
+ * @param $language
+ * Language object to edit.
+ */
+function _locale_languages_common_controls(&$form, $language = NULL) {
+ if (!is_object($language)) {
+ $language = new stdClass();
+ }
+ if (isset($language->language)) {
+ $form['langcode_view'] = array(
+ '#type' => 'item',
+ '#title' => t('Language code'),
+ '#markup' => $language->language
+ );
+ $form['langcode'] = array(
+ '#type' => 'value',
+ '#value' => $language->language
+ );
+ }
+ else {
+ $form['langcode'] = array('#type' => 'textfield',
+ '#title' => t('Language code'),
+ '#maxlength' => 12,
+ '#required' => TRUE,
+ '#default_value' => @$language->language,
+ '#disabled' => (isset($language->language)),
+ '#description' => t('<a href="@rfc4646">RFC 4646</a> compliant language identifier. Language codes typically use a country code, and optionally, a script or regional variant name. <em>Examples: "en", "en-US" and "zh-Hant".</em>', array('@rfc4646' => 'http://www.ietf.org/rfc/rfc4646.txt')),
+ );
+ }
+ $form['name'] = array('#type' => 'textfield',
+ '#title' => t('Language name in English'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->name,
+ '#required' => TRUE,
+ '#description' => t('Name of the language in English. Will be available for translation in all languages.'),
+ );
+ $form['native'] = array('#type' => 'textfield',
+ '#title' => t('Native language name'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->native,
+ '#required' => TRUE,
+ '#description' => t('Name of the language in the language being added.'),
+ );
+ $form['prefix'] = array('#type' => 'textfield',
+ '#title' => t('Path prefix language code'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->prefix,
+ '#description' => t('Language code or other custom text to use as a path prefix for URL language detection, if your <em>Detection and selection</em> settings use URL path prefixes. For the default language, this value may be left blank. <strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "deutsch" as the path prefix code for German results in URLs like "example.com/deutsch/contact".')
+ );
+ $form['domain'] = array('#type' => 'textfield',
+ '#title' => t('Language domain'),
+ '#maxlength' => 128,
+ '#default_value' => @$language->domain,
+ '#description' => t('The domain name to use for this language if URL domains are used for <em>Detection and selection</em>. Leave blank for the default language. <strong>Changing this value may break existing URLs.</strong> Example: Specifying "de.example.com" as language domain for German will result in an URL like "http://de.example.com/contact".'),
+ );
+ $form['direction'] = array('#type' => 'radios',
+ '#title' => t('Direction'),
+ '#required' => TRUE,
+ '#description' => t('Direction that text in this language is presented.'),
+ '#default_value' => @$language->direction,
+ '#options' => array(LANGUAGE_LTR => t('Left to right'), LANGUAGE_RTL => t('Right to left'))
+ );
+ return $form;
+}
+
+/**
+ * Validate the language addition form.
+ */
+function locale_languages_predefined_form_validate($form, &$form_state) {
+ $langcode = $form_state['values']['langcode'];
+
+ if (($duplicate = db_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) != 0) {
+ form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode)));
+ }
+
+ if (!isset($form_state['values']['name'])) {
+ // Predefined language selection.
+ include_once DRUPAL_ROOT . '/includes/iso.inc';
+ $predefined = _locale_get_predefined_list();
+ if (!isset($predefined[$langcode])) {
+ form_set_error('langcode', t('Invalid language code.'));
+ }
+ }
+ else {
+ // Reuse the editing form validation routine if we add a custom language.
+ locale_languages_edit_form_validate($form, $form_state);
+ }
+}
+
+/**
+ * Process the language addition form submission.
+ */
+function locale_languages_predefined_form_submit($form, &$form_state) {
+ $langcode = $form_state['values']['langcode'];
+ if (isset($form_state['values']['name'])) {
+ // Custom language form.
+ locale_add_language($langcode, $form_state['values']['name'], $form_state['values']['native'], $form_state['values']['direction'], $form_state['values']['domain'], $form_state['values']['prefix']);
+ drupal_set_message(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($form_state['values']['name']), '@locale-help' => url('admin/help/locale'))));
+ }
+ else {
+ // Predefined language selection.
+ include_once DRUPAL_ROOT . '/includes/iso.inc';
+ $predefined = _locale_get_predefined_list();
+ locale_add_language($langcode);
+ drupal_set_message(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($predefined[$langcode][0]), '@locale-help' => url('admin/help/locale'))));
+ }
+
+ // See if we have language files to import for the newly added
+ // language, collect and import them.
+ if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) {
+ batch_set($batch);
+ }
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+}
+
+/**
+ * Validate the language editing form. Reused for custom language addition too.
+ */
+function locale_languages_edit_form_validate($form, &$form_state) {
+ // Ensure sane field values for langcode, name, and native.
+ if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state['values']['langcode'])) {
+ form_set_error('langcode', t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title'])));
+ }
+ if ($form_state['values']['name'] != check_plain($form_state['values']['name'])) {
+ form_set_error('name', t('%field cannot contain any markup.', array('%field' => $form['name']['#title'])));
+ }
+ if ($form_state['values']['native'] != check_plain($form_state['values']['native'])) {
+ form_set_error('native', t('%field cannot contain any markup.', array('%field' => $form['native']['#title'])));
+ }
+
+ if (!empty($form_state['values']['domain']) && !empty($form_state['values']['prefix'])) {
+ form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.'));
+ }
+ if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {
+ form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate)));
+ }
+ if (empty($form_state['values']['prefix']) && language_default('language') != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {
+ form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.'));
+ }
+ if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {
+ form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate)));
+ }
+}
+
+/**
+ * Process the language editing form submission.
+ */
+function locale_languages_edit_form_submit($form, &$form_state) {
+ db_update('languages')
+ ->fields(array(
+ 'name' => $form_state['values']['name'],
+ 'native' => $form_state['values']['native'],
+ 'domain' => $form_state['values']['domain'],
+ 'prefix' => $form_state['values']['prefix'],
+ 'direction' => $form_state['values']['direction'],
+ ))
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ $default = language_default();
+ if ($default->language == $form_state['values']['langcode']) {
+ $properties = array('name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight');
+ foreach ($properties as $keyname) {
+ if (isset($form_state['values'][$keyname])) {
+ $default->$keyname = $form_state['values'][$keyname];
+ }
+ }
+ variable_set('language_default', $default);
+ }
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+
+/**
+ * User interface for the language deletion confirmation screen.
+ */
+function locale_languages_delete_form($form, &$form_state, $langcode) {
+
+ // Do not allow deletion of English locale.
+ if ($langcode == 'en') {
+ drupal_set_message(t('The English language cannot be deleted.'));
+ drupal_goto('admin/config/regional/language');
+ }
+
+ if (language_default('language') == $langcode) {
+ drupal_set_message(t('The default language cannot be deleted.'));
+ drupal_goto('admin/config/regional/language');
+ }
+
+ // For other languages, warn user that data loss is ahead.
+ $languages = language_list();
+
+ if (!isset($languages[$langcode])) {
+ drupal_not_found();
+ drupal_exit();
+ }
+ else {
+ $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
+ return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/config/regional/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel'));
+ }
+}
+
+/**
+ * Process language deletion submissions.
+ */
+function locale_languages_delete_form_submit($form, &$form_state) {
+ $languages = language_list();
+ if (isset($languages[$form_state['values']['langcode']])) {
+ // Remove translations first.
+ db_delete('locales_target')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ cache_clear_all('locale:' . $form_state['values']['langcode'], 'cache');
+ // With no translations, this removes existing JavaScript translations file.
+ _locale_rebuild_js($form_state['values']['langcode']);
+ // Remove the language.
+ db_delete('languages')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ db_update('node')
+ ->fields(array('language' => ''))
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ if ($languages[$form_state['values']['langcode']]->enabled) {
+ variable_set('language_count', variable_get('language_count', 1) - 1);
+ }
+ module_invoke_all('multilingual_settings_changed');
+ $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
+ drupal_set_message(t('The language %locale has been removed.', $variables));
+ watchdog('locale', 'The language %locale has been removed.', $variables);
+ }
+
+ // Changing the language settings impacts the interface:
+ cache_clear_all('*', 'cache_page', TRUE);
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+
+/**
+ * Setting for language negotiation options
+ */
+function locale_languages_configure_form() {
+ include_once DRUPAL_ROOT . '/includes/language.inc';
+
+ $form = array(
+ '#submit' => array('locale_languages_configure_form_submit'),
+ '#theme' => 'locale_languages_configure_form',
+ '#language_types' => language_types_configurable(FALSE),
+ '#language_types_info' => language_types_info(),
+ '#language_providers' => language_negotiation_info(),
+ );
+
+ foreach ($form['#language_types'] as $type) {
+ _locale_languages_configure_form_language_table($form, $type);
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save settings'),
+ );
+
+ return $form;
+}
+
+/**
+ * Helper function to build a language provider table.
+ */
+function _locale_languages_configure_form_language_table(&$form, $type) {
+ $info = $form['#language_types_info'][$type];
+
+ $table_form = array(
+ '#title' => t('@type language detection', array('@type' => $info['name'])),
+ '#tree' => TRUE,
+ '#description' => $info['description'],
+ '#language_providers' => array(),
+ '#show_operations' => FALSE,
+ 'weight' => array('#tree' => TRUE),
+ 'enabled' => array('#tree' => TRUE),
+ );
+
+ $language_providers = $form['#language_providers'];
+ $enabled_providers = variable_get("language_negotiation_$type", array());
+ $providers_weight = variable_get("locale_language_providers_weight_$type", array());
+
+ // Add missing data to the providers lists.
+ foreach ($language_providers as $id => $provider) {
+ if (!isset($providers_weight[$id])) {
+ $providers_weight[$id] = language_provider_weight($provider);
+ }
+ }
+
+ // Order providers list by weight.
+ asort($providers_weight);
+
+ foreach ($providers_weight as $id => $weight) {
+ // A language provider might be no more available if the defining module has
+ // been disabled after the last configuration saving.
+ if (!isset($language_providers[$id])) {
+ continue;
+ }
+
+ $enabled = isset($enabled_providers[$id]);
+ $provider = $language_providers[$id];
+
+ // List the provider only if the current type is defined in its 'types' key.
+ // If it is not defined default to all the configurable language types.
+ $types = array_flip(isset($provider['types']) ? $provider['types'] : $form['#language_types']);
+
+ if (isset($types[$type])) {
+ $table_form['#language_providers'][$id] = $provider;
+
+ $table_form['weight'][$id] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight for @title', array('@title' => $provider['name'])),
+ '#title_display' => 'invisible',
+ '#default_value' => $weight,
+ '#attributes' => array('class' => array("language-provider-weight-$type")),
+ );
+
+ $table_form['title'][$id] = array('#markup' => check_plain($provider['name']));
+
+ $table_form['enabled'][$id] = array(
+ '#type' => 'checkbox',
+ '#title' => t('@title language provider', array('@title' => $provider['name'])),
+ '#title_display' => 'invisible',
+ '#default_value' => $enabled,
+ );
+ if ($id === LANGUAGE_NEGOTIATION_DEFAULT) {
+ $table_form['enabled'][$id]['#default_value'] = TRUE;
+ $table_form['enabled'][$id]['#attributes'] = array('disabled' => 'disabled');
+ }
+
+ $table_form['description'][$id] = array('#markup' => filter_xss_admin($provider['description']));
+
+ $config_op = array();
+ if (isset($provider['config'])) {
+ $config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
+ // If there is at least one operation enabled show the operation column.
+ $table_form['#show_operations'] = TRUE;
+ }
+ $table_form['operation'][$id] = $config_op;
+ }
+ }
+
+ $form[$type] = $table_form;
+}
+
+/**
+ * Returns HTML for a language configuration form.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - form: A render element representing the form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_languages_configure_form($variables) {
+ $form = $variables['form'];
+ $output = '';
+
+ foreach ($form['#language_types'] as $type) {
+ $rows = array();
+ $info = $form['#language_types_info'][$type];
+ $title = '<label>' . $form[$type]['#title'] . '</label>';
+ $description = '<div class="description">' . $form[$type]['#description'] . '</div>';
+
+ foreach ($form[$type]['title'] as $id => $element) {
+ // Do not take form control structures.
+ if (is_array($element) && element_child($id)) {
+ $row = array(
+ 'data' => array(
+ '<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>',
+ drupal_render($form[$type]['description'][$id]),
+ drupal_render($form[$type]['enabled'][$id]),
+ drupal_render($form[$type]['weight'][$id]),
+ ),
+ 'class' => array('draggable'),
+ );
+ if ($form[$type]['#show_operations']) {
+ $row['data'][] = drupal_render($form[$type]['operation'][$id]);
+ }
+ $rows[] = $row;
+ }
+ }
+
+ $header = array(
+ array('data' => t('Detection method')),
+ array('data' => t('Description')),
+ array('data' => t('Enabled')),
+ array('data' => t('Weight')),
+ );
+
+ // If there is at least one operation enabled show the operation column.
+ if ($form[$type]['#show_operations']) {
+ $header[] = array('data' => t('Operations'));
+ }
+
+ $variables = array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'attributes' => array('id' => "language-negotiation-providers-$type"),
+ );
+ $table = theme('table', $variables);
+ $table .= drupal_render_children($form[$type]);
+
+ drupal_add_tabledrag("language-negotiation-providers-$type", 'order', 'sibling', "language-provider-weight-$type");
+
+ $output .= '<div class="form-item">' . $title . $description . $table . '</div>';
+ }
+
+ $output .= drupal_render_children($form);
+ return $output;
+}
+
+/**
+ * Submit handler for language negotiation settings.
+ */
+function locale_languages_configure_form_submit($form, &$form_state) {
+ $configurable_types = $form['#language_types'];
+
+ foreach ($configurable_types as $type) {
+ $negotiation = array();
+ $enabled_providers = $form_state['values'][$type]['enabled'];
+ $enabled_providers[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;
+ $providers_weight = $form_state['values'][$type]['weight'];
+
+ foreach ($providers_weight as $id => $weight) {
+ if ($enabled_providers[$id]) {
+ $provider = $form[$type]['#language_providers'][$id];
+ $provider['weight'] = $weight;
+ $negotiation[$id] = $provider;
+ }
+ }
+
+ language_negotiation_set($type, $negotiation);
+ variable_set("locale_language_providers_weight_$type", $providers_weight);
+ }
+
+ // Update non-configurable language types and the related language negotiation
+ // configuration.
+ language_types_set();
+
+ $form_state['redirect'] = 'admin/config/regional/language/configure';
+ drupal_set_message(t('Language negotiation configuration saved.'));
+}
+
+/**
+ * The URL language provider configuration form.
+ */
+function locale_language_providers_url_form($form, &$form_state) {
+ $form['locale_language_negotiation_url_part'] = array(
+ '#title' => t('Part of the URL that determines language'),
+ '#type' => 'radios',
+ '#options' => array(
+ LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX => t('Path prefix'),
+ LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN => t('Domain'),
+ ),
+ '#default_value' => variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX),
+ '#description' => t('<em>Path prefix</em>: URLs like http://example.com/de/contact set language to German (de). <em>Domain</em>: URLs like http://de.example.com/contact set the language to German. <strong>Warning: Changing this setting may break incoming URLs. Use with caution on a production site.</strong>'),
+ );
+
+ $form_state['redirect'] = 'admin/config/regional/language/configure';
+
+ return system_settings_form($form);
+}
+
+/**
+ * The URL language provider configuration form.
+ */
+function locale_language_providers_session_form($form, &$form_state) {
+ $form['locale_language_negotiation_session_param'] = array(
+ '#title' => t('Request/session parameter'),
+ '#type' => 'textfield',
+ '#default_value' => variable_get('locale_language_negotiation_session_param', 'language'),
+ '#description' => t('Name of the request/session parameter used to determine the desired language.'),
+ );
+
+ $form_state['redirect'] = 'admin/config/regional/language/configure';
+
+ return system_settings_form($form);
+}
+
+/**
+ * @} End of "locale-language-administration"
+ */
+
+/**
+ * @defgroup locale-translate-administration-screens Translation administration screens
+ * @{
+ * Screens for translation administration.
+ *
+ * These functions provide various screens as administration interface
+ * to import, export and view translations.
+ */
+
+/**
+ * Overview screen for translations.
+ */
+function locale_translate_overview_screen() {
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
+ $groups = module_invoke_all('locale', 'groups');
+
+ // Build headers with all groups in order.
+ $headers = array_merge(array(t('Language')), array_values($groups));
+
+ // Collect summaries of all source strings in all groups.
+ $sums = db_query("SELECT COUNT(*) AS strings, textgroup FROM {locales_source} GROUP BY textgroup");
+ $groupsums = array();
+ foreach ($sums as $group) {
+ $groupsums[$group->textgroup] = $group->strings;
+ }
+
+ // Set up overview table with default values, ensuring common order for values.
+ $rows = array();
+ foreach ($languages as $langcode => $language) {
+ $rows[$langcode] = array('name' => ($langcode == 'en' ? t('English (built-in)') : t($language->name)));
+ foreach ($groups as $group => $name) {
+ $rows[$langcode][$group] = ($langcode == 'en' ? t('n/a') : '0/' . (isset($groupsums[$group]) ? $groupsums[$group] : 0) . ' (0%)');
+ }
+ }
+
+ // Languages with at least one record in the locale table.
+ $translations = db_query("SELECT COUNT(*) AS translation, t.language, s.textgroup FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY textgroup, language");
+ foreach ($translations as $data) {
+ $ratio = (!empty($groupsums[$data->textgroup]) && $data->translation > 0) ? round(($data->translation/$groupsums[$data->textgroup]) * 100.0, 2) : 0;
+ $rows[$data->language][$data->textgroup] = $data->translation . '/' . $groupsums[$data->textgroup] . " ($ratio%)";
+ }
+
+ return theme('table', array('header' => $headers, 'rows' => $rows));
+}
+
+/**
+ * String search screen.
+ */
+function locale_translate_seek_screen() {
+ // Add CSS.
+ drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
+
+ $elements = drupal_get_form('locale_translation_filter_form');
+ $output = drupal_render($elements);
+ $output .= _locale_translate_seek();
+ return $output;
+}
+
+/**
+ * List locale translation filters that can be applied.
+ */
+function locale_translation_filters() {
+ $filters = array();
+
+ // Get all languages, except English
+ drupal_static_reset('language_list');
+ $languages = locale_language_list('name');
+ unset($languages['en']);
+
+ $filters['string'] = array(
+ 'title' => t('String contains'),
+ 'description' => t('Leave blank to show all strings. The search is case sensitive.'),
+ );
+
+ $filters['language'] = array(
+ 'title' => t('Language'),
+ 'options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages),
+ );
+
+ $filters['translation'] = array(
+ 'title' => t('Search in'),
+ 'options' => array('all' => t('Both translated and untranslated strings'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')),
+ );
+
+ $groups = module_invoke_all('locale', 'groups');
+ $filters['group'] = array(
+ 'title' => t('Limit search to'),
+ 'options' => array_merge(array('all' => t('All text groups')), $groups),
+ );
+
+ return $filters;
+}
+
+/**
+ * Return form for locale translation filters.
+ *
+ * @ingroup forms
+ */
+function locale_translation_filter_form() {
+ $filters = locale_translation_filters();
+
+ $form['filters'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Filter translatable strings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ foreach ($filters as $key => $filter) {
+ // Special case for 'string' filter.
+ if ($key == 'string') {
+ $form['filters']['status']['string'] = array(
+ '#type' => 'textfield',
+ '#title' => $filter['title'],
+ '#description' => $filter['description'],
+ );
+ }
+ else {
+ $form['filters']['status'][$key] = array(
+ '#title' => $filter['title'],
+ '#type' => 'select',
+ '#empty_value' => 'all',
+ '#empty_option' => $filter['options']['all'],
+ '#size' => 0,
+ '#options' => $filter['options'],
+ );
+ }
+ if (!empty($_SESSION['locale_translation_filter'][$key])) {
+ $form['filters']['status'][$key]['#default_value'] = $_SESSION['locale_translation_filter'][$key];
+ }
+ }
+
+ $form['filters']['actions'] = array(
+ '#type' => 'actions',
+ '#attributes' => array('class' => array('container-inline')),
+ );
+ $form['filters']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Filter'),
+ );
+ if (!empty($_SESSION['locale_translation_filter'])) {
+ $form['filters']['actions']['reset'] = array(
+ '#type' => 'submit',
+ '#value' => t('Reset')
+ );
+ }
+
+ return $form;
+}
+
+/**
+ * Validate result from locale translation filter form.
+ */
+function locale_translation_filter_form_validate($form, &$form_state) {
+ if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['language']) && empty($form_state['values']['group'])) {
+ form_set_error('type', t('You must select something to filter by.'));
+ }
+}
+
+/**
+ * Process result from locale translation filter form.
+ */
+function locale_translation_filter_form_submit($form, &$form_state) {
+ $op = $form_state['values']['op'];
+ $filters = locale_translation_filters();
+ switch ($op) {
+ case t('Filter'):
+ foreach ($filters as $name => $filter) {
+ if (isset($form_state['values'][$name])) {
+ $_SESSION['locale_translation_filter'][$name] = $form_state['values'][$name];
+ }
+ }
+ break;
+ case t('Reset'):
+ $_SESSION['locale_translation_filter'] = array();
+ break;
+ }
+
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+}
+
+/**
+ * User interface for the translation import screen.
+ */
+function locale_translate_import_form($form) {
+ // Get all languages, except English
+ drupal_static_reset('language_list');
+ $names = locale_language_list('name');
+ unset($names['en']);
+
+ if (!count($names)) {
+ $languages = _locale_prepare_predefined_list();
+ $default = key($languages);
+ }
+ else {
+ $languages = array(
+ t('Already added languages') => $names,
+ t('Languages not yet added') => _locale_prepare_predefined_list()
+ );
+ $default = key($names);
+ }
+
+ $form['import'] = array('#type' => 'fieldset',
+ '#title' => t('Import translation'),
+ );
+ $form['import']['file'] = array('#type' => 'file',
+ '#title' => t('Language file'),
+ '#size' => 50,
+ '#description' => t('A Gettext Portable Object (<em>.po</em>) file.'),
+ );
+ $form['import']['langcode'] = array('#type' => 'select',
+ '#title' => t('Import into'),
+ '#options' => $languages,
+ '#default_value' => $default,
+ '#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.'),
+ );
+ $form['import']['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ '#description' => t('Imported translations will be added to this text group.'),
+ );
+ $form['import']['mode'] = array('#type' => 'radios',
+ '#title' => t('Mode'),
+ '#default_value' => LOCALE_IMPORT_KEEP,
+ '#options' => array(
+ LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),
+ LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.')
+ ),
+ );
+ $form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));
+
+ return $form;
+}
+
+/**
+ * Process the locale import form submission.
+ */
+function locale_translate_import_form_submit($form, &$form_state) {
+ $validators = array('file_validate_extensions' => array('po'));
+ // Ensure we have the file uploaded
+ if ($file = file_save_upload('file', $validators)) {
+
+ // Add language, if not yet supported
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
+ $langcode = $form_state['values']['langcode'];
+ if (!isset($languages[$langcode])) {
+ include_once DRUPAL_ROOT . '/includes/iso.inc';
+ $predefined = _locale_get_predefined_list();
+ locale_add_language($langcode);
+ drupal_set_message(t('The language %language has been created.', array('%language' => t($predefined[$langcode][0]))));
+ }
+
+ // Now import strings into the language
+ if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode'], $form_state['values']['group']) == FALSE) {
+ $variables = array('%filename' => $file->filename);
+ drupal_set_message(t('The translation import of %filename failed.', $variables), 'error');
+ watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
+ }
+ }
+ else {
+ drupal_set_message(t('File to import not found.'), 'error');
+ $form_state['redirect'] = 'admin/config/regional/translate/import';
+ return;
+ }
+
+ $form_state['redirect'] = 'admin/config/regional/translate';
+ return;
+}
+
+/**
+ * User interface for the translation export screen.
+ */
+function locale_translate_export_screen() {
+ // Get all languages, except English
+ drupal_static_reset('language_list');
+ $names = locale_language_list('name');
+ unset($names['en']);
+ $output = '';
+ // Offer translation export if any language is set up.
+ if (count($names)) {
+ $elements = drupal_get_form('locale_translate_export_po_form', $names);
+ $output = drupal_render($elements);
+ }
+ $elements = drupal_get_form('locale_translate_export_pot_form');
+ $output .= drupal_render($elements);
+ return $output;
+}
+
+/**
+ * Form to export PO files for the languages provided.
+ *
+ * @param $names
+ * An associate array with localized language names
+ */
+function locale_translate_export_po_form($form, &$form_state, $names) {
+ $form['export_title'] = array('#type' => 'item',
+ '#title' => t('Export translation'),
+ );
+ $form['langcode'] = array('#type' => 'select',
+ '#title' => t('Language name'),
+ '#options' => $names,
+ '#description' => t('Select the language to export in Gettext Portable Object (<em>.po</em>) format.'),
+ );
+ $form['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ );
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
+ return $form;
+}
+
+/**
+ * Translation template export form.
+ */
+function locale_translate_export_pot_form() {
+ // Complete template export of the strings
+ $form['export_title'] = array('#type' => 'item',
+ '#title' => t('Export template'),
+ '#description' => t('Generate a Gettext Portable Object Template (<em>.pot</em>) file with all strings from the Drupal locale database.'),
+ );
+ $form['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ );
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
+ // Reuse PO export submission callback.
+ $form['#submit'][] = 'locale_translate_export_po_form_submit';
+ return $form;
+}
+
+/**
+ * Process a translation (or template) export form submission.
+ */
+function locale_translate_export_po_form_submit($form, &$form_state) {
+ // If template is required, language code is not given.
+ $language = NULL;
+ if (isset($form_state['values']['langcode'])) {
+ $languages = language_list();
+ $language = $languages[$form_state['values']['langcode']];
+ }
+ _locale_export_po($language, _locale_export_po_generate($language, _locale_export_get_strings($language, $form_state['values']['group'])));
+}
+/**
+ * @} End of "locale-translate-administration-screens"
+ */
+
+/**
+ * @defgroup locale-translate-edit-delete Translation editing/deletion interface
+ * @{
+ * Edit and delete translation strings.
+ *
+ * These functions provide the user interface to edit and delete
+ * translation strings.
+ */
+
+/**
+ * User interface for string editing.
+ */
+function locale_translate_edit_form($form, &$form_state, $lid) {
+ // Fetch source string, if possible.
+ $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject();
+ if (!$source) {
+ drupal_set_message(t('String not found.'), 'error');
+ drupal_goto('admin/config/regional/translate/translate');
+ }
+
+ // Add original text to the top and some values for form altering.
+ $form['original'] = array(
+ '#type' => 'item',
+ '#title' => t('Original text'),
+ '#markup' => check_plain(wordwrap($source->source, 0)),
+ );
+ if (!empty($source->context)) {
+ $form['context'] = array(
+ '#type' => 'item',
+ '#title' => t('Context'),
+ '#markup' => check_plain($source->context),
+ );
+ }
+ $form['lid'] = array(
+ '#type' => 'value',
+ '#value' => $lid
+ );
+ $form['textgroup'] = array(
+ '#type' => 'value',
+ '#value' => $source->textgroup,
+ );
+ $form['location'] = array(
+ '#type' => 'value',
+ '#value' => $source->location
+ );
+
+ // Include default form controls with empty values for all languages.
+ // This ensures that the languages are always in the same order in forms.
+ $languages = language_list();
+ $default = language_default();
+ // We don't need the default language value, that value is in $source.
+ $omit = $source->textgroup == 'default' ? 'en' : $default->language;
+ unset($languages[($omit)]);
+ $form['translations'] = array('#tree' => TRUE);
+ // Approximate the number of rows to use in the default textarea.
+ $rows = min(ceil(str_word_count($source->source) / 12), 10);
+ foreach ($languages as $langcode => $language) {
+ $form['translations'][$langcode] = array(
+ '#type' => 'textarea',
+ '#title' => t($language->name),
+ '#rows' => $rows,
+ '#default_value' => '',
+ );
+ }
+
+ // Fetch translations and fill in default values in the form.
+ $result = db_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(':lid' => $lid, ':omit' => $omit));
+ foreach ($result as $translation) {
+ $form['translations'][$translation->language]['#default_value'] = $translation->translation;
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save translations'));
+ return $form;
+}
+
+/**
+ * Validate string editing form submissions.
+ */
+function locale_translate_edit_form_validate($form, &$form_state) {
+ // Locale string check is needed for default textgroup only.
+ $safe_check_needed = $form_state['values']['textgroup'] == 'default';
+ foreach ($form_state['values']['translations'] as $key => $value) {
+ if ($safe_check_needed && !locale_string_is_safe($value)) {
+ form_set_error('translations', t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
+ watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);
+ }
+ }
+}
+
+/**
+ * Process string editing form submissions.
+ *
+ * Saves all translations of one string submitted from a form.
+ */
+function locale_translate_edit_form_submit($form, &$form_state) {
+ $lid = $form_state['values']['lid'];
+ foreach ($form_state['values']['translations'] as $key => $value) {
+ $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField();
+ if (!empty($value)) {
+ // Only update or insert if we have a value to use.
+ if (!empty($translation)) {
+ db_update('locales_target')
+ ->fields(array(
+ 'translation' => $value,
+ ))
+ ->condition('lid', $lid)
+ ->condition('language', $key)
+ ->execute();
+ }
+ else {
+ db_insert('locales_target')
+ ->fields(array(
+ 'lid' => $lid,
+ 'translation' => $value,
+ 'language' => $key,
+ ))
+ ->execute();
+ }
+ }
+ elseif (!empty($translation)) {
+ // Empty translation entered: remove existing entry from database.
+ db_delete('locales_target')
+ ->condition('lid', $lid)
+ ->condition('language', $key)
+ ->execute();
+ }
+
+ // Force JavaScript translation file recreation for this language.
+ _locale_invalidate_js($key);
+ }
+
+ drupal_set_message(t('The string has been saved.'));
+
+ // Clear locale cache.
+ _locale_invalidate_js();
+ cache_clear_all('locale:', 'cache', TRUE);
+
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+ return;
+}
+
+/**
+ * String deletion confirmation page.
+ */
+function locale_translate_delete_page($lid) {
+ if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {
+ return drupal_get_form('locale_translate_delete_form', $source);
+ }
+ return MENU_NOT_FOUND;
+}
+
+/**
+ * User interface for the string deletion confirmation screen.
+ */
+function locale_translate_delete_form($form, &$form_state, $source) {
+ $form['lid'] = array('#type' => 'value', '#value' => $source->lid);
+ return confirm_form($form, t('Are you sure you want to delete the string "%source"?', array('%source' => $source->source)), 'admin/config/regional/translate/translate', t('Deleting the string will remove all translations of this string in all languages. This action cannot be undone.'), t('Delete'), t('Cancel'));
+}
+
+/**
+ * Process string deletion submissions.
+ */
+function locale_translate_delete_form_submit($form, &$form_state) {
+ db_delete('locales_source')
+ ->condition('lid', $form_state['values']['lid'])
+ ->execute();
+ db_delete('locales_target')
+ ->condition('lid', $form_state['values']['lid'])
+ ->execute();
+ // Force JavaScript translation file recreation for all languages.
+ _locale_invalidate_js();
+ cache_clear_all('locale:', 'cache', TRUE);
+ drupal_set_message(t('The string has been removed.'));
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+}
+/**
+ * @} End of "locale-translate-edit-delete"
+ */
+
+/**
+ * Returns HTML for a locale date format form.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - form: A render element representing the form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_date_format_form($variables) {
+ $form = $variables['form'];
+ $header = array(
+ t('Date type'),
+ t('Format'),
+ );
+
+ foreach (element_children($form['date_formats']) as $key) {
+ $row = array();
+ $row[] = $form['date_formats'][$key]['#title'];
+ unset($form['date_formats'][$key]['#title']);
+ $row[] = array('data' => drupal_render($form['date_formats'][$key]));
+ $rows[] = $row;
+ }
+
+ $output = drupal_render($form['language']);
+ $output .= theme('table', array('header' => $header, 'rows' => $rows));
+ $output .= drupal_render_children($form);
+
+ return $output;
+}
+
+/**
+ * Display edit date format links for each language.
+ */
+function locale_date_format_language_overview_page() {
+ $header = array(
+ t('Language'),
+ array('data' => t('Operations'), 'colspan' => '2'),
+ );
+
+ // Get list of languages.
+ $languages = locale_language_list('native');
+
+ foreach ($languages as $langcode => $info) {
+ $row = array();
+ $row[] = $languages[$langcode];
+ $row[] = l(t('edit'), 'admin/config/regional/date-time/locale/' . $langcode . '/edit');
+ $row[] = l(t('reset'), 'admin/config/regional/date-time/locale/' . $langcode . '/reset');
+ $rows[] = $row;
+ }
+
+ return theme('table', array('header' => $header, 'rows' => $rows));
+}
+
+/**
+ * Provide date localization configuration options to users.
+ */
+function locale_date_format_form($form, &$form_state, $langcode) {
+ $languages = locale_language_list('native');
+ $language_name = $languages[$langcode];
+
+ // Display the current language name.
+ $form['language'] = array(
+ '#type' => 'item',
+ '#title' => t('Language'),
+ '#markup' => check_plain($language_name),
+ '#weight' => -10,
+ );
+ $form['langcode'] = array(
+ '#type' => 'value',
+ '#value' => $langcode,
+ );
+
+ // Get list of date format types.
+ $types = system_get_date_types();
+
+ // Get list of available formats.
+ $formats = system_get_date_formats();
+ $choices = array();
+ foreach ($formats as $type => $list) {
+ foreach ($list as $f => $format) {
+ $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
+ }
+ }
+ reset($formats);
+
+ // Get configured formats for each language.
+ $locale_formats = system_date_format_locale($langcode);
+ // Display a form field for each format type.
+ foreach ($types as $type => $type_info) {
+ if (!empty($locale_formats) && in_array($type, array_keys($locale_formats))) {
+ $default = $locale_formats[$type];
+ }
+ else {
+ $default = variable_get('date_format_' . $type, key($formats));
+ }
+
+ // Show date format select list.
+ $form['date_formats']['date_format_' . $type] = array(
+ '#type' => 'select',
+ '#title' => check_plain($type_info['title']),
+ '#attributes' => array('class' => array('date-format')),
+ '#default_value' => (isset($choices[$default]) ? $default : 'custom'),
+ '#options' => $choices,
+ );
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save configuration'),
+ );
+
+ return $form;
+}
+
+/**
+ * Submit handler for configuring localized date formats on the locale_date_format_form.
+ */
+function locale_date_format_form_submit($form, &$form_state) {
+ include_once DRUPAL_ROOT . '/includes/locale.inc';
+ $langcode = $form_state['values']['langcode'];
+
+ // Get list of date format types.
+ $types = system_get_date_types();
+ foreach ($types as $type => $type_info) {
+ $format = $form_state['values']['date_format_' . $type];
+ if ($format == 'custom') {
+ $format = $form_state['values']['date_format_' . $type . '_custom'];
+ }
+ locale_date_format_save($langcode, $type, $format);
+ }
+ drupal_set_message(t('Configuration saved.'));
+ $form_state['redirect'] = 'admin/config/regional/date-time/locale';
+}
+
+/**
+ * Reset locale specific date formats to the global defaults.
+ *
+ * @param $langcode
+ * Language code, e.g. 'en'.
+ */
+function locale_date_format_reset_form($form, &$form_state, $langcode) {
+ $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
+ $languages = language_list();
+ return confirm_form($form,
+ t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => $languages[$langcode]->name)),
+ 'admin/config/regional/date-time/locale',
+ t('Resetting will remove all localized date formats for this language. This action cannot be undone.'),
+ t('Reset'), t('Cancel'));
+}
+
+/**
+ * Reset date formats for a specific language to global defaults.
+ */
+function locale_date_format_reset_form_submit($form, &$form_state) {
+ db_delete('date_format_locale')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ $form_state['redirect'] = 'admin/config/regional/date-time/locale';
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.api.php b/kolab.org/www/drupal-7.26/modules/locale/locale.api.php
new file mode 100644
index 0000000..1f11fc9
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.api.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by the Locale module.
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/**
+ * Allows modules to define their own text groups that can be translated.
+ *
+ * @param $op
+ * Type of operation. Currently, only supports 'groups'.
+ */
+function hook_locale($op = 'groups') {
+ switch ($op) {
+ case 'groups':
+ return array('custom' => t('Custom'));
+ }
+}
+
+/**
+ * Allow modules to react to language settings changes.
+ *
+ * Every module needing to act when the number of enabled languages changes
+ * should implement this. This is an "internal" hook and should not be invoked
+ * elsewhere. The typical implementation would trigger some kind of rebuilding,
+ * this way system components could properly react to the change of the enabled
+ * languages number.
+ */
+function hook_multilingual_settings_changed() {
+ field_info_cache_clear();
+}
+
+/**
+ * @} End of "addtogroup hooks".
+ */
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.css b/kolab.org/www/drupal-7.26/modules/locale/locale.css
new file mode 100644
index 0000000..38112b5
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.css
@@ -0,0 +1,32 @@
+
+.locale-untranslated {
+ font-style: normal;
+ text-decoration: line-through;
+}
+
+#locale-translation-filter-form .form-item-language,
+#locale-translation-filter-form .form-item-translation,
+#locale-translation-filter-form .form-item-group {
+ float: left; /* LTR */
+ padding-right: .8em; /* LTR */
+ margin: 0.1em;
+ /**
+ * In Opera 9, DOM elements with the property of "overflow: auto"
+ * will partially hide its contents with unnecessary scrollbars when
+ * its immediate child is floated without an explicit width set.
+ */
+ width: 15em;
+}
+#locale-translation-filter-form .form-type-select select {
+ width: 100%;
+}
+#locale-translation-filter-form .form-actions {
+ float: left; /* LTR */
+ padding: 3ex 0 0 1em; /* LTR */
+}
+.language-switcher-locale-session a.active {
+ color: #0062A0;
+}
+.language-switcher-locale-session a.session-active {
+ color: #000000;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.datepicker.js b/kolab.org/www/drupal-7.26/modules/locale/locale.datepicker.js
new file mode 100644
index 0000000..f819282
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.datepicker.js
@@ -0,0 +1,79 @@
+(function ($) {
+
+/**
+ * Attaches language support to the jQuery UI datepicker component.
+ */
+Drupal.behaviors.localeDatepicker = {
+ attach: function(context, settings) {
+ // This code accesses Drupal.settings and localized strings via Drupal.t().
+ // So this code should run after these are initialized. By placing it in an
+ // attach behavior this is assured.
+ $.datepicker.regional['drupal-locale'] = $.extend({
+ closeText: Drupal.t('Done'),
+ prevText: Drupal.t('Prev'),
+ nextText: Drupal.t('Next'),
+ currentText: Drupal.t('Today'),
+ monthNames: [
+ Drupal.t('January'),
+ Drupal.t('February'),
+ Drupal.t('March'),
+ Drupal.t('April'),
+ Drupal.t('May'),
+ Drupal.t('June'),
+ Drupal.t('July'),
+ Drupal.t('August'),
+ Drupal.t('September'),
+ Drupal.t('October'),
+ Drupal.t('November'),
+ Drupal.t('December')
+ ],
+ monthNamesShort: [
+ Drupal.t('Jan'),
+ Drupal.t('Feb'),
+ Drupal.t('Mar'),
+ Drupal.t('Apr'),
+ Drupal.t('May'),
+ Drupal.t('Jun'),
+ Drupal.t('Jul'),
+ Drupal.t('Aug'),
+ Drupal.t('Sep'),
+ Drupal.t('Oct'),
+ Drupal.t('Nov'),
+ Drupal.t('Dec')
+ ],
+ dayNames: [
+ Drupal.t('Sunday'),
+ Drupal.t('Monday'),
+ Drupal.t('Tuesday'),
+ Drupal.t('Wednesday'),
+ Drupal.t('Thursday'),
+ Drupal.t('Friday'),
+ Drupal.t('Saturday')
+ ],
+ dayNamesShort: [
+ Drupal.t('Sun'),
+ Drupal.t('Mon'),
+ Drupal.t('Tue'),
+ Drupal.t('Wed'),
+ Drupal.t('Thu'),
+ Drupal.t('Fri'),
+ Drupal.t('Sat')
+ ],
+ dayNamesMin: [
+ Drupal.t('Su'),
+ Drupal.t('Mo'),
+ Drupal.t('Tu'),
+ Drupal.t('We'),
+ Drupal.t('Th'),
+ Drupal.t('Fr'),
+ Drupal.t('Sa')
+ ],
+ dateFormat: Drupal.t('mm/dd/yy'),
+ firstDay: 0,
+ isRTL: 0
+ }, Drupal.settings.jquery.ui.datepicker);
+ $.datepicker.setDefaults($.datepicker.regional['drupal-locale']);
+ }
+};
+
+})(jQuery);
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.info b/kolab.org/www/drupal-7.26/modules/locale/locale.info
new file mode 100644
index 0000000..3a260e2
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.info
@@ -0,0 +1,13 @@
+name = Locale
+description = Adds language handling functionality and enables the translation of the user interface to languages other than English.
+package = Core
+version = VERSION
+core = 7.x
+files[] = locale.test
+configure = admin/config/regional/language
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.install b/kolab.org/www/drupal-7.26/modules/locale/locale.install
new file mode 100644
index 0000000..b4db757
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.install
@@ -0,0 +1,457 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the locale module.
+ */
+
+/**
+ * Implements hook_install().
+ */
+function locale_install() {
+ // locales_source.source and locales_target.target are not used as binary
+ // fields; non-MySQL database servers need to ensure the field type is text
+ // and that LIKE produces a case-sensitive comparison.
+
+ db_insert('languages')
+ ->fields(array(
+ 'language' => 'en',
+ 'name' => 'English',
+ 'native' => 'English',
+ 'direction' => 0,
+ 'enabled' => 1,
+ 'weight' => 0,
+ 'javascript' => '',
+ ))
+ ->execute();
+}
+
+/**
+ * @addtogroup updates-6.x-to-7.x
+ * @{
+ */
+
+/**
+ * Add context field index and allow longer location.
+ */
+function locale_update_7000() {
+ db_drop_index('locales_source', 'source');
+ db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));
+
+ // Also drop the 'textgroup_location' index added by the i18nstrings module
+ // of the i18n project, which prevents the below schema update from running.
+ if (db_index_exists('locales_source', 'textgroup_location')) {
+ db_drop_index('locales_source', 'textgroup_location');
+ }
+
+ db_change_field('locales_source', 'location', 'location', array(
+ 'type' => 'text',
+ 'not null' => FALSE,
+ 'size' => 'big',
+ 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
+ ));
+}
+
+/**
+ * Upgrade language negotiation settings.
+ */
+function locale_update_7001() {
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ require_once DRUPAL_ROOT . '/modules/locale/locale.module';
+
+ switch (variable_get('language_negotiation', 0)) {
+ // LANGUAGE_NEGOTIATION_NONE.
+ case 0:
+ $negotiation = array();
+ break;
+
+ // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
+ case 1:
+ $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
+ // In Drupal 6 path prefixes are shown for the default language only when
+ // language negotiation is set to LANGUAGE_NEGOTIATION_PATH, while in
+ // Drupal 7 path prefixes are always shown if not empty. Hence we need to
+ // ensure that the default language has an empty prefix to avoid breaking
+ // the site URLs with a prefix that previously was missing.
+ $default = language_default();
+ $default->prefix = '';
+ variable_set('language_default', $default);
+ db_update('languages')
+ ->fields(array('prefix' => $default->prefix))
+ ->condition('language', $default->language)
+ ->execute();
+ break;
+
+ // LANGUAGE_NEGOTIATION_PATH.
+ case 2:
+ $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_USER, LOCALE_LANGUAGE_NEGOTIATION_BROWSER);
+ break;
+
+ // LANGUAGE_NEGOTIATION_DOMAIN.
+ case 3:
+ variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN);
+ $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
+ break;
+ }
+
+ // Save the new language negotiation options.
+ language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array_flip($negotiation));
+ language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE => 0));
+ language_negotiation_set(LANGUAGE_TYPE_URL, array(LOCALE_LANGUAGE_NEGOTIATION_URL => 0));
+
+ // Save admininstration UI settings.
+ $type = LANGUAGE_TYPE_INTERFACE;
+ $provider_weights = array_flip(array_keys(locale_language_negotiation_info()));
+ variable_set("locale_language_providers_weight_$type", $provider_weights);
+
+ // Unset the old language negotiation system variable.
+ variable_del('language_negotiation');
+
+ return array();
+}
+
+/**
+ * Updates URL language negotiation by adding the URL fallback detection method.
+ */
+function locale_update_7002() {
+ // language.inc may not have been included during bootstrap if there is not
+ // more than one language currently enabled.
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ $language_types_info = language_types_info();
+ $info = $language_types_info[LANGUAGE_TYPE_URL];
+ if (isset($info['fixed'])) {
+ language_negotiation_set(LANGUAGE_TYPE_URL, array_flip($info['fixed']));
+ }
+}
+
+/**
+ * @} End of "addtogroup updates-6.x-to-7.x".
+ */
+
+/**
+ * @addtogroup updates-7.x-extra
+ * @{
+ */
+
+/**
+ * Update "language_count" variable.
+ */
+function locale_update_7003() {
+ $languages = language_list('enabled');
+ variable_set('language_count', count($languages[1]));
+}
+
+/**
+ * Remove duplicates in {locales_source}.
+ */
+function locale_update_7004() {
+ // Look up all duplicates. For each set of duplicates, we select the row
+ // with the lowest lid as the "master" that will be preserved.
+ $result_source = db_query("SELECT MIN(lid) AS lid, source, context FROM {locales_source} WHERE textgroup = 'default' GROUP BY source, context HAVING COUNT(*) > 1");
+
+ $conflict = FALSE;
+ foreach ($result_source as $source) {
+ // Find all rows in {locales_target} that are translations of the same
+ // string (incl. context).
+ $result_target = db_query("SELECT t.lid, t.language, t.plural, t.translation FROM {locales_source} s JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default' ORDER BY lid", array(
+ ':source' => $source->source,
+ ':context' => $source->context,
+ ));
+
+ $translations = array();
+ $keep_lids = array($source->lid);
+ foreach ($result_target as $target) {
+ if (!isset($translations[$target->language])) {
+ $translations[$target->language] = $target->translation;
+ if ($target->lid != $source->lid) {
+ // Move translation to the master lid.
+ db_query('UPDATE {locales_target} SET lid = :new_lid WHERE lid = :old_lid', array(
+ ':new_lid' => $source->lid,
+ ':old_lid' => $target->lid));
+ }
+ }
+ elseif ($translations[$target->language] == $target->translation) {
+ // Delete duplicate translation.
+ db_query('DELETE FROM {locales_target} WHERE lid = :lid AND language = :language', array(
+ ':lid' => $target->lid,
+ ':language' => $target->language));
+ }
+ else {
+ // The same string is translated into several different strings in one
+ // language. We do not know which is the preferred, so we keep them all.
+ $keep_lids[] = $target->lid;
+ $conflict = TRUE;
+ }
+ }
+
+ // Delete rows in {locales_source} that are no longer referenced from
+ // {locales_target}.
+ db_delete('locales_source')
+ ->condition('source', $source->source)
+ ->condition('context', $source->context)
+ ->condition('textgroup', 'default')
+ ->condition('lid', $keep_lids, 'NOT IN')
+ ->execute();
+ }
+
+ if ($conflict) {
+ $url = 'http://drupal.org/node/746240';
+ drupal_set_message('Your {locales_source} table contains duplicates that could not be removed automatically. See <a href="' . $url .'" target="_blank">' . $url . '</a> for more information.', 'warning');
+ }
+}
+
+/**
+ * Increase {locales_languages}.formula column's length.
+ */
+function locale_update_7005() {
+ db_change_field('languages', 'formula', 'formula', array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.',
+ ));
+}
+
+/**
+ * @} End of "addtogroup updates-7.x-extra".
+ */
+
+/**
+ * Implements hook_uninstall().
+ */
+function locale_uninstall() {
+ // Delete all JavaScript translation files.
+ $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');
+
+ if (is_dir($locale_js_directory)) {
+ $files = db_query('SELECT language, javascript FROM {languages}');
+ foreach ($files as $file) {
+ if (!empty($file->javascript)) {
+ file_unmanaged_delete($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js');
+ }
+ }
+ // Delete the JavaScript translations directory if empty.
+ if (!file_scan_directory($locale_js_directory, '/.*/')) {
+ drupal_rmdir($locale_js_directory);
+ }
+ }
+
+ // Clear variables.
+ variable_del('language_default');
+ variable_del('language_count');
+ variable_del('language_types');
+ variable_del('locale_language_negotiation_url_part');
+ variable_del('locale_language_negotiation_session_param');
+ variable_del('language_content_type_default');
+ variable_del('language_content_type_negotiation');
+ variable_del('locale_cache_strings');
+ variable_del('locale_js_directory');
+ variable_del('javascript_parsed');
+ variable_del('locale_field_language_fallback');
+ variable_del('locale_cache_length');
+
+ foreach (language_types() as $type) {
+ variable_del("language_negotiation_$type");
+ variable_del("locale_language_providers_weight_$type");
+ }
+
+ foreach (node_type_get_types() as $type => $content_type) {
+ $setting = variable_del("language_content_type_$type");
+ }
+
+ // Switch back to English: with a $language->language value different from 'en'
+ // successive calls of t() might result in calling locale(), which in turn might
+ // try to query the unexisting {locales_source} and {locales_target} tables.
+ drupal_language_initialize();
+
+}
+
+/**
+ * Implements hook_schema().
+ */
+function locale_schema() {
+ $schema['languages'] = array(
+ 'description' => 'List of all available languages in the system.',
+ 'fields' => array(
+ 'language' => array(
+ 'type' => 'varchar',
+ 'length' => 12,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "Language code, e.g. 'de' or 'en-US'.",
+ ),
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Language name in English.',
+ ),
+ 'native' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Native language name.',
+ ),
+ 'direction' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).',
+ ),
+ 'enabled' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).',
+ ),
+ 'plurals' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Number of plural indexes in this language.',
+ ),
+ 'formula' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.',
+ ),
+ 'domain' => array(
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Domain to use for this language.',
+ ),
+ 'prefix' => array(
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Path prefix to use for this language.',
+ ),
+ 'weight' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Weight, used in lists of languages.',
+ ),
+ 'javascript' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Location of JavaScript translation file.',
+ ),
+ ),
+ 'primary key' => array('language'),
+ 'indexes' => array(
+ 'list' => array('weight', 'name'),
+ ),
+ );
+
+ $schema['locales_source'] = array(
+ 'description' => 'List of English source strings.',
+ 'fields' => array(
+ 'lid' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Unique identifier of this string.',
+ ),
+ 'location' => array(
+ 'type' => 'text',
+ 'not null' => FALSE,
+ 'size' => 'big',
+ 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
+ ),
+ 'textgroup' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => 'default',
+ 'description' => 'A module defined group of translations, see hook_locale().',
+ ),
+ 'source' => array(
+ 'type' => 'text',
+ 'mysql_type' => 'blob',
+ 'not null' => TRUE,
+ 'description' => 'The original string in English.',
+ ),
+ 'context' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The context this string applies to.',
+ ),
+ 'version' => array(
+ 'type' => 'varchar',
+ 'length' => 20,
+ 'not null' => TRUE,
+ 'default' => 'none',
+ 'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
+ ),
+ ),
+ 'primary key' => array('lid'),
+ 'indexes' => array(
+ 'source_context' => array(array('source', 30), 'context'),
+ ),
+ );
+
+ $schema['locales_target'] = array(
+ 'description' => 'Stores translated versions of strings.',
+ 'fields' => array(
+ 'lid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Source string ID. References {locales_source}.lid.',
+ ),
+ 'translation' => array(
+ 'type' => 'text',
+ 'mysql_type' => 'blob',
+ 'not null' => TRUE,
+ 'description' => 'Translation string value in this language.',
+ ),
+ 'language' => array(
+ 'type' => 'varchar',
+ 'length' => 12,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'Language code. References {languages}.language.',
+ ),
+ 'plid' => array(
+ 'type' => 'int',
+ 'not null' => TRUE, // This should be NULL for no referenced string, not zero.
+ 'default' => 0,
+ 'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.',
+ ),
+ 'plural' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Plural index number in case of plural strings.',
+ ),
+ ),
+ 'primary key' => array('language', 'lid', 'plural'),
+ 'foreign keys' => array(
+ 'locales_source' => array(
+ 'table' => 'locales_source',
+ 'columns' => array('lid' => 'lid'),
+ ),
+ ),
+ 'indexes' => array(
+ 'lid' => array('lid'),
+ 'plid' => array('plid'),
+ 'plural' => array('plural'),
+ ),
+ );
+
+ return $schema;
+}
+
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.module b/kolab.org/www/drupal-7.26/modules/locale/locale.module
new file mode 100644
index 0000000..768fead
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.module
@@ -0,0 +1,1098 @@
+<?php
+
+/**
+ * @file
+ * Add language handling functionality and enables the translation of the
+ * user interface to languages other than English.
+ *
+ * When enabled, multiple languages can be set up. The site interface
+ * can be displayed in different languages, as well as nodes can have languages
+ * assigned. The setup of languages and translations is completely web based.
+ * Gettext portable object files are supported.
+ */
+
+// ---------------------------------------------------------------------------------
+// Hook implementations
+
+/**
+ * Implements hook_help().
+ */
+function locale_help($path, $arg) {
+ switch ($path) {
+ case 'admin/help#locale':
+ $output = '';
+ $output .= '<h3>' . t('About') . '</h3>';
+ $output .= '<p>' . t('The Locale module allows your Drupal site to be presented in languages other than the default English, and to be multilingual. The Locale module works by maintaining a database of translations, and examining text as it is about to be displayed. When a translation of the text is available in the language to be displayed, the translation is displayed rather than the original text. When a translation is unavailable, the original text is displayed, and then stored for review by a translator. For more information, see the online handbook entry for <a href="@locale">Locale module</a>.', array('@locale' => 'http://drupal.org/documentation/modules/locale/')) . '</p>';
+ $output .= '<h3>' . t('Uses') . '</h3>';
+ $output .= '<dl>';
+ $output .= '<dt>' . t('Translating interface text') . '</dt>';
+ $output .= '<dd>' . t('Translations of text in the Drupal interface may be provided by:');
+ $output .= '<ul>';
+ $output .= '<li>' . t("Translating within your site, using the Locale module's integrated <a href='@translate'>translation interface</a>.", array('@translate' => url('admin/config/regional/translate'))) . '</li>';
+ $output .= '<li>' . t('Importing files from a set of existing translations, known as a translation package. A translation package enables the display of a specific version of Drupal in a specific language, and contains files in the Gettext Portable Object (<em>.po</em>) format. Although not all languages are available for every version of Drupal, translation packages for many languages are available for download from the <a href="@translations">Drupal translations page</a>.', array('@translations' => 'http://localize.drupal.org')) . '</li>';
+ $output .= '<li>' . t("If an existing translation package does not meet your needs, the Gettext Portable Object (<em>.po</em>) files within a package may be modified, or new <em>.po</em> files may be created, using a desktop Gettext editor. The Locale module's <a href='@import'>import</a> feature allows the translated strings from a new or modified <em>.po</em> file to be added to your site. The Locale module's <a href='@export'>export</a> feature generates files from your site's translated strings, that can either be shared with others or edited offline by a Gettext translation editor.", array('@import' => url('admin/config/regional/translate/import'), '@export' => url('admin/config/regional/translate/export'))) . '</li>';
+ $output .= '</ul></dd>';
+ $output .= '<dt>' . t('Configuring a multilingual site') . '</dt>';
+ $output .= '<dd>' . t("Language negotiation allows your site to automatically change language based on the domain or path used for each request. Users may (optionally) select their preferred language on their <em>My account</em> page, and your site can be configured to honor a web browser's preferred language settings. Site content can be translated using the <a href='@content-help'>Content translation module</a>.", array('@content-help' => url('admin/help/translation'))) . '</dd>';
+ $output .= '</dl>';
+ return $output;
+ case 'admin/config/regional/language':
+ $output = '<p>' . t('With multiple languages enabled, interface text can be translated, registered users may select their preferred language, and authors can assign a specific language to content. <a href="@translations">Download contributed translations</a> from Drupal.org.', array('@translations' => 'http://localize.drupal.org')) . '</p>';
+ return $output;
+ case 'admin/config/regional/language/add':
+ return '<p>' . t('Add a language to be supported by your site. If your desired language is not available in the <em>Language name</em> drop-down, click <em>Custom language</em> and provide a language code and other details manually. When providing a language code manually, be sure to enter a standardized language code, since this code may be used by browsers to determine an appropriate display language.') . '</p>';
+ case 'admin/config/regional/language/configure':
+ $output = '<p>' . t("Define how to decide which language is used to display page elements (primarily text provided by Drupal and modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Define the order of evaluation of language detection methods on this page.") . '</p>';
+ return $output;
+ case 'admin/config/regional/language/configure/session':
+ $output = '<p>' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>';
+ return $output;
+ case 'admin/config/regional/translate':
+ $output = '<p>' . t('This page provides an overview of available translatable strings. Drupal displays translatable strings in text groups; modules may define additional text groups containing other translatable strings. Because text groups provide a method of grouping related strings, they are often used to focus translation efforts on specific areas of the Drupal interface.') . '</p>';
+ $output .= '<p>' . t('See the <a href="@languages">Languages page</a> for more information on adding support for additional languages.', array('@languages' => url('admin/config/regional/language'))) . '</p>';
+ return $output;
+ case 'admin/config/regional/translate/import':
+ $output = '<p>' . t('This page imports the translated strings contained in an individual Gettext Portable Object (<em>.po</em>) file. Normally distributed as part of a translation package (each translation package may contain several <em>.po</em> files), a <em>.po</em> file may need to be imported after offline editing in a Gettext translation editor. Importing an individual <em>.po</em> file may be a lengthy process.') . '</p>';
+ $output .= '<p>' . t('Note that the <em>.po</em> files within a translation package are imported automatically (if available) when new modules or themes are enabled, or as new languages are added. Since this page only allows the import of one <em>.po</em> file at a time, it may be simpler to download and extract a translation package into your Drupal installation directory and <a href="@language-add">add the language</a> (which automatically imports all <em>.po</em> files within the package). Translation packages are available for download on the <a href="@translations">Drupal translation page</a>.', array('@language-add' => url('admin/config/regional/language/add'), '@translations' => 'http://localize.drupal.org')) . '</p>';
+ return $output;
+ case 'admin/config/regional/translate/export':
+ return '<p>' . t('This page exports the translated strings used by your site. An export file may be in Gettext Portable Object (<em>.po</em>) form, which includes both the original string and the translation (used to share translations with others), or in Gettext Portable Object Template (<em>.pot</em>) form, which includes the original strings only (used to create new translations with a Gettext translation editor).') . '</p>';
+ case 'admin/config/regional/translate/translate':
+ return '<p>' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: For translation tasks involving many strings, it may be more convenient to <a href="@export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings found within a specific text group or in a specific language.', array('@export' => url('admin/config/regional/translate/export'))) . '</p>';
+ case 'admin/structure/block/manage/%/%':
+ if ($arg[4] == 'locale' && $arg[5] == 'language') {
+ return '<p>' . t('This block is only shown if <a href="@languages">at least two languages are enabled</a> and <a href="@configuration">language negotiation</a> is set to <em>URL</em> or <em>Session</em>.', array('@languages' => url('admin/config/regional/language'), '@configuration' => url('admin/config/regional/language/configure'))) . '</p>';
+ }
+ break;
+ }
+}
+
+/**
+ * Implements hook_menu().
+ */
+function locale_menu() {
+ // Manage languages
+ $items['admin/config/regional/language'] = array(
+ 'title' => 'Languages',
+ 'description' => 'Configure languages for content and the user interface.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_languages_overview_form'),
+ 'access arguments' => array('administer languages'),
+ 'file' => 'locale.admin.inc',
+ 'weight' => -10,
+ );
+ $items['admin/config/regional/language/overview'] = array(
+ 'title' => 'List',
+ 'weight' => 0,
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ );
+ $items['admin/config/regional/language/add'] = array(
+ 'title' => 'Add language',
+ 'page callback' => 'locale_languages_add_screen', // two forms concatenated
+ 'access arguments' => array('administer languages'),
+ 'weight' => 5,
+ 'type' => MENU_LOCAL_ACTION,
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/language/configure'] = array(
+ 'title' => 'Detection and selection',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_languages_configure_form'),
+ 'access arguments' => array('administer languages'),
+ 'weight' => 10,
+ 'file' => 'locale.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ );
+ $items['admin/config/regional/language/configure/url'] = array(
+ 'title' => 'URL language detection configuration',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_language_providers_url_form'),
+ 'access arguments' => array('administer languages'),
+ 'file' => 'locale.admin.inc',
+ 'type' => MENU_VISIBLE_IN_BREADCRUMB,
+ );
+ $items['admin/config/regional/language/configure/session'] = array(
+ 'title' => 'Session language detection configuration',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_language_providers_session_form'),
+ 'access arguments' => array('administer languages'),
+ 'file' => 'locale.admin.inc',
+ 'type' => MENU_VISIBLE_IN_BREADCRUMB,
+ );
+ $items['admin/config/regional/language/edit/%'] = array(
+ 'title' => 'Edit language',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_languages_edit_form', 5),
+ 'access arguments' => array('administer languages'),
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/language/delete/%'] = array(
+ 'title' => 'Confirm',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_languages_delete_form', 5),
+ 'access arguments' => array('administer languages'),
+ 'file' => 'locale.admin.inc',
+ );
+
+ // Translation functionality
+ $items['admin/config/regional/translate'] = array(
+ 'title' => 'Translate interface',
+ 'description' => 'Translate the built in interface and optionally other text.',
+ 'page callback' => 'locale_translate_overview_screen',
+ 'access arguments' => array('translate interface'),
+ 'file' => 'locale.admin.inc',
+ 'weight' => -5,
+ );
+ $items['admin/config/regional/translate/overview'] = array(
+ 'title' => 'Overview',
+ 'weight' => 0,
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ );
+ $items['admin/config/regional/translate/translate'] = array(
+ 'title' => 'Translate',
+ 'weight' => 10,
+ 'type' => MENU_LOCAL_TASK,
+ 'page callback' => 'locale_translate_seek_screen', // search results and form concatenated
+ 'access arguments' => array('translate interface'),
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/translate/import'] = array(
+ 'title' => 'Import',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_translate_import_form'),
+ 'access arguments' => array('translate interface'),
+ 'weight' => 20,
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/translate/export'] = array(
+ 'title' => 'Export',
+ 'page callback' => 'locale_translate_export_screen', // possibly multiple forms concatenated
+ 'access arguments' => array('translate interface'),
+ 'weight' => 30,
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/translate/edit/%'] = array(
+ 'title' => 'Edit string',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_translate_edit_form', 5),
+ 'access arguments' => array('translate interface'),
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/translate/delete/%'] = array(
+ 'title' => 'Delete string',
+ 'page callback' => 'locale_translate_delete_page',
+ 'page arguments' => array(5),
+ 'access arguments' => array('translate interface'),
+ 'file' => 'locale.admin.inc',
+ );
+
+ // Localize date formats.
+ $items['admin/config/regional/date-time/locale'] = array(
+ 'title' => 'Localize',
+ 'description' => 'Configure date formats for each locale',
+ 'page callback' => 'locale_date_format_language_overview_page',
+ 'access arguments' => array('administer site configuration'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => -8,
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/date-time/locale/%/edit'] = array(
+ 'title' => 'Localize date formats',
+ 'description' => 'Configure date formats for each locale',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_date_format_form', 5),
+ 'access arguments' => array('administer site configuration'),
+ 'file' => 'locale.admin.inc',
+ );
+ $items['admin/config/regional/date-time/locale/%/reset'] = array(
+ 'title' => 'Reset date formats',
+ 'description' => 'Reset localized date formats to global defaults',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('locale_date_format_reset_form', 5),
+ 'access arguments' => array('administer site configuration'),
+ 'file' => 'locale.admin.inc',
+ );
+
+ return $items;
+}
+
+/**
+ * Implements hook_init().
+ *
+ * Initialize date formats according to the user's current locale.
+ */
+function locale_init() {
+ global $conf, $language;
+ include_once DRUPAL_ROOT . '/includes/locale.inc';
+
+ // For each date type (e.g. long, short), get the localized date format
+ // for the user's current language and override the default setting for it
+ // in $conf. This should happen on all pages except the date and time formats
+ // settings page, where we want to display the site default and not the
+ // localized version.
+ if (strpos($_GET['q'], 'admin/config/regional/date-time/formats') !== 0) {
+ $languages = array($language->language);
+
+ // Setup appropriate date formats for this locale.
+ $formats = locale_get_localized_date_format($languages);
+ foreach ($formats as $format_type => $format) {
+ $conf[$format_type] = $format;
+ }
+ }
+}
+
+/**
+ * Implements hook_permission().
+ */
+function locale_permission() {
+ return array(
+ 'administer languages' => array(
+ 'title' => t('Administer languages'),
+ ),
+ 'translate interface' => array(
+ 'title' => t('Translate interface texts'),
+ 'restrict access' => TRUE,
+ ),
+ );
+}
+
+/**
+ * Implements hook_locale().
+ */
+function locale_locale($op = 'groups') {
+ switch ($op) {
+ case 'groups':
+ return array('default' => t('Built-in interface'));
+ }
+}
+
+/**
+ * Form builder callback to display language selection widget.
+ *
+ * @ingroup forms
+ * @see locale_form_alter()
+ */
+function locale_language_selector_form(&$form, &$form_state, $user) {
+ global $language;
+ $languages = language_list('enabled');
+ $languages = $languages[1];
+
+ // If the user is being created, we set the user language to the page language.
+ $user_preferred_language = $user->uid ? user_preferred_language($user) : $language;
+
+ $names = array();
+ foreach ($languages as $langcode => $item) {
+ $name = t($item->name);
+ $names[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
+ }
+ $form['locale'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Language settings'),
+ '#weight' => 1,
+ '#access' => ($form['#user_category'] == 'account' || ($form['#user_category'] == 'register' && user_access('administer users'))),
+ );
+
+ // Get language negotiation settings.
+ $mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT;
+ $form['locale']['language'] = array(
+ '#type' => (count($names) <= 5 ? 'radios' : 'select'),
+ '#title' => t('Language'),
+ '#default_value' => $user_preferred_language->language,
+ '#options' => $names,
+ '#description' => $mode ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
+ );
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function locale_form_path_admin_form_alter(&$form, &$form_state) {
+ $form['language'] = array(
+ '#type' => 'select',
+ '#title' => t('Language'),
+ '#options' => array(LANGUAGE_NONE => t('All languages')) + locale_language_list('name'),
+ '#default_value' => $form['language']['#value'],
+ '#weight' => -10,
+ '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
+ );
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function locale_form_node_type_form_alter(&$form, &$form_state) {
+ if (isset($form['type'])) {
+ $form['workflow']['language_content_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Multilingual support'),
+ '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),
+ '#options' => array(t('Disabled'), t('Enabled')),
+ '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
+ );
+ }
+}
+
+/**
+ * Return whether the given content type has multilingual support.
+ *
+ * @return
+ * True if multilingual support is enabled.
+ */
+function locale_multilingual_node_type($type_name) {
+ return (bool) variable_get('language_content_type_' . $type_name, 0);
+}
+
+/**
+ * Implements hook_form_alter().
+ *
+ * Adds language fields to user forms.
+ */
+function locale_form_alter(&$form, &$form_state, $form_id) {
+ // Only alter user forms if there is more than one language.
+ if (drupal_multilingual()) {
+ // Display language selector when either creating a user on the admin
+ // interface or editing a user account.
+ if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
+ locale_language_selector_form($form, $form_state, $form['#user']);
+ }
+ }
+}
+
+/**
+ * Implements hook_form_BASE_FORM_ID_alter().
+ */
+function locale_form_node_form_alter(&$form, &$form_state) {
+ if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) {
+ $form['language'] = array(
+ '#type' => 'select',
+ '#title' => t('Language'),
+ '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
+ '#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
+ );
+ }
+ // Node type without language selector: assign the default for new nodes
+ elseif (!isset($form['#node']->nid)) {
+ $default = language_default();
+ $form['language'] = array(
+ '#type' => 'value',
+ '#value' => $default->language
+ );
+ }
+ $form['#submit'][] = 'locale_field_node_form_submit';
+}
+
+/**
+ * Form submit handler for node_form().
+ *
+ * This submit handler needs to run before entity_form_submit_build_entity()
+ * is invoked by node_form_submit_build_node(), because it alters the values of
+ * attached fields. Therefore, it cannot be a hook_node_submit() implementation.
+ */
+function locale_field_node_form_submit($form, &$form_state) {
+ locale_field_entity_form_submit('node', $form, $form_state);
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function locale_form_comment_form_alter(&$form, &$form_state, $form_id) {
+ // If a content type has multilingual support we set the content language as
+ // comment language.
+ if ($form['language']['#value'] == LANGUAGE_NONE && locale_multilingual_node_type($form['#node']->type)) {
+ global $language_content;
+ $form['language']['#value'] = $language_content->language;
+ $submit_callback = 'locale_field_comment_form_submit';
+ array_unshift($form['actions']['preview']['#submit'], $submit_callback);
+ array_unshift($form['#submit'], $submit_callback);
+ }
+}
+
+/**
+ * Form submit handler for comment_form().
+ *
+ * This submit handler needs to run before entity_form_submit_build_entity()
+ * is invoked by comment_form_submit_build_comment(), because it alters the
+ * values of attached fields.
+ */
+function locale_field_comment_form_submit($form, &$form_state) {
+ locale_field_entity_form_submit('comment', $form, $form_state);
+}
+
+/**
+ * Handles field language on submit for the given entity type.
+ *
+ * Checks if Locale is registered as a translation handler and handle possible
+ * language changes.
+ */
+function locale_field_entity_form_submit($entity_type, $form, &$form_state ) {
+ if (field_has_translation_handler($entity_type, 'locale')) {
+ $entity = (object) $form_state['values'];
+ $current_language = entity_language($entity_type, $entity);
+ list(, , $bundle) = entity_extract_ids($entity_type, $entity);
+
+ foreach (field_info_instances($entity_type, $bundle) as $instance) {
+ $field_name = $instance['field_name'];
+ $field = field_info_field($field_name);
+ $previous_language = $form[$field_name]['#language'];
+
+ // Handle a possible language change: new language values are inserted,
+ // previous ones are deleted.
+ if ($field['translatable'] && $previous_language != $current_language) {
+ $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
+ $form_state['values'][$field_name][$previous_language] = array();
+ }
+ }
+ }
+}
+
+/**
+ * Implements hook_theme().
+ */
+function locale_theme() {
+ return array(
+ 'locale_languages_overview_form' => array(
+ 'render element' => 'form',
+ ),
+ 'locale_languages_configure_form' => array(
+ 'render element' => 'form',
+ ),
+ 'locale_date_format_form' => array(
+ 'render element' => 'form',
+ ),
+ );
+}
+
+/**
+ * Implements hook_field_language_alter().
+ */
+function locale_field_language_alter(&$display_language, $context) {
+ // Do not apply core language fallback rules if they are disabled or if Locale
+ // is not registered as a translation handler.
+ if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {
+ locale_field_language_fallback($display_language, $context['entity'], $context['language']);
+ }
+}
+
+/**
+ * Applies language fallback rules to the fields attached to the given entity.
+ *
+ * Core language fallback rules simply check if fields have a field translation
+ * for the requested language code. If so the requested language is returned,
+ * otherwise all the fallback candidates are inspected to see if there is a
+ * field translation available in another language.
+ * By default this is called by locale_field_language_alter(), but this
+ * behavior can be disabled by setting the 'locale_field_language_fallback'
+ * variable to FALSE.
+ *
+ * @param $display_language
+ * A reference to an array of language codes keyed by field name.
+ * @param $entity
+ * The entity to be displayed.
+ * @param $langcode
+ * The language code $entity has to be displayed in.
+ */
+function locale_field_language_fallback(&$display_language, $entity, $langcode) {
+ // Lazily init fallback candidates to avoid unnecessary calls.
+ $fallback_candidates = NULL;
+ $field_languages = array();
+
+ foreach ($display_language as $field_name => $field_language) {
+ // If the requested language is defined for the current field use it,
+ // otherwise search for a fallback value among the fallback candidates.
+ if (isset($entity->{$field_name}[$langcode])) {
+ $display_language[$field_name] = $langcode;
+ }
+ elseif (!empty($entity->{$field_name})) {
+ if (!isset($fallback_candidates)) {
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ $fallback_candidates = language_fallback_get_candidates();
+ }
+ foreach ($fallback_candidates as $fallback_language) {
+ if (isset($entity->{$field_name}[$fallback_language])) {
+ $display_language[$field_name] = $fallback_language;
+ break;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements hook_entity_info_alter().
+ */
+function locale_entity_info_alter(&$entity_info) {
+ $entity_info['node']['translation']['locale'] = TRUE;
+ if (isset($entity_info['comment'])) {
+ $entity_info['comment']['translation']['locale'] = TRUE;
+ }
+}
+
+/**
+ * Implements hook_language_types_info().
+ *
+ * Defines the three core language types:
+ * - Interface language is the only configurable language type in core. It is
+ * used by t() as the default language if none is specified.
+ * - Content language is by default non-configurable and inherits the interface
+ * language negotiated value. It is used by the Field API to determine the
+ * display language for fields if no explicit value is specified.
+ * - URL language is by default non-configurable and is determined through the
+ * URL language provider or the URL fallback provider if no language can be
+ * detected. It is used by l() as the default language if none is specified.
+ */
+function locale_language_types_info() {
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ return array(
+ LANGUAGE_TYPE_INTERFACE => array(
+ 'name' => t('User interface text'),
+ 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'),
+ ),
+ LANGUAGE_TYPE_CONTENT => array(
+ 'name' => t('Content'),
+ 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
+ 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE),
+ ),
+ LANGUAGE_TYPE_URL => array(
+ 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK),
+ ),
+ );
+}
+
+/**
+ * Implements hook_language_negotiation_info().
+ */
+function locale_language_negotiation_info() {
+ $file = 'includes/locale.inc';
+ $providers = array();
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_URL] = array(
+ 'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL),
+ 'callbacks' => array(
+ 'language' => 'locale_language_from_url',
+ 'switcher' => 'locale_language_switcher_url',
+ 'url_rewrite' => 'locale_language_url_rewrite_url',
+ ),
+ 'file' => $file,
+ 'weight' => -8,
+ 'name' => t('URL'),
+ 'description' => t('Determine the language from the URL (Path prefix or domain).'),
+ 'config' => 'admin/config/regional/language/configure/url',
+ );
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_SESSION] = array(
+ 'callbacks' => array(
+ 'language' => 'locale_language_from_session',
+ 'switcher' => 'locale_language_switcher_session',
+ 'url_rewrite' => 'locale_language_url_rewrite_session',
+ ),
+ 'file' => $file,
+ 'weight' => -6,
+ 'name' => t('Session'),
+ 'description' => t('Determine the language from a request/session parameter.'),
+ 'config' => 'admin/config/regional/language/configure/session',
+ );
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_USER] = array(
+ 'callbacks' => array('language' => 'locale_language_from_user'),
+ 'file' => $file,
+ 'weight' => -4,
+ 'name' => t('User'),
+ 'description' => t("Follow the user's language preference."),
+ );
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_BROWSER] = array(
+ 'callbacks' => array('language' => 'locale_language_from_browser'),
+ 'file' => $file,
+ 'weight' => -2,
+ 'cache' => 0,
+ 'name' => t('Browser'),
+ 'description' => t("Determine the language from the browser's language settings."),
+ );
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_INTERFACE] = array(
+ 'types' => array(LANGUAGE_TYPE_CONTENT),
+ 'callbacks' => array('language' => 'locale_language_from_interface'),
+ 'file' => $file,
+ 'weight' => 8,
+ 'name' => t('Interface'),
+ 'description' => t('Use the detected interface language.'),
+ );
+
+ $providers[LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK] = array(
+ 'types' => array(LANGUAGE_TYPE_URL),
+ 'callbacks' => array('language' => 'locale_language_url_fallback'),
+ 'file' => $file,
+ 'weight' => 8,
+ 'name' => t('URL fallback'),
+ 'description' => t('Use an already detected language for URLs if none is found.'),
+ );
+
+ return $providers;
+}
+
+/**
+ * Implements hook_modules_enabled().
+ */
+function locale_modules_enabled($modules) {
+ include_once DRUPAL_ROOT . '/includes/language.inc';
+ language_types_set();
+ language_negotiation_purge();
+}
+
+/**
+ * Implements hook_modules_disabled().
+ */
+function locale_modules_disabled($modules) {
+ locale_modules_enabled($modules);
+}
+
+// ---------------------------------------------------------------------------------
+// Locale core functionality
+
+/**
+ * Provides interface translation services.
+ *
+ * This function is called from t() to translate a string if needed.
+ *
+ * @param $string
+ * A string to look up translation for. If omitted, all the
+ * cached strings will be returned in all languages already
+ * used on the page.
+ * @param $context
+ * The context of this string.
+ * @param $langcode
+ * Language code to use for the lookup.
+ */
+function locale($string = NULL, $context = NULL, $langcode = NULL) {
+ global $language;
+
+ // Use the advanced drupal_static() pattern, since this is called very often.
+ static $drupal_static_fast;
+ if (!isset($drupal_static_fast)) {
+ $drupal_static_fast['locale'] = &drupal_static(__FUNCTION__);
+ }
+ $locale_t = &$drupal_static_fast['locale'];
+
+
+ if (!isset($string)) {
+ // Return all cached strings if no string was specified
+ return $locale_t;
+ }
+
+ $langcode = isset($langcode) ? $langcode : $language->language;
+
+ // Store database cached translations in a static variable. Only build the
+ // cache after $language has been set to avoid an unnecessary cache rebuild.
+ if (!isset($locale_t[$langcode]) && isset($language)) {
+ $locale_t[$langcode] = array();
+ // Disabling the usage of string caching allows a module to watch for
+ // the exact list of strings used on a page. From a performance
+ // perspective that is a really bad idea, so we have no user
+ // interface for this. Be careful when turning this option off!
+ if (variable_get('locale_cache_strings', 1) == 1) {
+ if ($cache = cache_get('locale:' . $langcode, 'cache')) {
+ $locale_t[$langcode] = $cache->data;
+ }
+ elseif (lock_acquire('locale_cache_' . $langcode)) {
+ // Refresh database stored cache of translations for given language.
+ // We only store short strings used in current version, to improve
+ // performance and consume less memory.
+ $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75)));
+ foreach ($result as $data) {
+ $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
+ }
+ cache_set('locale:' . $langcode, $locale_t[$langcode]);
+ lock_release('locale_cache_' . $langcode);
+ }
+ }
+ }
+
+ // If we have the translation cached, skip checking the database
+ if (!isset($locale_t[$langcode][$context][$string])) {
+
+ // We do not have this translation cached, so get it from the DB.
+ $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
+ ':language' => $langcode,
+ ':source' => $string,
+ ':context' => (string) $context,
+ ))->fetchObject();
+ if ($translation) {
+ // We have the source string at least.
+ // Cache translation string or TRUE if no translation exists.
+ $locale_t[$langcode][$context][$string] = (empty($translation->translation) ? TRUE : $translation->translation);
+
+ if ($translation->version != VERSION) {
+ // This is the first use of this string under current Drupal version. Save version
+ // and clear cache, to include the string into caching next time. Saved version is
+ // also a string-history information for later pruning of the tables.
+ db_update('locales_source')
+ ->fields(array('version' => VERSION))
+ ->condition('lid', $translation->lid)
+ ->execute();
+ cache_clear_all('locale:', 'cache', TRUE);
+ }
+ }
+ else {
+ // We don't have the source string, cache this as untranslated.
+ db_merge('locales_source')
+ ->insertFields(array(
+ 'location' => request_uri(),
+ 'version' => VERSION,
+ ))
+ ->key(array(
+ 'source' => $string,
+ 'context' => (string) $context,
+ 'textgroup' => 'default',
+ ))
+ ->execute();
+ $locale_t[$langcode][$context][$string] = TRUE;
+ // Clear locale cache so this string can be added in a later request.
+ cache_clear_all('locale:', 'cache', TRUE);
+ }
+ }
+
+ return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]);
+}
+
+/**
+ * Reset static variables used by locale().
+ */
+function locale_reset() {
+ drupal_static_reset('locale');
+}
+
+/**
+ * Returns plural form index for a specific number.
+ *
+ * The index is computed from the formula of this language.
+ *
+ * @param $count
+ * Number to return plural for.
+ * @param $langcode
+ * Optional language code to translate to a language other than
+ * what is used to display the page.
+ *
+ * @return
+ * The numeric index of the plural variant to use for this $langcode and
+ * $count combination or -1 if the language was not found or does not have a
+ * plural formula.
+ */
+function locale_get_plural($count, $langcode = NULL) {
+ global $language;
+
+ // Used to locally cache the plural formulas for all languages.
+ $plural_formulas = &drupal_static(__FUNCTION__, array());
+
+ // Used to store precomputed plural indexes corresponding to numbers
+ // individually for each language.
+ $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array());
+
+ $langcode = $langcode ? $langcode : $language->language;
+
+ if (!isset($plural_indexes[$langcode][$count])) {
+ // Retrieve and statically cache the plural formulas for all languages.
+ if (empty($plural_formulas)) {
+ foreach (language_list() as $installed_language) {
+ $plural_formulas[$installed_language->language] = $installed_language->formula;
+ }
+ }
+ // If there is a plural formula for the language, evaluate it for the given
+ // $count and statically cache the result for the combination of language
+ // and count, since the result will always be identical.
+ if (!empty($plural_formulas[$langcode])) {
+ // $n is used inside the expression in the eval().
+ $n = $count;
+ $plural_indexes[$langcode][$count] = @eval('return intval(' . $plural_formulas[$langcode] . ');');
+ }
+ // In case there is no plural formula for English (no imported translation
+ // for English), use a default formula.
+ elseif ($langcode == 'en') {
+ $plural_indexes[$langcode][$count] = (int) ($count != 1);
+ }
+ // Otherwise, return -1 (unknown).
+ else {
+ $plural_indexes[$langcode][$count] = -1;
+ }
+ }
+ return $plural_indexes[$langcode][$count];
+}
+
+
+/**
+ * Returns a language name
+ */
+function locale_language_name($lang) {
+ $list = &drupal_static(__FUNCTION__);
+ if (!isset($list)) {
+ $list = locale_language_list();
+ }
+ return ($lang && isset($list[$lang])) ? $list[$lang] : t('All');
+}
+
+/**
+ * Returns array of language names
+ *
+ * @param $field
+ * 'name' => names in current language, localized
+ * 'native' => native names
+ * @param $all
+ * Boolean to return all languages or only enabled ones
+ */
+function locale_language_list($field = 'name', $all = FALSE) {
+ if ($all) {
+ $languages = language_list();
+ }
+ else {
+ $languages = language_list('enabled');
+ $languages = $languages[1];
+ }
+ $list = array();
+ foreach ($languages as $language) {
+ $list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field;
+ }
+ return $list;
+}
+
+/**
+ * Implements hook_modules_installed().
+ */
+function locale_modules_installed($modules) {
+ locale_system_update($modules);
+}
+
+/**
+ * Implements hook_themes_enabled().
+ *
+ * @todo This is technically wrong. We must not import upon enabling, but upon
+ * initial installation. The theme system is missing an installation hook.
+ */
+function locale_themes_enabled($themes) {
+ locale_system_update($themes);
+}
+
+/**
+ * Imports translations when new modules or themes are installed.
+ *
+ * This function will either import translation for the component change
+ * right away, or start a batch if more files need to be imported.
+ *
+ * @param $components
+ * An array of component (theme and/or module) names to import
+ * translations for.
+ */
+function locale_system_update($components) {
+ include_once DRUPAL_ROOT . '/includes/locale.inc';
+ if ($batch = locale_batch_by_component($components)) {
+ batch_set($batch);
+ }
+}
+
+/**
+ * Implements hook_js_alter().
+ *
+ * This function checks all JavaScript files currently added via drupal_add_js()
+ * and invokes parsing if they have not yet been parsed for Drupal.t()
+ * and Drupal.formatPlural() calls. Also refreshes the JavaScript translation
+ * file if necessary, and adds it to the page.
+ */
+function locale_js_alter(&$javascript) {
+ global $language;
+
+ $dir = 'public://' . variable_get('locale_js_directory', 'languages');
+ $parsed = variable_get('javascript_parsed', array());
+ $files = $new_files = FALSE;
+
+ // Require because locale_js_alter() could be called without locale_init().
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+
+ foreach ($javascript as $item) {
+ if ($item['type'] == 'file') {
+ $files = TRUE;
+ $filepath = $item['data'];
+ if (!in_array($filepath, $parsed)) {
+ // Don't parse our own translations files.
+ if (substr($filepath, 0, strlen($dir)) != $dir) {
+ _locale_parse_js_file($filepath);
+ $parsed[] = $filepath;
+ $new_files = TRUE;
+ }
+ }
+ }
+ }
+
+ // If there are any new source files we parsed, invalidate existing
+ // JavaScript translation files for all languages, adding the refresh
+ // flags into the existing array.
+ if ($new_files) {
+ $parsed += _locale_invalidate_js();
+ }
+
+ // If necessary, rebuild the translation file for the current language.
+ if (!empty($parsed['refresh:' . $language->language])) {
+ // Don't clear the refresh flag on failure, so that another try will
+ // be performed later.
+ if (_locale_rebuild_js()) {
+ unset($parsed['refresh:' . $language->language]);
+ }
+ // Store any changes after refresh was attempted.
+ variable_set('javascript_parsed', $parsed);
+ }
+ // If no refresh was attempted, but we have new source files, we need
+ // to store them too. This occurs if current page is in English.
+ elseif ($new_files) {
+ variable_set('javascript_parsed', $parsed);
+ }
+
+ // Add the translation JavaScript file to the page.
+ if ($files && !empty($language->javascript)) {
+ // Add the translation JavaScript file to the page.
+ $file = $dir . '/' . $language->language . '_' . $language->javascript . '.js';
+ $javascript[$file] = drupal_js_defaults($file);
+ }
+}
+
+/**
+ * Implements hook_css_alter().
+ *
+ * This function checks all CSS files currently added via drupal_add_css() and
+ * and checks to see if a related right to left CSS file should be included.
+ */
+function locale_css_alter(&$css) {
+ global $language;
+
+ // If the current language is RTL, add the CSS file with the RTL overrides.
+ if ($language->direction == LANGUAGE_RTL) {
+ foreach ($css as $data => $item) {
+ // Only provide RTL overrides for files.
+ if ($item['type'] == 'file') {
+ $rtl_path = str_replace('.css', '-rtl.css', $item['data']);
+ if (file_exists($rtl_path) && !isset($css[$rtl_path])) {
+ // Replicate the same item, but with the RTL path and a little larger
+ // weight so that it appears directly after the original CSS file.
+ $item['data'] = $rtl_path;
+ $item['weight'] += 0.0001;
+ $css[$rtl_path] = $item;
+ }
+ }
+ }
+ }
+}
+
+ /**
+ * Implement hook_library_alter().
+ *
+ * Provides the language support for the jQuery UI Date Picker.
+ */
+function locale_library_alter(&$libraries, $module) {
+ if ($module == 'system' && isset($libraries['ui.datepicker'])) {
+ global $language;
+ // locale.datepicker.js should be added in the JS_LIBRARY group, so that
+ // this attach behavior will execute early. JS_LIBRARY is the default for
+ // hook_library_info_alter(), thus does not have to be specified explicitly.
+ $datepicker = drupal_get_path('module', 'locale') . '/locale.datepicker.js';
+ $libraries['ui.datepicker']['js'][$datepicker] = array();
+ $libraries['ui.datepicker']['js'][] = array(
+ 'data' => array(
+ 'jquery' => array(
+ 'ui' => array(
+ 'datepicker' => array(
+ 'isRTL' => $language->direction == LANGUAGE_RTL,
+ 'firstDay' => variable_get('date_first_day', 0),
+ ),
+ ),
+ ),
+ ),
+ 'type' => 'setting',
+ );
+ }
+}
+
+// ---------------------------------------------------------------------------------
+// Language switcher block
+
+/**
+ * Implements hook_block_info().
+ */
+function locale_block_info() {
+ include_once DRUPAL_ROOT . '/includes/language.inc';
+ $block = array();
+ $info = language_types_info();
+ foreach (language_types_configurable(FALSE) as $type) {
+ $block[$type] = array(
+ 'info' => t('Language switcher (@type)', array('@type' => $info[$type]['name'])),
+ // Not worth caching.
+ 'cache' => DRUPAL_NO_CACHE,
+ );
+ }
+ return $block;
+}
+
+/**
+ * Implements hook_block_view().
+ *
+ * Displays a language switcher. Only show if we have at least two languages.
+ */
+function locale_block_view($type) {
+ if (drupal_multilingual()) {
+ $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
+ $links = language_negotiation_get_switch_links($type, $path);
+
+ if (isset($links->links)) {
+ drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
+ $class = "language-switcher-{$links->provider}";
+ $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
+ $block['content'] = theme('links__locale_block', $variables);
+ $block['subject'] = t('Languages');
+ return $block;
+ }
+ }
+}
+
+/**
+ * Implements hook_url_outbound_alter().
+ *
+ * Rewrite outbound URLs with language based prefixes.
+ */
+function locale_url_outbound_alter(&$path, &$options, $original_path) {
+ // Only modify internal URLs.
+ if (!$options['external'] && drupal_multilingual()) {
+ static $drupal_static_fast;
+ if (!isset($drupal_static_fast)) {
+ $drupal_static_fast['callbacks'] = &drupal_static(__FUNCTION__);
+ }
+ $callbacks = &$drupal_static_fast['callbacks'];
+
+ if (!isset($callbacks)) {
+ $callbacks = array();
+ include_once DRUPAL_ROOT . '/includes/language.inc';
+
+ foreach (language_types_configurable() as $type) {
+ // Get URL rewriter callbacks only from enabled language providers.
+ $negotiation = variable_get("language_negotiation_$type", array());
+
+ foreach ($negotiation as $id => $provider) {
+ if (isset($provider['callbacks']['url_rewrite'])) {
+ if (isset($provider['file'])) {
+ require_once DRUPAL_ROOT . '/' . $provider['file'];
+ }
+ // Avoid duplicate callback entries.
+ $callbacks[$provider['callbacks']['url_rewrite']] = TRUE;
+ }
+ }
+ }
+
+ $callbacks = array_keys($callbacks);
+ }
+
+ foreach ($callbacks as $callback) {
+ $callback($path, $options);
+ }
+
+ // No language dependent path allowed in this mode.
+ if (empty($callbacks)) {
+ unset($options['language']);
+ }
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/locale.test b/kolab.org/www/drupal-7.26/modules/locale/locale.test
new file mode 100644
index 0000000..9ffec9f
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/locale.test
@@ -0,0 +1,3143 @@
+<?php
+
+/**
+ * @file
+ * Tests for locale.module.
+ *
+ * The test file includes:
+ * - a functional test for the language configuration forms;
+ * - functional tests for the translation functionalities, including searching;
+ * - a functional test for the PO files import feature, including validation;
+ * - functional tests for translations and templates export feature;
+ * - functional tests for the uninstall process;
+ * - a functional test for the language switching feature;
+ * - a functional test for a user's ability to change their default language;
+ * - a functional test for configuring a different path alias per language;
+ * - a functional test for configuring a different path alias per language;
+ * - a functional test for multilingual support by content type and on nodes.
+ * - a functional test for multilingual fields.
+ * - a functional test for comment language.
+ * - a functional test fot language types/negotiation info.
+ */
+
+
+/**
+ * Functional tests for the language configuration forms.
+ */
+class LocaleConfigurationTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Language configuration',
+ 'description' => 'Adds a new locale and tests changing its status and the default language.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ /**
+ * Functional tests for adding, editing and deleting languages.
+ */
+ function testLanguageConfiguration() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ $this->drupalLogin($admin_user);
+
+ // Add predefined language.
+ $edit = array(
+ 'langcode' => 'fr',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+ $this->assertText('fr', 'Language added successfully.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+
+ // Add custom language.
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertText($langcode, 'Language code found.');
+ $this->assertText($name, 'Name found.');
+ $this->assertText($native, 'Native found.');
+ $this->assertText($native, 'Test language added.');
+
+ // Check if we can change the default language.
+ $path = 'admin/config/regional/language';
+ $this->drupalGet($path);
+ $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
+ // Change the default language.
+ $edit = array(
+ 'site_default' => $langcode,
+ );
+ $this->drupalPost(NULL, $edit, t('Save configuration'));
+ $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+
+ // Check if a valid language prefix is added after changing the default
+ // language.
+ $this->drupalGet('admin/config/regional/language/edit/en');
+ $this->assertFieldByXPath('//input[@name="prefix"]', 'en', 'A valid path prefix has been added to the previous default language.');
+
+ // Ensure we can't delete the default language.
+ $this->drupalGet('admin/config/regional/language/delete/' . $langcode);
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertText(t('The default language cannot be deleted.'), 'Failed to delete the default language.');
+
+ // Check if we can disable a language.
+ $edit = array(
+ 'enabled[en]' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Save configuration'));
+ $this->assertNoFieldChecked('edit-enabled-en', 'Language disabled.');
+
+ // Set disabled language to be the default and ensure it is re-enabled.
+ $edit = array(
+ 'site_default' => 'en',
+ );
+ $this->drupalPost(NULL, $edit, t('Save configuration'));
+ $this->assertFieldChecked('edit-enabled-en', 'Default language re-enabled.');
+
+ // Ensure 'edit' link works.
+ $this->clickLink(t('edit'));
+ $this->assertTitle(t('Edit language | Drupal'), 'Page title is "Edit language".');
+ // Edit a language.
+ $name = $this->randomName(16);
+ $edit = array(
+ 'name' => $name,
+ );
+ $this->drupalPost('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language'));
+ $this->assertRaw($name, 'The language has been updated.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+
+ // Ensure 'delete' link works.
+ $this->drupalGet('admin/config/regional/language');
+ $this->clickLink(t('delete'));
+ $this->assertText(t('Are you sure you want to delete the language'), '"delete" link is correct.');
+ // Delete an enabled language.
+ $this->drupalGet('admin/config/regional/language/delete/' . $langcode);
+ // First test the 'cancel' link.
+ $this->clickLink(t('Cancel'));
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertRaw($name, 'The language was not deleted.');
+ // Delete the language for real. This a confirm form, we do not need any
+ // fields changed.
+ $this->drupalPost('admin/config/regional/language/delete/' . $langcode, array(), t('Delete'));
+ // We need raw here because %locale will add HTML.
+ $this->assertRaw(t('The language %locale has been removed.', array('%locale' => $name)), 'The test language has been removed.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ // Verify that language is no longer found.
+ $this->drupalGet('admin/config/regional/language/delete/' . $langcode);
+ $this->assertResponse(404, 'Language no longer found.');
+ // Make sure the "language_count" variable has been updated correctly.
+ drupal_static_reset('language_list');
+ $enabled = language_list('enabled');
+ $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), 'Language count is correct.');
+ // Delete a disabled language.
+ // Disable an enabled language.
+ $edit = array(
+ 'enabled[fr]' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Save configuration'));
+ $this->assertNoFieldChecked('edit-enabled-fr', 'French language disabled.');
+ // Get the count of enabled languages.
+ drupal_static_reset('language_list');
+ $enabled = language_list('enabled');
+ // Delete the disabled language.
+ $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete'));
+ // We need raw here because %locale will add HTML.
+ $this->assertRaw(t('The language %locale has been removed.', array('%locale' => 'French')), 'Disabled language has been removed.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ // Verify that language is no longer found.
+ $this->drupalGet('admin/config/regional/language/delete/fr');
+ $this->assertResponse(404, 'Language no longer found.');
+ // Make sure the "language_count" variable has not changed.
+ $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), 'Language count is correct.');
+
+
+ // Ensure we can't delete the English language.
+ $this->drupalGet('admin/config/regional/language/delete/en');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertText(t('The English language cannot be deleted.'), 'Failed to delete English language.');
+ }
+
+}
+
+/**
+ * Tests localization of the JavaScript libraries.
+ *
+ * Currently, only the jQuery datepicker is localized using Drupal translations.
+ */
+class LocaleLibraryInfoAlterTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Javascript library localisation',
+ 'description' => 'Tests the localisation of JavaScript libraries.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+ }
+
+ /**
+ * Verifies that the datepicker can be localized.
+ *
+ * @see locale_library_info_alter()
+ */
+ public function testLibraryInfoAlter() {
+ drupal_add_library('system', 'ui.datepicker');
+ $scripts = drupal_get_js();
+ $this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.');
+ }
+}
+
+/**
+ * Functional tests for JavaScript parsing for translatable strings.
+ */
+class LocaleJavascriptTranslationTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Javascript translation',
+ 'description' => 'Tests parsing js files for translatable strings',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+ }
+
+ function testFileParsing() {
+
+ $filename = drupal_get_path('module', 'locale_test') . '/locale_test.js';
+
+ // Parse the file to look for source strings.
+ _locale_parse_js_file($filename);
+
+ // Get all of the source strings that were found.
+ $source_strings = db_select('locales_source', 's')
+ ->fields('s', array('source', 'context'))
+ ->condition('s.location', $filename)
+ ->execute()
+ ->fetchAllKeyed();
+
+ // List of all strings that should be in the file.
+ $test_strings = array(
+ "Standard Call t" => '',
+ "Whitespace Call t" => '',
+
+ "Single Quote t" => '',
+ "Single Quote \\'Escaped\\' t" => '',
+ "Single Quote Concat strings t" => '',
+
+ "Double Quote t" => '',
+ "Double Quote \\\"Escaped\\\" t" => '',
+ "Double Quote Concat strings t" => '',
+
+ "Context !key Args t" => "Context string",
+
+ "Context Unquoted t" => "Context string unquoted",
+ "Context Single Quoted t" => "Context string single quoted",
+ "Context Double Quoted t" => "Context string double quoted",
+
+ "Standard Call plural" => '',
+ "Standard Call @count plural" => '',
+ "Whitespace Call plural" => '',
+ "Whitespace Call @count plural" => '',
+
+ "Single Quote plural" => '',
+ "Single Quote @count plural" => '',
+ "Single Quote \\'Escaped\\' plural" => '',
+ "Single Quote \\'Escaped\\' @count plural" => '',
+
+ "Double Quote plural" => '',
+ "Double Quote @count plural" => '',
+ "Double Quote \\\"Escaped\\\" plural" => '',
+ "Double Quote \\\"Escaped\\\" @count plural" => '',
+
+ "Context !key Args plural" => "Context string",
+ "Context !key Args @count plural" => "Context string",
+
+ "Context Unquoted plural" => "Context string unquoted",
+ "Context Unquoted @count plural" => "Context string unquoted",
+ "Context Single Quoted plural" => "Context string single quoted",
+ "Context Single Quoted @count plural" => "Context string single quoted",
+ "Context Double Quoted plural" => "Context string double quoted",
+ "Context Double Quoted @count plural" => "Context string double quoted",
+ );
+
+ // Assert that all strings were found properly.
+ foreach ($test_strings as $str => $context) {
+ $args = array('%source' => $str, '%context' => $context);
+
+ // Make sure that the string was found in the file.
+ $this->assertTrue(isset($source_strings[$str]), format_string('Found source string: %source', $args));
+
+ // Make sure that the proper context was matched.
+ $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, strlen($context) > 0 ? format_string('Context for %source is %context', $args) : format_string('Context for %source is blank', $args));
+ }
+
+ $this->assertEqual(count($source_strings), count($test_strings), 'Found correct number of source strings.');
+ }
+}
+/**
+ * Functional test for string translation and validation.
+ */
+class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'String translate, search and validate',
+ 'description' => 'Adds a new locale and translates its name. Checks the validation of translation strings and search results.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ /**
+ * Adds a language and tests string translation by users with the appropriate permissions.
+ */
+ function testStringTranslation() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ // User to translate and delete string.
+ $translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language. This will be translated.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ // This is the language indicator on the translation search screen for
+ // untranslated strings. Copied straight from locale.inc.
+ $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
+ // This will be the translation of $name.
+ $translation = $this->randomName(16);
+
+ // Add custom language.
+ $this->drupalLogin($admin_user);
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Add string.
+ t($name, array(), array('langcode' => $langcode));
+ // Reset locale cache.
+ locale_reset();
+ $this->assertText($langcode, 'Language code found.');
+ $this->assertText($name, 'Name found.');
+ $this->assertText($native, 'Native found.');
+ // No t() here, we do not want to add this string to the database and it's
+ // surely not translated yet.
+ $this->assertText($native, 'Test language added.');
+ $this->drupalLogout();
+
+ // Search for the name and translate it.
+ $this->drupalLogin($translate_user);
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // assertText() seems to remove the input field where $name always could be
+ // found, so this is not a false assert. See how assertNoText succeeds
+ // later.
+ $this->assertText($name, 'Search found the name.');
+ $this->assertRaw($language_indicator, 'Name is untranslated.');
+ // Assume this is the only result, given the random name.
+ $this->clickLink(t('edit'));
+ // We save the lid from the path.
+ $matches = array();
+ preg_match('!admin/config/regional/translate/edit/(\d+)!', $this->getUrl(), $matches);
+ $lid = $matches[1];
+ // No t() here, it's surely not translated yet.
+ $this->assertText($name, 'name found on edit screen.');
+ $edit = array(
+ "translations[$langcode]" => $translation,
+ );
+ $this->drupalPost(NULL, $edit, t('Save translations'));
+ $this->assertText(t('The string has been saved.'), 'The string has been saved.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, 't() works.');
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // The indicator should not be here.
+ $this->assertNoRaw($language_indicator, 'String is translated.');
+
+ // Try to edit a non-existent string and ensure we're redirected correctly.
+ // Assuming we don't have 999,999 strings already.
+ $random_lid = 999999;
+ $this->drupalGet('admin/config/regional/translate/edit/' . $random_lid);
+ $this->assertText(t('String not found'), 'String not found.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->drupalLogout();
+
+ // Delete the language.
+ $this->drupalLogin($admin_user);
+ $path = 'admin/config/regional/language/delete/' . $langcode;
+ // This a confirm form, we do not need any fields changed.
+ $this->drupalPost($path, array(), t('Delete'));
+ // We need raw here because %locale will add HTML.
+ $this->assertRaw(t('The language %locale has been removed.', array('%locale' => $name)), 'The test language has been removed.');
+ // Reload to remove $name.
+ $this->drupalGet($path);
+ // Verify that language is no longer found.
+ $this->assertResponse(404, 'Language no longer found.');
+ $this->drupalLogout();
+
+ // Delete the string.
+ $this->drupalLogin($translate_user);
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // Assume this is the only result, given the random name.
+ $this->clickLink(t('delete'));
+ $this->assertText(t('Are you sure you want to delete the string'), '"delete" link is correct.');
+ // Delete the string.
+ $path = 'admin/config/regional/translate/delete/' . $lid;
+ $this->drupalGet($path);
+ // First test the 'cancel' link.
+ $this->clickLink(t('Cancel'));
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertRaw($name, 'The string was not deleted.');
+ // Delete the name string.
+ $this->drupalPost('admin/config/regional/translate/delete/' . $lid, array(), t('Delete'));
+ $this->assertText(t('The string has been removed.'), 'The string has been removed message.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText($name, 'Search now can not find the name.');
+ }
+
+ /*
+ * Adds a language and checks that the JavaScript translation files are
+ * properly created and rebuilt on deletion.
+ */
+ function testJavaScriptTranslation() {
+ $user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages'));
+ $this->drupalLogin($user);
+
+ $langcode = 'xx';
+ // The English name for the language. This will be translated.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+
+ // Add custom language.
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ drupal_static_reset('language_list');
+
+ // Build the JavaScript translation file.
+ $this->drupalGet('admin/config/regional/translate/translate');
+
+ // Retrieve the id of the first string available in the {locales_source}
+ // table and translate it.
+ $query = db_select('locales_source', 'l');
+ $query->addExpression('min(l.lid)', 'lid');
+ $result = $query->condition('l.location', '%.js%', 'LIKE')
+ ->condition('l.textgroup', 'default')
+ ->execute();
+ $url = 'admin/config/regional/translate/edit/' . $result->fetchObject()->lid;
+ $edit = array('translations['. $langcode .']' => $this->randomName());
+ $this->drupalPost($url, $edit, t('Save translations'));
+
+ // Trigger JavaScript translation parsing and building.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ _locale_rebuild_js($langcode);
+
+ // Retrieve the JavaScript translation hash code for the custom language to
+ // check that the translation file has been properly built.
+ $file = db_select('languages', 'l')
+ ->fields('l', array('javascript'))
+ ->condition('language', $langcode)
+ ->execute()
+ ->fetchObject();
+ $js_file = 'public://' . variable_get('locale_js_directory', 'languages') . '/' . $langcode . '_' . $file->javascript . '.js';
+ $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file created: %file', array('%file' => $result ? $js_file : 'not found')));
+
+ // Test JavaScript translation rebuilding.
+ file_unmanaged_delete($js_file);
+ $this->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
+ cache_clear_all();
+ _locale_rebuild_js($langcode);
+ $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : 'not found')));
+ }
+
+ /**
+ * Tests the validation of the translation input.
+ */
+ function testStringValidation() {
+ global $base_url;
+
+ // User to add language and strings.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface'));
+ $this->drupalLogin($admin_user);
+ $langcode = 'xx';
+ // The English name for the language. This will be translated.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ // This is the language indicator on the translation search screen for
+ // untranslated strings. Copied straight from locale.inc.
+ $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
+ // These will be the invalid translations of $name.
+ $key = $this->randomName(16);
+ $bad_translations[$key] = "<script>alert('xss');</script>" . $key;
+ $key = $this->randomName(16);
+ $bad_translations[$key] = '<img SRC="javascript:alert(\'xss\');">' . $key;
+ $key = $this->randomName(16);
+ $bad_translations[$key] = '<<SCRIPT>alert("xss");//<</SCRIPT>' . $key;
+ $key = $this->randomName(16);
+ $bad_translations[$key] ="<BODY ONLOAD=alert('xss')>" . $key;
+
+ // Add custom language.
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Add string.
+ t($name, array(), array('langcode' => $langcode));
+ // Reset locale cache.
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // Find the edit path.
+ $content = $this->drupalGetContent();
+ $this->assertTrue(preg_match('@(admin/config/regional/translate/edit/[0-9]+)@', $content, $matches), 'Found the edit path.');
+ $path = $matches[0];
+ foreach ($bad_translations as $key => $translation) {
+ $edit = array(
+ "translations[$langcode]" => $translation,
+ );
+ $this->drupalPost($path, $edit, t('Save translations'));
+ // Check for a form error on the textarea.
+ $form_class = $this->xpath('//form[@id="locale-translate-edit-form"]//textarea/@class');
+ $this->assertNotIdentical(FALSE, strpos($form_class[0], 'error'), 'The string was rejected as unsafe.');
+ $this->assertNoText(t('The string has been saved.'), 'The string was not saved.');
+ }
+ }
+
+ /**
+ * Tests translation search form.
+ */
+ function testStringSearch() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ // User to translate and delete string.
+ $translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
+
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language. This will be translated.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ // This is the language indicator on the translation search screen for
+ // untranslated strings. Copied straight from locale.inc.
+ $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
+ // This will be the translation of $name.
+ $translation = $this->randomName(16);
+
+ // Add custom language.
+ $this->drupalLogin($admin_user);
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Add string.
+ t($name, array(), array('langcode' => $langcode));
+ // Reset locale cache.
+ locale_reset();
+ $this->drupalLogout();
+
+ // Search for the name.
+ $this->drupalLogin($translate_user);
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // assertText() seems to remove the input field where $name always could be
+ // found, so this is not a false assert. See how assertNoText succeeds
+ // later.
+ $this->assertText($name, 'Search found the string.');
+
+ // Ensure untranslated string doesn't appear if searching on 'only
+ // translated strings'.
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'translated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), "Search didn't find the string.");
+
+ // Ensure untranslated string appears if searching on 'only untranslated
+ // strings' in "all" (hasn't been translated to any language).
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'untranslated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'Search found the string.');
+
+ // Ensure untranslated string appears if searching on 'only untranslated
+ // strings' in the custom language (hasn't been translated to that specific language).
+ $search = array(
+ 'string' => $name,
+ 'language' => $langcode,
+ 'translation' => 'untranslated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'Search found the string.');
+
+ // Add translation.
+ // Assume this is the only result, given the random name.
+ $this->clickLink(t('edit'));
+ // We save the lid from the path.
+ $matches = array();
+ preg_match('!admin/config/regional/translate/edit/(\d)+!', $this->getUrl(), $matches);
+ $lid = $matches[1];
+ $edit = array(
+ "translations[$langcode]" => $translation,
+ );
+ $this->drupalPost(NULL, $edit, t('Save translations'));
+
+ // Ensure translated string does appear if searching on 'only
+ // translated strings'.
+ $search = array(
+ 'string' => $translation,
+ 'language' => 'all',
+ 'translation' => 'translated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'Search found the translation.');
+
+ // Ensure translated source string doesn't appear if searching on 'only
+ // untranslated strings'.
+ $search = array(
+ 'string' => $name,
+ 'language' => 'all',
+ 'translation' => 'untranslated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), "Search didn't find the source string.");
+
+ // Ensure translated string doesn't appear if searching on 'only
+ // untranslated strings'.
+ $search = array(
+ 'string' => $translation,
+ 'language' => 'all',
+ 'translation' => 'untranslated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), "Search didn't find the translation.");
+
+ // Ensure translated string does appear if searching on the custom language.
+ $search = array(
+ 'string' => $translation,
+ 'language' => $langcode,
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'Search found the translation.');
+
+ // Ensure translated string doesn't appear if searching on English.
+ $search = array(
+ 'string' => $translation,
+ 'language' => 'en',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), "Search didn't find the translation.");
+
+ // Search for a string that isn't in the system.
+ $unavailable_string = $this->randomName(16);
+ $search = array(
+ 'string' => $unavailable_string,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), "Search didn't find the invalid string.");
+ }
+}
+
+/**
+ * Tests plural index computation functionality.
+ */
+class LocalePluralFormatTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Plural formula evaluation',
+ 'description' => 'Tests plural formula evaluation for various languages.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
+ $this->drupalLogin($admin_user);
+
+ // Import some .po files with formulas to set up the environment.
+ // These will also add the languages to the system and enable them.
+ $this->importPoFile($this->getPoFileWithSimplePlural(), array(
+ 'langcode' => 'fr',
+ ));
+ $this->importPoFile($this->getPoFileWithComplexPlural(), array(
+ 'langcode' => 'hr',
+ ));
+ }
+
+ /**
+ * Tests locale_get_plural() functionality.
+ */
+ function testGetPluralFormat() {
+ $this->drupalGet('locale_test_plural_format_page');
+ $tests = _locale_test_plural_format_tests();
+ $result = array();
+ foreach ($tests as $test) {
+ $this->assertPluralFormat($test['count'], $test['language'], $test['expected-result']);
+ }
+ }
+
+ /**
+ * Helper assert to test locale_get_plural page.
+ *
+ * @param $count
+ * Number for testing.
+ * @param $lang
+ * Language for testing
+ * @param $expected_result
+ * Expected result.
+ * @param $message
+ */
+ function assertPluralFormat($count, $lang, $expected_result) {
+ $message_param = array(
+ '@lang' => $lang,
+ '@count' => $count,
+ '@expected_result' => $expected_result,
+ );
+ $message = t("Computed plural index for '@lang' with count @count is @expected_result.", $message_param);
+
+ $message_param = array(
+ '@lang' => $lang,
+ '@expected_result' => $expected_result,
+ );
+ $this->assertText(format_string('Language: @lang, locale_get_plural: @expected_result.', $message_param, $message));
+ }
+
+ /**
+ * Imports a standalone .po file in a given language.
+ *
+ * @param $contents
+ * Contents of the .po file to import.
+ * @param $options
+ * Additional options to pass to the translation import form.
+ */
+ function importPoFile($contents, array $options = array()) {
+ $name = tempnam('temporary://', "po_") . '.po';
+ file_put_contents($name, $contents);
+ $options['files[file]'] = $name;
+ $this->drupalPost('admin/config/regional/translate/import', $options, t('Import'));
+ drupal_unlink($name);
+ }
+
+ /**
+ * Returns a .po file with a simple plural formula.
+ */
+ function getPoFileWithSimplePlural() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n!=1);\\n"
+
+msgid "One sheep"
+msgid_plural "@count sheep"
+msgstr[0] "un mouton"
+msgstr[1] "@count moutons"
+
+msgid "Monday"
+msgstr "lundi"
+EOF;
+ }
+
+ /**
+ * Returns a .po file with a complex plural formula.
+ */
+ function getPoFileWithComplexPlural() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
+
+msgid "1 hour"
+msgid_plural "@count hours"
+msgstr[0] "@count sat"
+msgstr[1] "@count sata"
+msgstr[2] "@count sati"
+
+msgid "Monday"
+msgstr "Ponedjeljak"
+EOF;
+ }
+}
+
+/**
+ * Functional tests for the import of translation files.
+ */
+class LocaleImportFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Translation import',
+ 'description' => 'Tests the import of locale files.',
+ 'group' => 'Locale',
+ );
+ }
+
+ /**
+ * A user able to create languages and import translations.
+ */
+ protected $admin_user = NULL;
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+
+ $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Test import of standalone .po files.
+ */
+ function testStandalonePoFile() {
+ // Try importing a .po file.
+ $this->importPoFile($this->getPoFile(), array(
+ 'langcode' => 'fr',
+ ));
+
+ // The import should automatically create the corresponding language.
+ $this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), 'The language has been automatically created.');
+
+ // The import should have created 7 strings.
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 9, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
+
+ // This import should have saved plural forms to have 2 variants.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, 'Plural number initialized.');
+
+ // Ensure we were redirected correctly.
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+
+
+ // Try importing a .po file with invalid tags in the default text group.
+ $this->importPoFile($this->getBadPoFile(), array(
+ 'langcode' => 'fr',
+ ));
+
+ // The import should have created 1 string and rejected 2.
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
+ $skip_message = format_plural(2, 'One translation string was skipped because it contains disallowed HTML.', '@count translation strings were skipped because they contain disallowed HTML.');
+ $this->assertRaw($skip_message, 'Unsafe strings were skipped.');
+
+
+ // Try importing a .po file with invalid tags in a non default text group.
+ $this->importPoFile($this->getBadPoFile(), array(
+ 'langcode' => 'fr',
+ 'group' => 'custom',
+ ));
+
+ // The import should have created 3 strings.
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 3, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
+
+
+ // Try importing a .po file which doesn't exist.
+ $name = $this->randomName(16);
+ $this->drupalPost('admin/config/regional/translate/import', array(
+ 'langcode' => 'fr',
+ 'files[file]' => $name,
+ 'group' => 'custom',
+ ), t('Import'));
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/import', array('absolute' => TRUE)), 'Correct page redirection.');
+ $this->assertText(t('File to import not found.'), 'File to import not found message.');
+
+
+ // Try importing a .po file with overriding strings, and ensure existing
+ // strings are kept.
+ $this->importPoFile($this->getOverwritePoFile(), array(
+ 'langcode' => 'fr',
+ 'mode' => 1, // Existing strings are kept, only new strings are added.
+ ));
+
+ // The import should have created 1 string.
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
+ // Ensure string wasn't overwritten.
+ $search = array(
+ 'string' => 'Montag',
+ 'language' => 'fr',
+ 'translation' => 'translated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertText(t('No strings available.'), 'String not overwritten by imported string.');
+
+ // This import should not have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, 'Plural numbers untouched.');
+
+ $this->importPoFile($this->getPoFileWithBrokenPlural(), array(
+ 'langcode' => 'fr',
+ 'mode' => 1, // Existing strings are kept, only new strings are added.
+ ));
+
+ // Attempt to import broken .po file as well to prove that this
+ // will not overwrite the proper plural formula imported above.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, 'Broken plurals: plural numbers untouched.');
+
+ $this->importPoFile($this->getPoFileWithMissingPlural(), array(
+ 'langcode' => 'fr',
+ 'mode' => 1, // Existing strings are kept, only new strings are added.
+ ));
+
+ // Attempt to import .po file which has no plurals and prove that this
+ // will not overwrite the proper plural formula imported above.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, 'No plurals: plural numbers untouched.');
+
+
+ // Try importing a .po file with overriding strings, and ensure existing
+ // strings are overwritten.
+ $this->importPoFile($this->getOverwritePoFile(), array(
+ 'langcode' => 'fr',
+ 'mode' => 0, // Strings in the uploaded file replace existing ones, new ones are added.
+ ));
+
+ // The import should have updated 2 strings.
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), 'The translation file was successfully imported.');
+ // Ensure string was overwritten.
+ $search = array(
+ 'string' => 'Montag',
+ 'language' => 'fr',
+ 'translation' => 'translated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'String overwritten by imported string.');
+ // This import should have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 3, 'Plural numbers changed.');
+ }
+
+ /**
+ * Test automatic import of a module's translation files when a language is
+ * enabled.
+ */
+ function testAutomaticModuleTranslationImportLanguageEnable() {
+ // Code for the language - manually set to match the test translation file.
+ $langcode = 'xx';
+ // The English name for the language.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+
+ // Create a custom language.
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+
+ // Ensure the translation file was automatically imported when language was
+ // added.
+ $this->assertText(t('One translation file imported for the enabled modules.'), 'Language file automatically imported.');
+
+ // Ensure strings were successfully imported.
+ $search = array(
+ 'string' => 'lundi',
+ 'language' => $langcode,
+ 'translation' => 'translated',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ $this->assertNoText(t('No strings available.'), 'String successfully imported.');
+ }
+
+ /**
+ * Test msgctxt context support.
+ */
+ function testLanguageContext() {
+ // Try importing a .po file.
+ $this->importPoFile($this->getPoFileWithContext(), array(
+ 'langcode' => 'hr',
+ ));
+
+ $this->assertIdentical(t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', 'Long month name context is working.');
+ $this->assertIdentical(t('May', array(), array('langcode' => 'hr')), 'Svi.', 'Default context is working.');
+ }
+
+ /**
+ * Test empty msgstr at end of .po file see #611786.
+ */
+ function testEmptyMsgstr() {
+ $langcode = 'hu';
+
+ // Try importing a .po file.
+ $this->importPoFile($this->getPoFileWithMsgstr(), array(
+ 'langcode' => $langcode,
+ ));
+
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
+ $this->assertIdentical(t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', 'String imported and translated.');
+
+ // Try importing a .po file.
+ $this->importPoFile($this->getPoFileWithEmptyMsgstr(), array(
+ 'langcode' => $langcode,
+ 'mode' => 0,
+ ));
+ $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 0, '%delete' => 1)), 'The translation file was successfully imported.');
+ // This is the language indicator on the translation search screen for
+ // untranslated strings. Copied straight from locale.inc.
+ $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
+ $str = "Operations";
+ $search = array(
+ 'string' => $str,
+ 'language' => 'all',
+ 'translation' => 'all',
+ 'group' => 'all',
+ );
+ $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
+ // assertText() seems to remove the input field where $str always could be
+ // found, so this is not a false assert.
+ $this->assertText($str, 'Search found the string.');
+ $this->assertRaw($language_indicator, 'String is untranslated again.');
+ }
+
+ /**
+ * Helper function: import a standalone .po file in a given language.
+ *
+ * @param $contents
+ * Contents of the .po file to import.
+ * @param $options
+ * Additional options to pass to the translation import form.
+ */
+ function importPoFile($contents, array $options = array()) {
+ $name = tempnam('temporary://', "po_") . '.po';
+ file_put_contents($name, $contents);
+ $options['files[file]'] = $name;
+ $this->drupalPost('admin/config/regional/translate/import', $options, t('Import'));
+ drupal_unlink($name);
+ }
+
+ /**
+ * Helper function that returns a proper .po file.
+ */
+ function getPoFile() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "One sheep"
+msgid_plural "@count sheep"
+msgstr[0] "un mouton"
+msgstr[1] "@count moutons"
+
+msgid "Monday"
+msgstr "lundi"
+
+msgid "Tuesday"
+msgstr "mardi"
+
+msgid "Wednesday"
+msgstr "mercredi"
+
+msgid "Thursday"
+msgstr "jeudi"
+
+msgid "Friday"
+msgstr "vendredi"
+
+msgid "Saturday"
+msgstr "samedi"
+
+msgid "Sunday"
+msgstr "dimanche"
+EOF;
+ }
+
+ /**
+ * Helper function that returns a bad .po file.
+ */
+ function getBadPoFile() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "Save configuration"
+msgstr "Enregistrer la configuration"
+
+msgid "edit"
+msgstr "modifier<img SRC="javascript:alert(\'xss\');">"
+
+msgid "delete"
+msgstr "supprimer<script>alert('xss');</script>"
+
+EOF;
+ }
+
+ /**
+ * Helper function that returns a proper .po file, for testing overwriting
+ * existing translations.
+ */
+ function getOverwritePoFile() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
+
+msgid "Monday"
+msgstr "Montag"
+
+msgid "Day"
+msgstr "Jour"
+EOF;
+ }
+
+ /**
+ * Helper function that returns a .po file with context.
+ */
+ function getPoFileWithContext() {
+ // Croatian (code hr) is one the the languages that have a different
+ // form for the full name and the abbreviated name for the month May.
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
+
+msgctxt "Long month name"
+msgid "May"
+msgstr "Svibanj"
+
+msgid "May"
+msgstr "Svi."
+EOF;
+ }
+
+ /**
+ * Helper function that returns a .po file with an empty last item.
+ */
+ function getPoFileWithEmptyMsgstr() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "Operations"
+msgstr ""
+
+EOF;
+ }
+ /**
+ * Helper function that returns a .po file with an empty last item.
+ */
+ function getPoFileWithMsgstr() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "Operations"
+msgstr "Műveletek"
+
+msgid "Will not appear in Drupal core, so we can ensure the test passes"
+msgstr ""
+
+EOF;
+ }
+
+
+ /**
+ * Returns a .po file with a missing plural formula.
+ */
+ function getPoFileWithMissingPlural() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+
+msgid "Monday"
+msgstr "Ponedjeljak"
+EOF;
+ }
+
+ /**
+ * Returns a .po file with a broken plural formula.
+ */
+ function getPoFileWithBrokenPlural() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: broken, will not parse\\n"
+
+msgid "Monday"
+msgstr "lundi"
+EOF;
+ }
+
+}
+
+/**
+ * Functional tests for the export of translation files.
+ */
+class LocaleExportFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Translation export',
+ 'description' => 'Tests the exportation of locale files.',
+ 'group' => 'Locale',
+ );
+ }
+
+ /**
+ * A user able to create languages and export translations.
+ */
+ protected $admin_user = NULL;
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+
+ $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Test exportation of translations.
+ */
+ function testExportTranslation() {
+ // First import some known translations.
+ // This will also automatically enable the 'fr' language.
+ $name = tempnam('temporary://', "po_") . '.po';
+ file_put_contents($name, $this->getPoFile());
+ $this->drupalPost('admin/config/regional/translate/import', array(
+ 'langcode' => 'fr',
+ 'files[file]' => $name,
+ ), t('Import'));
+ drupal_unlink($name);
+
+ // Get the French translations.
+ $this->drupalPost('admin/config/regional/translate/export', array(
+ 'langcode' => 'fr',
+ ), t('Export'));
+
+ // Ensure we have a translation file.
+ $this->assertRaw('# French translation of Drupal', 'Exported French translation file.');
+ // Ensure our imported translations exist in the file.
+ $this->assertRaw('msgstr "lundi"', 'French translations present in exported file.');
+ }
+
+ /**
+ * Test exportation of translation template file.
+ */
+ function testExportTranslationTemplateFile() {
+ // Get the translation template file.
+ // There are two 'Export' buttons on this page, but it somehow works. It'd
+ // be better if we could use the submit button id like documented but that
+ // doesn't work.
+ $this->drupalPost('admin/config/regional/translate/export', array(), t('Export'));
+ // Ensure we have a translation file.
+ $this->assertRaw('# LANGUAGE translation of PROJECT', 'Exported translation template file.');
+ }
+
+ /**
+ * Helper function that returns a proper .po file.
+ */
+ function getPoFile() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 6\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "Monday"
+msgstr "lundi"
+EOF;
+ }
+
+}
+
+/**
+ * Tests for the st() function.
+ */
+class LocaleInstallTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'String translation using st()',
+ 'description' => 'Tests that st() works like t().',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+
+ // st() lives in install.inc, so ensure that it is loaded for all tests.
+ require_once DRUPAL_ROOT . '/includes/install.inc';
+ }
+
+ /**
+ * Verify that function signatures of t() and st() are equal.
+ */
+ function testFunctionSignatures() {
+ $reflector_t = new ReflectionFunction('t');
+ $reflector_st = new ReflectionFunction('st');
+ $this->assertEqual($reflector_t->getParameters(), $reflector_st->getParameters(), 'Function signatures of t() and st() are equal.');
+ }
+}
+
+/**
+ * Locale uninstall with English UI functional test.
+ */
+class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Locale uninstall (EN)',
+ 'description' => 'Tests the uninstall process using the built-in UI language.',
+ 'group' => 'Locale',
+ );
+ }
+
+ /**
+ * The default language set for the UI before uninstall.
+ */
+ protected $language;
+
+ function setUp() {
+ parent::setUp('locale');
+ $this->language = 'en';
+ }
+
+ /**
+ * Check if the values of the Locale variables are correct after uninstall.
+ */
+ function testUninstallProcess() {
+ $locale_module = array('locale');
+
+ // Add a new language and optionally set it as default.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ locale_add_language('fr', 'French', 'Français', LANGUAGE_LTR, '', '', TRUE, $this->language == 'fr');
+
+ // Check the UI language.
+ drupal_language_initialize();
+ global $language;
+ $this->assertEqual($language->language, $this->language, format_string('Current language: %lang', array('%lang' => $language->language)));
+
+ // Enable multilingual workflow option for articles.
+ variable_set('language_content_type_article', 1);
+
+ // Change JavaScript translations directory.
+ variable_set('locale_js_directory', 'js_translations');
+
+ // Build the JavaScript translation file for French.
+ $user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
+ $this->drupalLogin($user);
+ $this->drupalGet('admin/config/regional/translate/translate');
+ $string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array(
+ ':location' => '%.js%',
+ ':textgroup' => 'default',
+ ))->fetchObject();
+ $edit = array('translations[fr]' => 'french translation');
+ $this->drupalPost('admin/config/regional/translate/edit/' . $string->lid, $edit, t('Save translations'));
+ _locale_rebuild_js('fr');
+ $file = db_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject();
+ $js_file = 'public://' . variable_get('locale_js_directory', 'languages') . '/fr_' . $file->javascript . '.js';
+ $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file created: %file', array('%file' => $result ? $js_file : 'none')));
+
+ // Disable string caching.
+ variable_set('locale_cache_strings', 0);
+
+ // Change language negotiation options.
+ drupal_load('module', 'locale');
+ variable_set('language_types', drupal_language_types() + array('language_custom' => TRUE));
+ variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, locale_language_negotiation_info());
+ variable_set('language_negotiation_' . LANGUAGE_TYPE_CONTENT, locale_language_negotiation_info());
+ variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, locale_language_negotiation_info());
+
+ // Change language providers settings.
+ variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
+ variable_set('locale_language_negotiation_session_param', TRUE);
+
+ // Uninstall Locale.
+ module_disable($locale_module);
+ drupal_uninstall_modules($locale_module);
+
+ // Visit the front page.
+ $this->drupalGet('');
+
+ // Check the init language logic.
+ drupal_language_initialize();
+ $this->assertEqual($language->language, 'en', format_string('Language after uninstall: %lang', array('%lang' => $language->language)));
+
+ // Check JavaScript files deletion.
+ $this->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
+
+ // Check language count.
+ $language_count = variable_get('language_count', 1);
+ $this->assertEqual($language_count, 1, format_string('Language count: %count', array('%count' => $language_count)));
+
+ // Check language negotiation.
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ $this->assertTrue(count(language_types()) == count(drupal_language_types()), 'Language types reset');
+ $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $this->assertTrue($language_negotiation, format_string('Interface language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
+ $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $this->assertTrue($language_negotiation, format_string('Content language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
+ $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $this->assertTrue($language_negotiation, format_string('URL language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
+
+ // Check language providers settings.
+ $this->assertFalse(variable_get('locale_language_negotiation_url_part', FALSE), 'URL language provider indicator settings cleared.');
+ $this->assertFalse(variable_get('locale_language_negotiation_session_param', FALSE), 'Visit language provider settings cleared.');
+
+ // Check JavaScript parsed.
+ $javascript_parsed_count = count(variable_get('javascript_parsed', array()));
+ $this->assertEqual($javascript_parsed_count, 0, format_string('JavaScript parsed count: %count', array('%count' => $javascript_parsed_count)));
+
+ // Check multilingual workflow option for articles.
+ $multilingual = variable_get('language_content_type_article', 0);
+ $this->assertEqual($multilingual, 0, format_string('Multilingual workflow option: %status', array('%status' => $multilingual ? 'enabled': 'disabled')));
+
+ // Check JavaScript translations directory.
+ $locale_js_directory = variable_get('locale_js_directory', 'languages');
+ $this->assertEqual($locale_js_directory, 'languages', format_string('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
+
+ // Check string caching.
+ $locale_cache_strings = variable_get('locale_cache_strings', 1);
+ $this->assertEqual($locale_cache_strings, 1, format_string('String caching: %status', array('%status' => $locale_cache_strings ? 'enabled': 'disabled')));
+ }
+}
+
+/**
+ * Locale uninstall with French UI functional test.
+ *
+ * Because this class extends LocaleUninstallFunctionalTest, it doesn't require a new
+ * test of its own. Rather, it switches the default UI language in setUp and then
+ * runs the testUninstallProcess (which it inherits from LocaleUninstallFunctionalTest)
+ * to test with this new language.
+ */
+class LocaleUninstallFrenchFunctionalTest extends LocaleUninstallFunctionalTest {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Locale uninstall (FR)',
+ 'description' => 'Tests the uninstall process using French as interface language.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ $this->language = 'fr';
+ }
+}
+
+/**
+ * Functional tests for the language switching feature.
+ */
+class LocaleLanguageSwitchingFunctionalTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Language switching',
+ 'description' => 'Tests for the language switching feature.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+
+ // Create and login user.
+ $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer languages', 'translate interface', 'access administration pages'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Functional tests for the language switcher block.
+ */
+ function testLanguageBlock() {
+ // Enable the language switching block.
+ $language_type = LANGUAGE_TYPE_INTERFACE;
+ $edit = array(
+ "blocks[locale_{$language_type}][region]" => 'sidebar_first',
+ );
+ $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
+
+ // Add language.
+ $edit = array(
+ 'langcode' => 'fr',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ // Enable URL language detection and selection.
+ $edit = array('language[enabled][locale-url]' => '1');
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Assert that the language switching block is displayed on the frontpage.
+ $this->drupalGet('');
+ $this->assertText(t('Languages'), 'Language switcher block found.');
+
+ // Assert that only the current language is marked as active.
+ list($language_switcher) = $this->xpath('//div[@id=:id]/div[@class="content"]', array(':id' => 'block-locale-' . $language_type));
+ $links = array(
+ 'active' => array(),
+ 'inactive' => array(),
+ );
+ $anchors = array(
+ 'active' => array(),
+ 'inactive' => array(),
+ );
+ foreach ($language_switcher->ul->li as $link) {
+ $classes = explode(" ", (string) $link['class']);
+ list($language) = array_intersect($classes, array('en', 'fr'));
+ if (in_array('active', $classes)) {
+ $links['active'][] = $language;
+ }
+ else {
+ $links['inactive'][] = $language;
+ }
+ $anchor_classes = explode(" ", (string) $link->a['class']);
+ if (in_array('active', $anchor_classes)) {
+ $anchors['active'][] = $language;
+ }
+ else {
+ $anchors['inactive'][] = $language;
+ }
+ }
+ $this->assertIdentical($links, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language list item is marked as active on the language switcher block.');
+ $this->assertIdentical($anchors, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language anchor is marked as active on the language switcher block.');
+ }
+}
+
+/**
+ * Test browser language detection.
+ */
+class LocaleBrowserDetectionTest extends DrupalUnitTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Browser language detection',
+ 'description' => 'Tests for the browser language detection.',
+ 'group' => 'Locale',
+ );
+ }
+
+ /**
+ * Unit tests for the locale_language_from_browser() function.
+ */
+ function testLanguageFromBrowser() {
+ // Load the required functions.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+
+ $languages = array(
+ // In our test case, 'en' has priority over 'en-US'.
+ 'en' => (object) array(
+ 'language' => 'en',
+ ),
+ 'en-US' => (object) array(
+ 'language' => 'en-US',
+ ),
+ // But 'fr-CA' has priority over 'fr'.
+ 'fr-CA' => (object) array(
+ 'language' => 'fr-CA',
+ ),
+ 'fr' => (object) array(
+ 'language' => 'fr',
+ ),
+ // 'es-MX' is alone.
+ 'es-MX' => (object) array(
+ 'language' => 'es-MX',
+ ),
+ // 'pt' is alone.
+ 'pt' => (object) array(
+ 'language' => 'pt',
+ ),
+ // Language codes with more then one dash are actually valid.
+ // eh-oh-laa-laa is the official language code of the Teletubbies.
+ 'eh-oh-laa-laa' => (object) array(
+ 'language' => 'eh-oh-laa-laa',
+ ),
+ );
+
+ $test_cases = array(
+ // Equal qvalue for each language, choose the site preferred one.
+ 'en,en-US,fr-CA,fr,es-MX' => 'en',
+ 'en-US,en,fr-CA,fr,es-MX' => 'en',
+ 'fr,en' => 'en',
+ 'en,fr' => 'en',
+ 'en-US,fr' => 'en',
+ 'fr,en-US' => 'en',
+ 'fr,fr-CA' => 'fr-CA',
+ 'fr-CA,fr' => 'fr-CA',
+ 'fr' => 'fr-CA',
+ 'fr;q=1' => 'fr-CA',
+ 'fr,es-MX' => 'fr-CA',
+ 'fr,es' => 'fr-CA',
+ 'es,fr' => 'fr-CA',
+ 'es-MX,de' => 'es-MX',
+ 'de,es-MX' => 'es-MX',
+
+ // Different cases and whitespace.
+ 'en' => 'en',
+ 'En' => 'en',
+ 'EN' => 'en',
+ ' en' => 'en',
+ 'en ' => 'en',
+ 'en, fr' => 'en',
+
+ // A less specific language from the browser matches a more specific one
+ // from the website, and the other way around for compatibility with
+ // some versions of Internet Explorer.
+ 'es' => 'es-MX',
+ 'es-MX' => 'es-MX',
+ 'pt' => 'pt',
+ 'pt-PT' => 'pt',
+ 'pt-PT;q=0.5,pt-BR;q=1,en;q=0.7' => 'en',
+ 'pt-PT;q=1,pt-BR;q=0.5,en;q=0.7' => 'en',
+ 'pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7' => 'en',
+ 'pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7' => 'en',
+
+ // Language code with several dashes are valid. The less specific language
+ // from the browser matches the more specific one from the website.
+ 'eh-oh-laa-laa' => 'eh-oh-laa-laa',
+ 'eh-oh-laa' => 'eh-oh-laa-laa',
+ 'eh-oh' => 'eh-oh-laa-laa',
+ 'eh' => 'eh-oh-laa-laa',
+
+ // Different qvalues.
+ 'fr,en;q=0.5' => 'fr-CA',
+ 'fr,en;q=0.5,fr-CA;q=0.25' => 'fr',
+
+ // Silly wildcards are also valid.
+ '*,fr-CA;q=0.5' => 'en',
+ '*,en;q=0.25' => 'fr-CA',
+ 'en,en-US;q=0.5,fr;q=0.25' => 'en',
+ 'en-US,en;q=0.5,fr;q=0.25' => 'en-US',
+
+ // Unresolvable cases.
+ '' => FALSE,
+ 'de,pl' => FALSE,
+ 'iecRswK4eh' => FALSE,
+ $this->randomName(10) => FALSE,
+ );
+
+ foreach ($test_cases as $accept_language => $expected_result) {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language;
+ $result = locale_language_from_browser($languages);
+ $this->assertIdentical($result, $expected_result, format_string("Language selection '@accept-language' selects '@result', result = '@actual'", array('@accept-language' => $accept_language, '@result' => $expected_result, '@actual' => isset($result) ? $result : 'none')));
+ }
+ }
+}
+
+/**
+ * Functional tests for a user's ability to change their default language.
+ */
+class LocaleUserLanguageFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'User language settings',
+ 'description' => "Tests user's ability to change their default language.",
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ /**
+ * Test if user can change their default language.
+ */
+ function testUserLanguageConfiguration() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ // User to change their default language.
+ $web_user = $this->drupalCreateUser();
+
+ // Add custom language.
+ $this->drupalLogin($admin_user);
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = 'xx';
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+
+ // Add custom language and disable it.
+ // Code for the language.
+ $langcode_disabled = 'xx-yy';
+ // The English name for the language. This will be translated.
+ $name_disabled = $this->randomName(16);
+ // The native name for the language.
+ $native_disabled = $this->randomName(16);
+ // The domain prefix.
+ $prefix_disabled = $langcode_disabled;
+ $edit = array(
+ 'langcode' => $langcode_disabled,
+ 'name' => $name_disabled,
+ 'native' => $native_disabled,
+ 'prefix' => $prefix_disabled,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Disable the language.
+ $edit = array(
+ 'enabled[' . $langcode_disabled . ']' => FALSE,
+ );
+ $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
+ $this->drupalLogout();
+
+ // Login as normal user and edit account settings.
+ $this->drupalLogin($web_user);
+ $path = 'user/' . $web_user->uid . '/edit';
+ $this->drupalGet($path);
+ // Ensure language settings fieldset is available.
+ $this->assertText(t('Language settings'), 'Language settings available.');
+ // Ensure custom language is present.
+ $this->assertText($name, 'Language present on form.');
+ // Ensure disabled language isn't present.
+ $this->assertNoText($name_disabled, 'Disabled language not present on form.');
+ // Switch to our custom language.
+ $edit = array(
+ 'language' => $langcode,
+ );
+ $this->drupalPost($path, $edit, t('Save'));
+ // Ensure form was submitted successfully.
+ $this->assertText(t('The changes have been saved.'), 'Changes were saved.');
+ // Check if language was changed.
+ $elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-language-' . $langcode));
+ $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), 'Default language successfully updated.');
+
+ $this->drupalLogout();
+ }
+}
+
+/**
+ * Functional test for language handling during user creation.
+ */
+class LocaleUserCreationTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'User creation',
+ 'description' => 'Tests whether proper language is stored for new users and access to language selector.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ variable_set('user_register', USER_REGISTER_VISITORS);
+ }
+
+ /**
+ * Functional test for language handling during user creation.
+ */
+ function testLocalUserCreation() {
+ // User to add and remove language and create new users.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users'));
+ $this->drupalLogin($admin_user);
+
+ // Add predefined language.
+ $langcode = 'fr';
+ $edit = array(
+ 'langcode' => 'fr',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+ $this->assertText($langcode, 'Language added successfully.');
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+
+ // Set language negotiation.
+ $edit = array(
+ 'language[enabled][locale-url]' => TRUE,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+ $this->assertText(t('Language negotiation configuration saved.'), 'Set language negotiation.');
+
+ // Check if the language selector is available on admin/people/create and
+ // set to the currently active language.
+ $this->drupalGet($langcode . '/admin/people/create');
+ $this->assertFieldChecked("edit-language-$langcode", 'Global language set in the language selector.');
+
+ // Create a user with the admin/people/create form and check if the correct
+ // language is set.
+ $username = $this->randomName(10);
+ $edit = array(
+ 'name' => $username,
+ 'mail' => $this->randomName(4) . '@example.com',
+ 'pass[pass1]' => $username,
+ 'pass[pass2]' => $username,
+ );
+
+ $this->drupalPost($langcode . '/admin/people/create', $edit, t('Create new account'));
+
+ $user = user_load_by_name($username);
+ $this->assertEqual($user->language, $langcode, 'New user has correct language set.');
+
+ // Register a new user and check if the language selector is hidden.
+ $this->drupalLogout();
+
+ $this->drupalGet($langcode . '/user/register');
+ $this->assertNoFieldByName('language[fr]', 'Language selector is not accessible.');
+
+ $username = $this->randomName(10);
+ $edit = array(
+ 'name' => $username,
+ 'mail' => $this->randomName(4) . '@example.com',
+ );
+
+ $this->drupalPost($langcode . '/user/register', $edit, t('Create new account'));
+
+ $user = user_load_by_name($username);
+ $this->assertEqual($user->language, $langcode, 'New user has correct language set.');
+
+ // Test if the admin can use the language selector and if the
+ // correct language is was saved.
+ $user_edit = $langcode . '/user/' . $user->uid . '/edit';
+
+ $this->drupalLogin($admin_user);
+ $this->drupalGet($user_edit);
+ $this->assertFieldChecked("edit-language-$langcode", 'Language selector is accessible and correct language is selected.');
+
+ // Set pass_raw so we can login the new user.
+ $user->pass_raw = $this->randomName(10);
+ $edit = array(
+ 'pass[pass1]' => $user->pass_raw,
+ 'pass[pass2]' => $user->pass_raw,
+ );
+
+ $this->drupalPost($user_edit, $edit, t('Save'));
+
+ $this->drupalLogin($user);
+ $this->drupalGet($user_edit);
+ $this->assertFieldChecked("edit-language-$langcode", 'Language selector is accessible and correct language is selected.');
+ }
+}
+
+/**
+ * Functional tests for configuring a different path alias per language.
+ */
+class LocalePathFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Path language settings',
+ 'description' => 'Checks you can configure a language for individual URL aliases.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'path');
+ }
+
+ /**
+ * Test if a language can be associated with a path alias.
+ */
+ function testPathLanguageConfiguration() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages'));
+
+ // Add custom language.
+ $this->drupalLogin($admin_user);
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+
+ // Check that the "xx" front page is not available when path prefixes are
+ // not enabled yet.
+ $this->drupalPost('admin/config/regional/language/configure', array(), t('Save settings'));
+ $this->drupalGet($prefix);
+ $this->assertResponse(404, 'The "xx" front page is not available yet.');
+
+ // Enable URL language detection and selection.
+ $edit = array('language[enabled][locale-url]' => 1);
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Create a node.
+ $node = $this->drupalCreateNode(array('type' => 'page'));
+
+ // Create a path alias in default language (English).
+ $path = 'admin/config/search/path/add';
+ $english_path = $this->randomName(8);
+ $edit = array(
+ 'source' => 'node/' . $node->nid,
+ 'alias' => $english_path,
+ 'language' => 'en',
+ );
+ $this->drupalPost($path, $edit, t('Save'));
+
+ // Create a path alias in new custom language.
+ $custom_language_path = $this->randomName(8);
+ $edit = array(
+ 'source' => 'node/' . $node->nid,
+ 'alias' => $custom_language_path,
+ 'language' => $langcode,
+ );
+ $this->drupalPost($path, $edit, t('Save'));
+
+ // Confirm English language path alias works.
+ $this->drupalGet($english_path);
+ $this->assertText($node->title, 'English alias works.');
+
+ // Confirm custom language path alias works.
+ $this->drupalGet($prefix . '/' . $custom_language_path);
+ $this->assertText($node->title, 'Custom language alias works.');
+
+ // Create a custom path.
+ $custom_path = $this->randomName(8);
+
+ // Check priority of language for alias by source path.
+ $edit = array(
+ 'source' => 'node/' . $node->nid,
+ 'alias' => $custom_path,
+ 'language' => LANGUAGE_NONE,
+ );
+ path_save($edit);
+ $lookup_path = drupal_lookup_path('alias', 'node/' . $node->nid, 'en');
+ $this->assertEqual($english_path, $lookup_path, 'English language alias has priority.');
+ // Same check for language 'xx'.
+ $lookup_path = drupal_lookup_path('alias', 'node/' . $node->nid, $prefix);
+ $this->assertEqual($custom_language_path, $lookup_path, 'Custom language alias has priority.');
+ path_delete($edit);
+
+ // Create language nodes to check priority of aliases.
+ $first_node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $second_node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+
+ // Assign a custom path alias to the first node with the English language.
+ $edit = array(
+ 'source' => 'node/' . $first_node->nid,
+ 'alias' => $custom_path,
+ 'language' => 'en',
+ );
+ path_save($edit);
+
+ // Assign a custom path alias to second node with LANGUAGE_NONE.
+ $edit = array(
+ 'source' => 'node/' . $second_node->nid,
+ 'alias' => $custom_path,
+ 'language' => LANGUAGE_NONE,
+ );
+ path_save($edit);
+
+ // Test that both node titles link to our path alias.
+ $this->drupalGet('<front>');
+ $custom_path_url = base_path() . (variable_get('clean_url', 0) ? $custom_path : '?q=' . $custom_path);
+ $elements = $this->xpath('//a[@href=:href and .=:title]', array(':href' => $custom_path_url, ':title' => $first_node->title));
+ $this->assertTrue(!empty($elements), 'First node links to the path alias.');
+ $elements = $this->xpath('//a[@href=:href and .=:title]', array(':href' => $custom_path_url, ':title' => $second_node->title));
+ $this->assertTrue(!empty($elements), 'Second node links to the path alias.');
+
+ // Confirm that the custom path leads to the first node.
+ $this->drupalGet($custom_path);
+ $this->assertText($first_node->title, 'Custom alias returns first node.');
+
+ // Confirm that the custom path with prefix leads to the second node.
+ $this->drupalGet($prefix . '/' . $custom_path);
+ $this->assertText($second_node->title, 'Custom alias with prefix returns second node.');
+ }
+}
+
+/**
+ * Functional tests for multilingual support on nodes.
+ */
+class LocaleContentFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Content language settings',
+ 'description' => 'Checks you can enable multilingual support on content types and configure a language for a node.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ /**
+ * Verifies that machine name fields are always LTR.
+ */
+ function testMachineNameLTR() {
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
+
+ // Log in as admin.
+ $this->drupalLogin($admin_user);
+
+ // Verify that the machine name field is LTR for a new content type.
+ $this->drupalGet('admin/structure/types/add');
+ $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
+
+ // Install the Arabic language (which is RTL) and configure as the default.
+ $edit = array();
+ $edit['langcode'] = 'ar';
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ $edit = array();
+ $edit['site_default'] = 'ar';
+ $this->drupalPost(NULL, $edit, t('Save configuration'));
+
+ // Verify that the machine name field is still LTR for a new content type.
+ $this->drupalGet('admin/structure/types/add');
+ $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.');
+ }
+
+ /**
+ * Test if a content type can be set to multilingual and language setting is
+ * present on node add and edit forms.
+ */
+ function testContentTypeLanguageConfiguration() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
+ // User to create a node.
+ $web_user = $this->drupalCreateUser(array('create article content', 'create page content', 'edit any page content'));
+
+ // Add custom language.
+ $this->drupalLogin($admin_user);
+ // Code for the language.
+ $langcode = 'xx';
+ // The English name for the language.
+ $name = $this->randomName(16);
+ // The native name for the language.
+ $native = $this->randomName(16);
+ // The domain prefix.
+ $prefix = $langcode;
+ $edit = array(
+ 'langcode' => $langcode,
+ 'name' => $name,
+ 'native' => $native,
+ 'prefix' => $prefix,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+
+ // Add disabled custom language.
+ // Code for the language.
+ $langcode_disabled = 'xx-yy';
+ // The English name for the language.
+ $name_disabled = $this->randomName(16);
+ // The native name for the language.
+ $native_disabled = $this->randomName(16);
+ // The domain prefix.
+ $prefix_disabled = $langcode_disabled;
+ $edit = array(
+ 'langcode' => $langcode_disabled,
+ 'name' => $name_disabled,
+ 'native' => $native_disabled,
+ 'prefix' => $prefix_disabled,
+ 'direction' => '0',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Disable second custom language.
+ $path = 'admin/config/regional/language';
+ $edit = array(
+ 'enabled[' . $langcode_disabled . ']' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Save configuration'));
+
+ // Set "Basic page" content type to use multilingual support.
+ $this->drupalGet('admin/structure/types/manage/page');
+ $this->assertText(t('Multilingual support'), 'Multilingual support fieldset present on content type configuration form.');
+ $edit = array(
+ 'language_content_type' => 1,
+ );
+ $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
+ $this->drupalLogout();
+
+ // Verify language selection is not present on add article form.
+ $this->drupalLogin($web_user);
+ $this->drupalGet('node/add/article');
+ // Verify language select list is not present.
+ $this->assertNoFieldByName('language', NULL, 'Language select not present on add article form.');
+
+ // Verify language selection appears on add "Basic page" form.
+ $this->drupalGet('node/add/page');
+ // Verify language select list is present.
+ $this->assertFieldByName('language', NULL, 'Language select present on add Basic page form.');
+ // Ensure enabled language appears.
+ $this->assertText($name, 'Enabled language present.');
+ // Ensure disabled language doesn't appear.
+ $this->assertNoText($name_disabled, 'Disabled language not present.');
+
+ // Create "Basic page" content.
+ $node_title = $this->randomName();
+ $node_body = $this->randomName();
+ $edit = array(
+ 'type' => 'page',
+ 'title' => $node_title,
+ 'body' => array($langcode => array(array('value' => $node_body))),
+ 'language' => $langcode,
+ );
+ $node = $this->drupalCreateNode($edit);
+ // Edit the content and ensure correct language is selected.
+ $path = 'node/' . $node->nid . '/edit';
+ $this->drupalGet($path);
+ $this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', 'Correct language selected.');
+ // Ensure we can change the node language.
+ $edit = array(
+ 'language' => 'en',
+ );
+ $this->drupalPost($path, $edit, t('Save'));
+ $this->assertRaw(t('%title has been updated.', array('%title' => $node_title)), 'Basic page content updated.');
+
+ $this->drupalLogout();
+ }
+}
+
+/**
+ * Test UI language negotiation
+ * 1. URL (PATH) > DEFAULT
+ * UI Language base on URL prefix, browser language preference has no
+ * influence:
+ * admin/config
+ * UI in site default language
+ * zh-hans/admin/config
+ * UI in Chinese
+ * blah-blah/admin/config
+ * 404
+ * 2. URL (PATH) > BROWSER > DEFAULT
+ * admin/config
+ * UI in user's browser language preference if the site has that
+ * language enabled, if not, the default language
+ * zh-hans/admin/config
+ * UI in Chinese
+ * blah-blah/admin/config
+ * 404
+ * 3. URL (DOMAIN) > DEFAULT
+ * http://example.com/admin/config
+ * UI language in site default
+ * http://example.cn/admin/config
+ * UI language in Chinese
+ */
+class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'UI language negotiation',
+ 'description' => 'Test UI language switching by URL path prefix and domain.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ drupal_load('module', 'locale');
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Tests for language switching by URL path.
+ */
+ function testUILanguageNegotiation() {
+ // A few languages to switch to.
+ // This one is unknown, should get the default lang version.
+ $language_unknown = 'blah-blah';
+ // For testing browser lang preference.
+ $language_browser_fallback = 'vi';
+ // For testing path prefix.
+ $language = 'zh-hans';
+ // For setting browser language preference to 'vi'.
+ $http_header_browser_fallback = array("Accept-Language: $language_browser_fallback;q=1");
+ // For setting browser language preference to some unknown.
+ $http_header_blah = array("Accept-Language: blah;q=1");
+
+ // This domain should switch the UI to Chinese.
+ $language_domain = 'example.cn';
+
+ // Setup the site languages by installing two languages.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ locale_add_language($language_browser_fallback);
+ locale_add_language($language);
+
+ // We will look for this string in the admin/config screen to see if the
+ // corresponding translated string is shown.
+ $default_string = 'Configure languages for content and the user interface';
+
+ // Set the default language in order for the translated string to be registered
+ // into database when seen by t(). Without doing this, our target string
+ // is for some reason not found when doing translate search. This might
+ // be some bug.
+ drupal_static_reset('language_list');
+ $languages = language_list('enabled');
+ variable_set('language_default', $languages[1]['vi']);
+ // First visit this page to make sure our target string is searchable.
+ $this->drupalGet('admin/config');
+ // Now the t()'ed string is in db so switch the language back to default.
+ variable_del('language_default');
+
+ // Translate the string.
+ $language_browser_fallback_string = "In $language_browser_fallback In $language_browser_fallback In $language_browser_fallback";
+ $language_string = "In $language In $language In $language";
+ // Do a translate search of our target string.
+ $edit = array( 'string' => $default_string);
+ $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Filter'));
+ // Should find the string and now click edit to post translated string.
+ $this->clickLink('edit');
+ $edit = array(
+ "translations[$language_browser_fallback]" => $language_browser_fallback_string,
+ "translations[$language]" => $language_string,
+ );
+ $this->drupalPost(NULL, $edit, t('Save translations'));
+
+ // Configure URL language rewrite.
+ variable_set('locale_language_negotiation_url_type', LANGUAGE_TYPE_INTERFACE);
+
+ $tests = array(
+ // Default, browser preference should have no influence.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
+ 'path' => 'admin/config',
+ 'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
+ ),
+ // Language prefix.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
+ 'path' => "$language/admin/config",
+ 'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
+ ),
+ // Default, go by browser preference.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER),
+ 'path' => 'admin/config',
+ 'expect' => $language_browser_fallback_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_BROWSER,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
+ ),
+ // Prefix, switch to the language.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER),
+ 'path' => "$language/admin/config",
+ 'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (PATH) > BROWSER: with langage prefix, UI language is based on path prefix',
+ ),
+ // Default, browser language preference is not one of site's lang.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER, LANGUAGE_NEGOTIATION_DEFAULT),
+ 'path' => 'admin/config',
+ 'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'http_header' => $http_header_blah,
+ 'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
+ ),
+ );
+
+ foreach ($tests as $test) {
+ $this->runTest($test);
+ }
+
+ // Unknown language prefix should return 404.
+ variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, locale_language_negotiation_info());
+ $this->drupalGet("$language_unknown/admin/config", array(), $http_header_browser_fallback);
+ $this->assertResponse(404, "Unknown language path prefix should return 404");
+
+ // Setup for domain negotiation, first configure the language to have domain
+ // URL. We use HTTPS and a port to make sure that only the domain name is used.
+ $edit = array('prefix' => '', 'domain' => "https://$language_domain:99");
+ $this->drupalPost("admin/config/regional/language/edit/$language", $edit, t('Save language'));
+ // Set the site to use domain language negotiation.
+
+ $tests = array(
+ // Default domain, browser preference should have no influence.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
+ 'locale_language_negotiation_url_part' => LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN,
+ 'path' => 'admin/config',
+ 'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (DOMAIN) > DEFAULT: default domain should get default language',
+ ),
+ // Language domain specific URL, we set the $_SERVER['HTTP_HOST'] in
+ // locale_test.module hook_boot() to simulate this.
+ array(
+ 'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
+ 'locale_language_negotiation_url_part' => LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN,
+ 'locale_test_domain' => $language_domain . ':88',
+ 'path' => 'admin/config',
+ 'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
+ 'http_header' => $http_header_browser_fallback,
+ 'message' => 'URL (DOMAIN) > DEFAULT: domain example.cn should switch to Chinese',
+ ),
+ );
+
+ foreach ($tests as $test) {
+ $this->runTest($test);
+ }
+ }
+
+ private function runTest($test) {
+ if (!empty($test['language_negotiation'])) {
+ $negotiation = array_flip($test['language_negotiation']);
+ language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotiation);
+ }
+ if (!empty($test['locale_language_negotiation_url_part'])) {
+ variable_set('locale_language_negotiation_url_part', $test['locale_language_negotiation_url_part']);
+ }
+ if (!empty($test['locale_test_domain'])) {
+ variable_set('locale_test_domain', $test['locale_test_domain']);
+ }
+ $this->drupalGet($test['path'], array(), $test['http_header']);
+ $this->assertText($test['expect'], $test['message']);
+ $this->assertText(t('Language negotiation provider: @name', array('@name' => $test['expected_provider'])));
+ }
+
+ /**
+ * Test URL language detection when the requested URL has no language.
+ */
+ function testUrlLanguageFallback() {
+ // Add the Italian language.
+ $language_browser_fallback = 'it';
+ locale_add_language($language_browser_fallback);
+ $languages = language_list();
+
+ // Enable the path prefix for the default language: this way any unprefixed
+ // URL must have a valid fallback value.
+ $edit = array('prefix' => 'en');
+ $this->drupalPost('admin/config/regional/language/edit/en', $edit, t('Save language'));
+
+ // Enable browser and URL language detection.
+ $edit = array(
+ 'language[enabled][locale-browser]' => TRUE,
+ 'language[enabled][locale-url]' => TRUE,
+ 'language[weight][locale-browser]' => -8,
+ 'language[weight][locale-url]' => -10,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+ $this->drupalGet('admin/config/regional/language/configure');
+
+ // Enable the language switcher block.
+ $edit = array('blocks[locale_language][region]' => 'sidebar_first');
+ $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
+
+ // Access the front page without specifying any valid URL language prefix
+ // and having as browser language preference a non-default language.
+ $http_header = array("Accept-Language: $language_browser_fallback;q=1");
+ $this->drupalGet('', array(), $http_header);
+
+ // Check that the language switcher active link matches the given browser
+ // language.
+ $args = array(':url' => base_path() . (!empty($GLOBALS['conf']['clean_url']) ? $language_browser_fallback : "?q=$language_browser_fallback"));
+ $fields = $this->xpath('//div[@id="block-locale-language"]//a[@class="language-link active" and @href=:url]', $args);
+ $this->assertTrue($fields[0] == $languages[$language_browser_fallback]->native, 'The browser language is the URL active language');
+
+ // Check that URLs are rewritten using the given browser language.
+ $fields = $this->xpath('//div[@id="site-name"]//a[@rel="home" and @href=:url]//span', $args);
+ $this->assertTrue($fields[0] == 'Drupal', 'URLs are rewritten using the browser language.');
+ }
+
+ /**
+ * Tests url() when separate domains are used for multiple languages.
+ */
+ function testLanguageDomain() {
+ // Add the Italian language, without protocol.
+ $langcode = 'it';
+ locale_add_language($langcode, 'Italian', 'Italian', LANGUAGE_LTR, 'it.example.com', '', TRUE, FALSE);
+
+ // Add the French language, with protocol.
+ $langcode = 'fr';
+ locale_add_language($langcode, 'French', 'French', LANGUAGE_LTR, 'http://fr.example.com', '', TRUE, FALSE);
+
+ // Enable language URL detection.
+ $negotiation = array_flip(array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT));
+ language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotiation);
+
+ variable_set('locale_language_negotiation_url_part', 1);
+
+ global $is_https;
+ $languages = language_list();
+
+ foreach (array('it', 'fr') as $langcode) {
+ // Build the link we're going to test based on the clean URL setting.
+ $link = (!empty($GLOBALS['conf']['clean_url'])) ? $langcode . '.example.com/admin' : $langcode . '.example.com/?q=admin';
+
+ // Test URL in another language.
+ // Base path gives problems on the testbot, so $correct_link is hard-coded.
+ // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
+ $url = url('admin', array('language' => $languages[$langcode]));
+ $url_scheme = ($is_https) ? 'https://' : 'http://';
+ $correct_link = $url_scheme . $link;
+ $this->assertTrue($url == $correct_link, format_string('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
+
+ // Test HTTPS via options.
+ variable_set('https', TRUE);
+ $url = url('admin', array('https' => TRUE, 'language' => $languages[$langcode]));
+ $correct_link = 'https://' . $link;
+ $this->assertTrue($url == $correct_link, format_string('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
+ variable_set('https', FALSE);
+
+ // Test HTTPS via current URL scheme.
+ $temp_https = $is_https;
+ $is_https = TRUE;
+ $url = url('admin', array('language' => $languages[$langcode]));
+ $correct_link = 'https://' . $link;
+ $this->assertTrue($url == $correct_link, format_string('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
+ $is_https = $temp_https;
+ }
+ }
+}
+
+/**
+ * Test that URL rewriting works as expected.
+ */
+class LocaleUrlRewritingTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'URL rewriting',
+ 'description' => 'Test that URL rewriting works as expected.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+
+ // Create and login user.
+ $this->web_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ $this->drupalLogin($this->web_user);
+
+ // Install French language.
+ $edit = array();
+ $edit['langcode'] = 'fr';
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ // Install Italian language.
+ $edit = array();
+ $edit['langcode'] = 'it';
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ // Disable Italian language.
+ $edit = array('enabled[it]' => FALSE);
+ $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
+
+ // Enable URL language detection and selection.
+ $edit = array('language[enabled][locale-url]' => 1);
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Reset static caching.
+ drupal_static_reset('language_list');
+ drupal_static_reset('locale_url_outbound_alter');
+ drupal_static_reset('locale_language_url_rewrite_url');
+ }
+
+ /**
+ * Check that disabled or non-installed languages are not considered.
+ */
+ function testUrlRewritingEdgeCases() {
+ // Check URL rewriting with a disabled language.
+ $languages = language_list();
+ $this->checkUrl($languages['it'], 'Path language is ignored if language is disabled.', 'URL language negotiation does not work with disabled languages');
+
+ // Check URL rewriting with a non-installed language.
+ $non_existing = language_default();
+ $non_existing->language = $this->randomName();
+ $non_existing->prefix = $this->randomName();
+ $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');
+ }
+
+ /**
+ * Check URL rewriting for the given language.
+ *
+ * The test is performed with a fixed URL (the default front page) to simply
+ * check that language prefixes are not added to it and that the prefixed URL
+ * is actually not working.
+ *
+ * @param string $language
+ * The language prefix, e.g. 'es'.
+ * @param string $message1
+ * Message to display in assertion that language prefixes are not added.
+ * @param string $message2
+ * The message to display confirming prefixed URL is not working.
+ */
+ private function checkUrl($language, $message1, $message2) {
+ $options = array('language' => $language);
+ $base_path = trim(base_path(), '/');
+ $rewritten_path = trim(str_replace(array('?q=', $base_path), '', url('node', $options)), '/');
+ $segments = explode('/', $rewritten_path, 2);
+ $prefix = $segments[0];
+ $path = isset($segments[1]) ? $segments[1] : $prefix;
+ // If the rewritten URL has not a language prefix we pick the right one from
+ // the language object so we can always check the prefixed URL.
+ if ($this->assertNotEqual($language->prefix, $prefix, $message1)) {
+ $prefix = $language->prefix;
+ }
+ $this->drupalGet("$prefix/$path");
+ $this->assertResponse(404, $message2);
+ }
+}
+
+/**
+ * Functional test for multilingual fields.
+ */
+class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Multilingual fields',
+ 'description' => 'Test multilingual support for fields.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ // Setup users.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
+ $this->drupalLogin($admin_user);
+
+ // Add a new language.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ locale_add_language('it', 'Italian', 'Italiano', LANGUAGE_LTR, '', '', TRUE, FALSE);
+
+ // Enable URL language detection and selection.
+ $edit = array('language[enabled][locale-url]' => '1');
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Set "Basic page" content type to use multilingual support.
+ $edit = array(
+ 'language_content_type' => 1,
+ );
+ $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
+
+ // Make node body translatable.
+ $field = field_info_field('body');
+ $field['translatable'] = TRUE;
+ field_update_field($field);
+ }
+
+ /**
+ * Test if field languages are correctly set through the node form.
+ */
+ function testMultilingualNodeForm() {
+ // Create "Basic page" content.
+ $langcode = LANGUAGE_NONE;
+ $title_key = "title";
+ $title_value = $this->randomName(8);
+ $body_key = "body[$langcode][0][value]";
+ $body_value = $this->randomName(16);
+
+ // Create node to edit.
+ $edit = array();
+ $edit[$title_key] = $title_value;
+ $edit[$body_key] = $body_value;
+ $edit['language'] = 'en';
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+
+ // Check that the node exists in the database.
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
+ $this->assertTrue($node, 'Node found in database.');
+
+ $assert = isset($node->body['en']) && !isset($node->body[LANGUAGE_NONE]) && $node->body['en'][0]['value'] == $body_value;
+ $this->assertTrue($assert, 'Field language correctly set.');
+
+ // Change node language.
+ $this->drupalGet("node/$node->nid/edit");
+ $edit = array(
+ $title_key => $this->randomName(8),
+ 'language' => 'it'
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
+ $this->assertTrue($node, 'Node found in database.');
+
+ $assert = isset($node->body['it']) && !isset($node->body['en']) && $node->body['it'][0]['value'] == $body_value;
+ $this->assertTrue($assert, 'Field language correctly changed.');
+
+ // Enable content language URL detection.
+ language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LOCALE_LANGUAGE_NEGOTIATION_URL => 0));
+
+ // Test multilingual field language fallback logic.
+ $this->drupalGet("it/node/$node->nid");
+ $this->assertRaw($body_value, 'Body correctly displayed using Italian as requested language');
+
+ $this->drupalGet("node/$node->nid");
+ $this->assertRaw($body_value, 'Body correctly displayed using English as requested language');
+ }
+
+ /*
+ * Test multilingual field display settings.
+ */
+ function testMultilingualDisplaySettings() {
+ // Create "Basic page" content.
+ $langcode = LANGUAGE_NONE;
+ $title_key = "title";
+ $title_value = $this->randomName(8);
+ $body_key = "body[$langcode][0][value]";
+ $body_value = $this->randomName(16);
+
+ // Create node to edit.
+ $edit = array();
+ $edit[$title_key] = $title_value;
+ $edit[$body_key] = $body_value;
+ $edit['language'] = 'en';
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+
+ // Check that the node exists in the database.
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
+ $this->assertTrue($node, 'Node found in database.');
+
+ // Check if node body is showed.
+ $this->drupalGet("node/$node->nid");
+ $body = $this->xpath('//div[@id=:id]//div[@property="content:encoded"]/p', array(':id' => 'node-' . $node->nid));
+ $this->assertEqual(current($body), $node->body['en'][0]['value'], 'Node body is correctly showed.');
+ }
+}
+
+/**
+ * Functional tests for comment language.
+ */
+class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment language',
+ 'description' => 'Tests for comment language.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale', 'locale_test');
+
+ // Create and login user.
+ $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'administer content types', 'administer comments', 'create article content'));
+ $this->drupalLogin($admin_user);
+
+ // Add language.
+ $edit = array('langcode' => 'fr');
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ // Set "Article" content type to use multilingual support.
+ $edit = array('language_content_type' => 1);
+ $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
+
+ // Enable content language negotiation UI.
+ variable_set('locale_test_content_language_type', TRUE);
+
+ // Set interface language detection to user and content language detection
+ // to URL. Disable inheritance from interface language to ensure content
+ // language will fall back to the default language if no URL language can be
+ // detected.
+ $edit = array(
+ 'language[enabled][locale-user]' => TRUE,
+ 'language_content[enabled][locale-url]' => TRUE,
+ 'language_content[enabled][locale-interface]' => FALSE,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Change user language preference, this way interface language is always
+ // French no matter what path prefix the URLs have.
+ $edit = array('language' => 'fr');
+ $this->drupalPost("user/{$admin_user->uid}/edit", $edit, t('Save'));
+
+ // Make comment body translatable.
+ $field = field_info_field('comment_body');
+ $field['translatable'] = TRUE;
+ field_update_field($field);
+ $this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.');
+ }
+
+ /**
+ * Test that comment language is properly set.
+ */
+ function testCommentLanguage() {
+ drupal_static_reset('language_list');
+
+ // Create two nodes, one for english and one for french, and comment each
+ // node using both english and french as content language by changing URL
+ // language prefixes. Meanwhile interface language is always French, which
+ // is the user language preference. This way we can ensure that node
+ // language and interface language do not influence comment language, as
+ // only content language has to.
+ foreach (language_list() as $node_langcode => $node_language) {
+ $language_none = LANGUAGE_NONE;
+
+ // Create "Article" content.
+ $title = $this->randomName();
+ $edit = array(
+ "title" => $title,
+ "body[$language_none][0][value]" => $this->randomName(),
+ "language" => $node_langcode,
+ );
+ $this->drupalPost("node/add/article", $edit, t('Save'));
+ $node = $this->drupalGetNodeByTitle($title);
+
+ foreach (language_list() as $langcode => $language) {
+ // Post a comment with content language $langcode.
+ $prefix = empty($language->prefix) ? '' : $language->prefix . '/';
+ $comment_values[$node_langcode][$langcode] = $this->randomName();
+ // Initially field form widgets have no language.
+ $edit = array(
+ 'subject' => $this->randomName(),
+ "comment_body[$language_none][0][value]" => $comment_values[$node_langcode][$langcode],
+ );
+ $this->drupalPost("{$prefix}node/{$node->nid}", $edit, t('Preview'));
+ // After the first submit the submitted entity language is taken into
+ // account.
+ $edit = array(
+ 'subject' => $edit['subject'],
+ "comment_body[$langcode][0][value]" => $comment_values[$node_langcode][$langcode],
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ // Check that comment language matches the current content language.
+ $cid = db_select('comment', 'c')
+ ->fields('c', array('cid'))
+ ->condition('nid', $node->nid)
+ ->orderBy('cid', 'DESC')
+ ->range(0, 1)
+ ->execute()
+ ->fetchField();
+ $comment = comment_load($cid);
+ $comment_langcode = entity_language('comment', $comment);
+ $args = array('%node_language' => $node_langcode, '%comment_language' => $comment_langcode, '%langcode' => $langcode);
+ $this->assertEqual($comment_langcode, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
+ $this->assertEqual($comment->comment_body[$langcode][0]['value'], $comment_values[$node_langcode][$langcode], 'Comment body correctly stored.');
+ }
+ }
+
+ // Check that comment bodies appear in the administration UI.
+ $this->drupalGet('admin/content/comment');
+ foreach ($comment_values as $node_values) {
+ foreach ($node_values as $value) {
+ $this->assertRaw($value);
+ }
+ }
+ }
+
+}
+
+/**
+ * Functional tests for localizing date formats.
+ */
+class LocaleDateFormatsFunctionalTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Localize date formats',
+ 'description' => 'Tests for the localization of date formats.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+
+ // Create and login user.
+ $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'create article content'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Functional tests for localizing date formats.
+ */
+ function testLocalizeDateFormats() {
+ // Add language.
+ $edit = array(
+ 'langcode' => 'fr',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ // Set language negotiation.
+ $language_type = LANGUAGE_TYPE_INTERFACE;
+ $edit = array(
+ "{$language_type}[enabled][locale-url]" => TRUE,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Configure date formats.
+ $this->drupalGet('admin/config/regional/date-time/locale');
+ $this->assertText('Français', 'Configured languages appear.');
+ $edit = array(
+ 'date_format_long' => 'd.m.Y - H:i',
+ 'date_format_medium' => 'd.m.Y - H:i',
+ 'date_format_short' => 'd.m.Y - H:i',
+ );
+ $this->drupalPost('admin/config/regional/date-time/locale/fr/edit', $edit, t('Save configuration'));
+ $this->assertText(t('Configuration saved.'), 'French date formats updated.');
+ $edit = array(
+ 'date_format_long' => 'j M Y - g:ia',
+ 'date_format_medium' => 'j M Y - g:ia',
+ 'date_format_short' => 'j M Y - g:ia',
+ );
+ $this->drupalPost('admin/config/regional/date-time/locale/en/edit', $edit, t('Save configuration'));
+ $this->assertText(t('Configuration saved.'), 'English date formats updated.');
+
+ // Create node content.
+ $node = $this->drupalCreateNode(array('type' => 'article'));
+
+ // Configure format for the node posted date changes with the language.
+ $this->drupalGet('node/' . $node->nid);
+ $english_date = format_date($node->created, 'custom', 'j M Y');
+ $this->assertText($english_date, 'English date format appears');
+ $this->drupalGet('fr/node/' . $node->nid);
+ $french_date = format_date($node->created, 'custom', 'd.m.Y');
+ $this->assertText($french_date, 'French date format appears');
+ }
+}
+
+/**
+ * Functional test for language types/negotiation info.
+ */
+class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Language negotiation info',
+ 'description' => 'Tests alterations to language types/negotiation info.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ require_once DRUPAL_ROOT .'/includes/language.inc';
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'view the administration theme'));
+ $this->drupalLogin($admin_user);
+ $this->drupalPost('admin/config/regional/language/add', array('langcode' => 'it'), t('Add language'));
+ }
+
+ /**
+ * Tests alterations to language types/negotiation info.
+ */
+ function testInfoAlterations() {
+ // Enable language type/negotiation info alterations.
+ variable_set('locale_test_language_types', TRUE);
+ variable_set('locale_test_language_negotiation_info', TRUE);
+ $this->languageNegotiationUpdate();
+
+ // Check that fixed language types are properly configured without the need
+ // of saving the language negotiation settings.
+ $this->checkFixedLanguageTypes();
+
+ // Make the content language type configurable by updating the language
+ // negotiation settings with the proper flag enabled.
+ variable_set('locale_test_content_language_type', TRUE);
+ $this->languageNegotiationUpdate();
+ $type = LANGUAGE_TYPE_CONTENT;
+ $language_types = variable_get('language_types', drupal_language_types());
+ $this->assertTrue($language_types[$type], 'Content language type is configurable.');
+
+ // Enable some core and custom language providers. The test language type is
+ // supposed to be configurable.
+ $test_type = 'test_language_type';
+ $provider = LOCALE_LANGUAGE_NEGOTIATION_INTERFACE;
+ $test_provider = 'test_language_provider';
+ $form_field = $type . '[enabled]['. $provider .']';
+ $edit = array(
+ $form_field => TRUE,
+ $type . '[enabled][' . $test_provider . ']' => TRUE,
+ $test_type . '[enabled][' . $test_provider . ']' => TRUE,
+ );
+ $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+ // Remove the interface language provider by updating the language
+ // negotiation settings with the proper flag enabled.
+ variable_set('locale_test_language_negotiation_info_alter', TRUE);
+ $this->languageNegotiationUpdate();
+ $negotiation = variable_get("language_negotiation_$type", array());
+ $this->assertFalse(isset($negotiation[$provider]), 'Interface language provider removed from the stored settings.');
+ $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, 'Interface language provider unavailable.');
+
+ // Check that type-specific language providers can be assigned only to the
+ // corresponding language types.
+ foreach (language_types_configurable() as $type) {
+ $form_field = $type . '[enabled][test_language_provider_ts]';
+ if ($type == $test_type) {
+ $this->assertFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider available for %type.', array('%type' => $type)));
+ }
+ else {
+ $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider unavailable for %type.', array('%type' => $type)));
+ }
+ }
+
+ // Check language negotiation results.
+ $this->drupalGet('');
+ $last = variable_get('locale_test_language_negotiation_last', array());
+ foreach (language_types() as $type) {
+ $langcode = $last[$type];
+ $value = $type == LANGUAGE_TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
+ $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type, '%language' => $langcode)));
+ }
+
+ // Disable locale_test and check that everything is set back to the original
+ // status.
+ $this->languageNegotiationUpdate('disable');
+
+ // Check that only the core language types are available.
+ foreach (language_types() as $type) {
+ $this->assertTrue(strpos($type, 'test') === FALSE, format_string('The %type language is still available', array('%type' => $type)));
+ }
+
+ // Check that fixed language types are properly configured, even those
+ // previously set to configurable.
+ $this->checkFixedLanguageTypes();
+
+ // Check that unavailable language providers are not present in the
+ // negotiation settings.
+ $negotiation = variable_get("language_negotiation_$type", array());
+ $this->assertFalse(isset($negotiation[$test_provider]), 'The disabled test language provider is not part of the content language negotiation settings.');
+
+ // Check that configuration page presents the correct options and settings.
+ $this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
+ $this->assertNoRaw(t('This is a test language provider'), 'No test language provider available.');
+ }
+
+ /**
+ * Update language types/negotiation information.
+ *
+ * Manually invoke locale_modules_enabled()/locale_modules_disabled() since
+ * they would not be invoked after enabling/disabling locale_test the first
+ * time.
+ */
+ private function languageNegotiationUpdate($op = 'enable') {
+ static $last_op = NULL;
+ $modules = array('locale_test');
+
+ // Enable/disable locale_test only if we did not already before.
+ if ($last_op != $op) {
+ $function = "module_{$op}";
+ $function($modules);
+ // Reset hook implementation cache.
+ module_implements(NULL, FALSE, TRUE);
+ }
+
+ drupal_static_reset('language_types_info');
+ drupal_static_reset('language_negotiation_info');
+ $function = "locale_modules_{$op}d";
+ if (function_exists($function)) {
+ $function($modules);
+ }
+
+ $this->drupalGet('admin/config/regional/language/configure');
+ }
+
+ /**
+ * Check that language negotiation for fixed types matches the stored one.
+ */
+ private function checkFixedLanguageTypes() {
+ drupal_static_reset('language_types_info');
+ foreach (language_types_info() as $type => $info) {
+ if (isset($info['fixed'])) {
+ $negotiation = variable_get("language_negotiation_$type", array());
+ $equal = count($info['fixed']) == count($negotiation);
+ while ($equal && list($id) = each($negotiation)) {
+ list(, $info_id) = each($info['fixed']);
+ $equal = $info_id == $id;
+ }
+ $this->assertTrue($equal, format_string('language negotiation for %type is properly set up', array('%type' => $type)));
+ }
+ }
+ }
+}
+
+/**
+ * Functional tests for CSS alter functions.
+ */
+class LocaleCSSAlterTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'CSS altering',
+ 'description' => 'Test CSS alter functions.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ /**
+ * Verifies that -rtl.css file is added directly after LTR .css file.
+ */
+ function testCSSFilesOrderInRTLMode() {
+ global $base_url;
+
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
+
+ // Log in as admin.
+ $this->drupalLogin($admin_user);
+
+ // Install the Arabic language (which is RTL) and configure as the default.
+ $edit = array();
+ $edit['langcode'] = 'ar';
+ $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+ $edit = array();
+ $edit['site_default'] = 'ar';
+ $this->drupalPost(NULL, $edit, t('Save configuration'));
+
+ // Verify that the -rtl.css file is added directly after LTR file.
+ $this->drupalGet('');
+ $query_string = '?' . variable_get('css_js_query_string', '0');
+ $this->assertRaw('@import url("' . $base_url . '/modules/system/system.base.css' . $query_string . '");' . "\n" . '@import url("' . $base_url . '/modules/system/system.base-rtl.css' . $query_string . '");' . "\n", 'CSS: system.base-rtl.css is added directly after system.base.css.');
+ $this->assertRaw('@import url("' . $base_url . '/modules/system/system.menus.css' . $query_string . '");' . "\n" . '@import url("' . $base_url . '/modules/system/system.menus-rtl.css' . $query_string . '");' . "\n", 'CSS: system.menus-rtl.css is added directly after system.menus.css.');
+ $this->assertRaw('@import url("' . $base_url . '/modules/system/system.messages.css' . $query_string . '");' . "\n" . '@import url("' . $base_url . '/modules/system/system.messages-rtl.css' . $query_string . '");' . "\n", 'CSS: system.messages-rtl.css is added directly after system.messages.css.');
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.info b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.info
new file mode 100644
index 0000000..7506100
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.info
@@ -0,0 +1,12 @@
+name = "Locale Test"
+description = "Support module for the locale layer tests."
+core = 7.x
+package = Testing
+version = VERSION
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.js b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.js
new file mode 100644
index 0000000..0693bca
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.js
@@ -0,0 +1,46 @@
+
+Drupal.t("Standard Call t");
+Drupal
+.
+t
+(
+"Whitespace Call t"
+)
+;
+
+Drupal.t('Single Quote t');
+Drupal.t('Single Quote \'Escaped\' t');
+Drupal.t('Single Quote ' + 'Concat ' + 'strings ' + 't');
+
+Drupal.t("Double Quote t");
+Drupal.t("Double Quote \"Escaped\" t");
+Drupal.t("Double Quote " + "Concat " + "strings " + "t");
+
+Drupal.t("Context Unquoted t", {}, {context: "Context string unquoted"});
+Drupal.t("Context Single Quoted t", {}, {'context': "Context string single quoted"});
+Drupal.t("Context Double Quoted t", {}, {"context": "Context string double quoted"});
+
+Drupal.t("Context !key Args t", {'!key': 'value'}, {context: "Context string"});
+
+Drupal.formatPlural(1, "Standard Call plural", "Standard Call @count plural");
+Drupal
+.
+formatPlural
+(
+1,
+"Whitespace Call plural",
+"Whitespace Call @count plural"
+)
+;
+
+Drupal.formatPlural(1, 'Single Quote plural', 'Single Quote @count plural');
+Drupal.formatPlural(1, 'Single Quote \'Escaped\' plural', 'Single Quote \'Escaped\' @count plural');
+
+Drupal.formatPlural(1, "Double Quote plural", "Double Quote @count plural");
+Drupal.formatPlural(1, "Double Quote \"Escaped\" plural", "Double Quote \"Escaped\" @count plural");
+
+Drupal.formatPlural(1, "Context Unquoted plural", "Context Unquoted @count plural", {}, {context: "Context string unquoted"});
+Drupal.formatPlural(1, "Context Single Quoted plural", "Context Single Quoted @count plural", {}, {'context': "Context string single quoted"});
+Drupal.formatPlural(1, "Context Double Quoted plural", "Context Double Quoted @count plural", {}, {"context": "Context string double quoted"});
+
+Drupal.formatPlural(1, "Context !key Args plural", "Context !key Args @count plural", {'!key': 'value'}, {context: "Context string"});
diff --git a/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.module b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.module
new file mode 100644
index 0000000..64f4aed
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/tests/locale_test.module
@@ -0,0 +1,242 @@
+<?php
+
+/**
+ * @file
+ * Mock module for locale layer tests.
+ */
+
+/**
+ * Implements hook_locale().
+ */
+function locale_test_locale($op = 'groups') {
+ switch ($op) {
+ case 'groups':
+ return array('custom' => t('Custom'));
+ }
+}
+
+/**
+ * Implements hook_boot().
+ *
+ * For testing domain language negotiation, we fake it by setting
+ * the HTTP_HOST here
+ */
+function locale_test_boot() {
+ if (variable_get('locale_test_domain')) {
+ $_SERVER['HTTP_HOST'] = variable_get('locale_test_domain');
+ }
+}
+
+/**
+ * Implements hook_init().
+ */
+function locale_test_init() {
+ locale_test_store_language_negotiation();
+ if (isset($GLOBALS['language']) && isset($GLOBALS['language']->provider)) {
+ drupal_set_message(t('Language negotiation provider: @name', array('@name' => $GLOBALS['language']->provider)));
+ }
+}
+
+/**
+ * Implements hook_language_types_info().
+ */
+function locale_test_language_types_info() {
+ if (variable_get('locale_test_language_types', FALSE)) {
+ return array(
+ 'test_language_type' => array(
+ 'name' => t('Test'),
+ 'description' => t('A test language type.'),
+ ),
+ 'fixed_test_language_type' => array(
+ 'fixed' => array('test_language_provider'),
+ ),
+ );
+ }
+}
+
+/**
+ * Implements hook_menu().
+ *
+ * @return array
+ */
+function locale_test_menu() {
+ $items = array();
+ $items['locale_test_plural_format_page'] = array(
+ 'page callback' => 'locale_test_plural_format_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ return $items;
+}
+
+/**
+ * Implements hook_language_types_info_alter().
+ */
+function locale_test_language_types_info_alter(array &$language_types) {
+ if (variable_get('locale_test_content_language_type', FALSE)) {
+ unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']);
+ }
+}
+
+/**
+ * Implements hook_language_negotiation_info().
+ */
+function locale_test_language_negotiation_info() {
+ if (variable_get('locale_test_language_negotiation_info', FALSE)) {
+ $info = array(
+ 'callbacks' => array(
+ 'language' => 'locale_test_language_provider',
+ ),
+ 'file' => drupal_get_path('module', 'locale_test') .'/locale_test.module',
+ 'weight' => -10,
+ 'description' => t('This is a test language provider.'),
+ );
+
+ return array(
+ 'test_language_provider' => array(
+ 'name' => t('Test'),
+ 'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'),
+ ) + $info,
+ 'test_language_provider_ts' => array(
+ 'name' => t('Type-specific test'),
+ 'types' => array('test_language_type'),
+ ) + $info,
+ );
+ }
+}
+
+/**
+ * Implements hook_language_negotiation_info_alter().
+ */
+function locale_test_language_negotiation_info_alter(array &$language_providers) {
+ if (variable_get('locale_test_language_negotiation_info_alter', FALSE)) {
+ unset($language_providers[LOCALE_LANGUAGE_NEGOTIATION_INTERFACE]);
+ }
+}
+
+/**
+ * Store the last negotiated languages.
+ */
+function locale_test_store_language_negotiation() {
+ $last = array();
+ foreach (language_types() as $type) {
+ $last[$type] = $GLOBALS[$type]->language;
+ }
+ variable_set('locale_test_language_negotiation_last', $last);
+}
+
+/**
+ * Test language provider.
+ */
+function locale_test_language_provider($languages) {
+ return 'it';
+}
+
+/**
+ * Returns markup for locale_get_plural testing.
+ *
+ * @return array
+ */
+function locale_test_plural_format_page() {
+ $tests = _locale_test_plural_format_tests();
+ $result = array();
+ foreach ($tests as $test) {
+ $string_param = array(
+ '@lang' => $test['language'],
+ '@locale_get_plural' => locale_get_plural($test['count'], $test['language'])
+ );
+ $result[] = array(
+ '#prefix' => '<br/>',
+ '#markup' => format_string('Language: @lang, locale_get_plural: @locale_get_plural.', $string_param),
+ );
+ }
+ return $result;
+}
+
+/**
+ * Helper function with list of test cases
+ *
+ * @return array
+ */
+function _locale_test_plural_format_tests() {
+ return array(
+ // Test data for English (no formula present).
+ array(
+ 'count' => 1,
+ 'language' => 'en',
+ 'expected-result' => 0,
+ ),
+ array(
+ 'count' => 0,
+ 'language' => 'en',
+ 'expected-result' => 1,
+ ),
+ array(
+ 'count' => 5,
+ 'language' => 'en',
+ 'expected-result' => 1,
+ ),
+
+ // Test data for French (simpler formula).
+ array(
+ 'count' => 1,
+ 'language' => 'fr',
+ 'expected-result' => 0,
+ ),
+ array(
+ 'count' => 0,
+ 'language' => 'fr',
+ 'expected-result' => 1,
+ ),
+ array(
+ 'count' => 5,
+ 'language' => 'fr',
+ 'expected-result' => 1,
+ ),
+
+ // Test data for Croatian (more complex formula).
+ array(
+ 'count' => 1,
+ 'language' => 'hr',
+ 'expected-result' => 0,
+ ),
+ array(
+ 'count' => 21,
+ 'language' => 'hr',
+ 'expected-result' => 0,
+ ),
+ array(
+ 'count' => 0,
+ 'language' => 'hr',
+ 'expected-result' => 2,
+ ),
+ array(
+ 'count' => 2,
+ 'language' => 'hr',
+ 'expected-result' => 1,
+ ),
+ array(
+ 'count' => 8,
+ 'language' => 'hr',
+ 'expected-result' => 2,
+ ),
+
+ // Test data for Hungarian (nonexistent language).
+ array(
+ 'count' => 1,
+ 'language' => 'hu',
+ 'expected-result' => -1,
+ ),
+ array(
+ 'count' => 21,
+ 'language' => 'hu',
+ 'expected-result' => -1,
+ ),
+ array(
+ 'count' => 0,
+ 'language' => 'hu',
+ 'expected-result' => -1,
+ ),
+ );
+}
diff --git a/kolab.org/www/drupal-7.26/modules/locale/tests/translations/test.xx.po b/kolab.org/www/drupal-7.26/modules/locale/tests/translations/test.xx.po
new file mode 100644
index 0000000..659a6e3
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/locale/tests/translations/test.xx.po
@@ -0,0 +1,28 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 7\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
+
+msgid "Monday"
+msgstr "lundi"
+
+msgid "Tuesday"
+msgstr "mardi"
+
+msgid "Wednesday"
+msgstr "mercredi"
+
+msgid "Thursday"
+msgstr "jeudi"
+
+msgid "Friday"
+msgstr "vendredi"
+
+msgid "Saturday"
+msgstr "samedi"
+
+msgid "Sunday"
+msgstr "dimanche"