diff -U2 b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php --- b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php @@ -171,11 +171,12 @@ $this->assertText('First plural form'); $this->assertText('2. plural form'); - // Plural values for both languages. + $this->assertNoText('3. plural form'); + + // Plural values for langcode hr. $this->assertText('@count sat'); $this->assertText('@count sata'); $this->assertText('@count sati'); - $this->assertNoText('3. plural form'); - // Edit some translations and see if that took effect. + // Edit langcode hr translations and see if that took effect. $edit = array( 'strings[10][translations][1]' => '@count sata edited', @@ -184,0 +186,15 @@ + $search = array( + 'langcode' => 'fr', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + // Plural values for the langcode fr. + $this->assertText('1 heure'); + $this->assertText('@count heures'); + $this->assertNoText('2. plural form'); + + // Edit langcode fr translations and see if that took effect. + $edit = array( + 'strings[10][translations][0]' => '1 heure edited', + ); + $this->drupalPost($path, $edit, t('Save translations')); + @@ -188,15 +204,29 @@ // specifically for a language. format_plural(1, '1 day', '@count days', array(), array('langcode' => 'fr')); - // Look up editing page for this plural string and check fields. $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 day" . LOCALE_PLURAL_DELIMITER . "@count days"))->fetchField(); - $path = 'admin/config/regional/translate/edit/' . $lid; + // Look up editing page for this plural string and check fields. + $search = array( + 'string' => '1 day', + 'langcode' => 'fr', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); - // Save complete translations for the string in both languages. + // Save complete translations for the string in langcode fr. $edit = array( - 'translations[fr][0]' => '1 jour', - 'translations[fr][1]' => '@count jours', - 'translations[hr][0]' => '@count dan', - 'translations[hr][1]' => '@count dana', - 'translations[hr][2]' => '@count dana', + "strings[$lid][translations][0]" => '1 jour', + "strings[$lid][translations][1]" => '@count jours', + ); + $this->drupalPost($path, $edit, t('Save translations')); + + // Save complete translations for the string in langcode hr. + $search = array( + 'string' => '1 day', + 'langcode' => 'hr', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + $edit = array( + "strings[$lid][translations][0]" => '@count dan', + "strings[$lid][translations][1]" => '@count dana', + "strings[$lid][translations][2]" => '@count dana', ); $this->drupalPost($path, $edit, t('Save translations')); @@ -219,5 +249,4 @@ } - /** * Imports a standalone .po file in a given language. diff -U2 b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php --- b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php @@ -75,9 +75,10 @@ // 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]; + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $this->randomName(), + ); // No t() here, it's surely not translated yet. $this->assertText($name, t('name found on edit screen.')); @@ -92,16 +93,41 @@ // Assume this is the only result, given the random name. - $this->clickLink(t('edit')); - $string_edit_url = $this->getUrl(); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; $edit = array( - "translations[$langcode][0]" => $translation, - 'translations[en][0]' => $translation_to_en, + $lid => $translation, ); - $this->drupalPost(NULL, $edit, t('Save translations')); - $this->assertText(t('The string has been saved.'), t('The string has been saved.')); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + $this->assertText(t('The strings have been saved.'), t('The strings have been saved.')); $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.')); - $this->drupalGet($string_edit_url); + $search = array( + 'string' => $name, + 'langcode' => $langcode, + 'translation' => 'translated', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); $this->assertRaw($translation, t('Non-English translation properly saved.')); + + + $search = array( + 'string' => $name, + 'langcode' => 'en', + 'translation' => 'untranslated', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $translation_to_en, + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + $search = array( + 'string' => $name, + 'langcode' => 'en', + 'translation' => 'translated', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); $this->assertRaw($translation_to_en, t('English translation properly saved.')); + $this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, t('t() works for non-English.')); // Refresh the locale() cache to get fresh data from t() below. We are in @@ -112,7 +138,12 @@ $this->assertTrue($name != $translation_to_en && t($name, array(), array('langcode' => 'en')) == $translation_to_en, t('t() works for English.')); $this->assertTrue(t($name, array(), array('langcode' => LANGUAGE_SYSTEM)) == $name, t('t() works for LANGUAGE_SYSTEM.')); + + $search = array( + 'string' => $name, + 'langcode' => 'en', + 'translation' => 'untranslated', + ); $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); - // The indicator should not be here. - $this->assertNoRaw($language_indicator, t('String is translated.')); + $this->assertText(t('No strings available.'), t('String is translated.')); $this->drupalLogout(); @@ -136,24 +167,24 @@ $search = array( 'string' => $name, - 'langcode' => $langcode, - 'translation' => 'all', + 'langcode' => 'en', + 'translation' => 'translated', ); $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'), t('"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)), t('Correct page redirection.')); - $this->assertRaw($name, t('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.'), t('The string has been removed message.')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.')); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => '', + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + $this->assertRaw($name, t('The strings have been saved.')); + $this->drupalLogin($translate_user); + $search = array( + 'string' => $name, + 'langcode' => 'en', + 'translation' => 'untranslated', + ); $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); - $this->assertNoText($name, t('Search now can not find the name.')); + $this->assertNoText(t('No strings available.'), t('The translation has been removed')); } @@ -181,14 +212,27 @@ // 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')->execute(); - $url = 'admin/config/regional/translate/edit/' . $result->fetchObject()->lid; - $edit = array('translations['. $langcode .'][0]' => $this->randomName()); - $this->drupalPost($url, $edit, t('Save translations')); + // Retrieve the source string of the first string available in the + // {locales_source} table and translate it. + $source = db_select('locales_source', 'l') + ->fields('l', array('source')) + ->condition('l.location', '%.js%', 'LIKE') + ->range(0, 1) + ->execute() + ->fetchField(); + + $search = array( + 'string' => $source, + 'langcode' => $langcode, + 'translation' => 'all', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $this->randomName(), + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); // Trigger JavaScript translation parsing and building. @@ -219,7 +263,5 @@ // The English name for the language. This will be translated. $name = $this->randomName(16); - // This is the language indicator on the translation search screen for - // untranslated strings. - $language_indicator = "$langcode "; + // These will be the invalid translations of $name. $key = $this->randomName(16); @@ -250,12 +292,12 @@ $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), t('Found the edit path.')); - $path = $matches[0]; + + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; foreach ($bad_translations as $key => $translation) { $edit = array( - "translations[$langcode][0]" => $translation, + $lid => $translation, ); - $this->drupalPost($path, $edit, t('Save translations')); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); // Check for a form error on the textarea. $form_class = $this->xpath('//form[@id="locale-translate-edit-form"]//textarea/@class'); @@ -295,4 +337,13 @@ ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); + + $edit = array( + 'predefined_langcode' => 'custom', + 'langcode' => 'yy', + 'name' => $this->randomName(16), + 'direction' => '0', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); + // Add string. t($name, array(), array('langcode' => $langcode)); @@ -336,13 +387,11 @@ // 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]; + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; $edit = array( - "translations[$langcode][0]" => $translation, + $lid => $translation, ); - $this->drupalPost(NULL, $edit, t('Save translations')); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); // Ensure translated string does appear if searching on 'only @@ -388,5 +437,5 @@ $search = array( 'string' => $translation, - 'langcode' => LANGUAGE_SYSTEM, + 'langcode' => 'yy', 'translation' => 'all', ); diff -U2 b/core/modules/locale/locale.css b/core/modules/locale/locale.css --- b/core/modules/locale/locale.css +++ b/core/modules/locale/locale.css @@ -3,6 +3,6 @@ #locale-translate-filter-form .form-item-customized { float: left; /* LTR */ - padding-right: .8em; /* LTR */ - margin: 0.1em; + padding-right: 1em; /* LTR */ + margin-bottom: 0; /** * In Opera 9, DOM elements with the property of "overflow: auto" @@ -19,2 +19,13 @@ - padding: 3ex 0 0 1em; /* LTR */ + padding: 3.5ex 0 0 0em; /* LTR */ } +#locale-translate-edit-form th{ + width: 50%; + table-layout: fixed; +} +#locale-translate-edit-form tr .form-item{ + white-space: normal; +} +#locale-translate-edit-form td { + vertical-align: top +} + diff -U2 b/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc --- b/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -169,6 +169,5 @@ } else { - - $empty_option = isset( $filter['options'][$filter['default']]) ? $filter['options'][$filter['default']] : array(); + $empty_option = isset($filter['options'][$filter['default']]) ? $filter['options'][$filter['default']] : ''; $form['filters']['status'][$key] = array( '#title' => $filter['title'], @@ -232,9 +231,7 @@ */ function locale_translate_edit_form($form, &$form_state) { - $strings = locale_translate_query(); - - $plural_formulas = variable_get('locale_translation_plurals', array()); - $filter_values = locale_translate_filter_values(); + $langcode = $filter_values['langcode']; + $form['langcode'] = array( '#type' => 'value', @@ -247,92 +244,99 @@ '#theme' => 'locale_translate_edit_form_strings', ); - foreach ($strings as $string) { - // Split source to work with plural values. - $source_array = explode(LOCALE_PLURAL_DELIMITER, $string->source); - $translation_array = explode(LOCALE_PLURAL_DELIMITER, $string->translation); - if (count($source_array) == 1) { - // Add original text value and mark as non-plural. - $form['strings'][$string->lid]['plural'] = array( - '#type' => 'value', - '#value' => 0 - ); - $form['strings'][$string->lid]['original'] = array( - '#type' => 'item', - '#title' => t('Original text'), - '#title_display' => 'invisible', - '#markup' => check_plain($source_array[0]), - ); - } - else { - // Add original text value and mark as plural. - $form['strings'][$string->lid]['plural'] = array( - '#type' => 'value', - '#value' => 1 - ); - $form['strings'][$string->lid]['original_singular'] = array( - '#type' => 'item', - '#title' => t('Singular form'), - '#markup' => check_plain($source_array[0]), - ); - $form['strings'][$string->lid]['original_plural'] = array( - '#type' => 'item', - '#title' => t('Plural form'), - '#markup' => check_plain($source_array[1]), - ); - } - if (!empty($string->context)) { - $form['strings'][$string->lid]['context'] = array( - '#type' => 'value', - '#value' => check_plain($string->context), - ); - } - $form['strings'][$string->lid]['location'] = array( - '#type' => 'value', - '#value' => $string->location, - ); - - // Approximate the number of rows to use in the default textarea. - $rows = min(ceil(str_word_count($source_array[0]) / 12), 10); - if (empty($form['strings'][$string->lid]['plural']['#value'])) { - $form['strings'][$string->lid]['translations'][0] = array( - '#type' => 'textarea', - '#title_display' => 'invisible', - '#rows' => $rows, - '#default_value' => $translation_array[0], - ); - } - else { - // Dealing with plural strings. - if (isset($plural_formulas[$string->language]['plurals']) && $plural_formulas[$string->language]['plurals'] > 1) { - // Add a textarea for each plural variant. - for ($i = 0; $i < $plural_formulas[$string->language]['plurals']; $i++) { - $form['strings'][$string->lid]['translations'][$i] = array( - '#type' => 'textarea', - '#title' => ($i == 0 ? t('Singular form') : format_plural($i, 'First plural form', '@count. plural form')), - '#rows' => $rows, - '#default_value' => $translation_array[$i], - ); - } + + if(isset($langcode)) { + $strings = locale_translate_query(); + + $plural_formulas = variable_get('locale_translation_plurals', array()); + + foreach ($strings as $string) { + // Split source to work with plural values. + $source_array = explode(LOCALE_PLURAL_DELIMITER, $string->source); + $translation_array = explode(LOCALE_PLURAL_DELIMITER, $string->translation); + if (count($source_array) == 1) { + // Add original text value and mark as non-plural. + $form['strings'][$string->lid]['plural'] = array( + '#type' => 'value', + '#value' => 0 + ); + $form['strings'][$string->lid]['original'] = array( + '#type' => 'item', + '#title' => t('Original text'), + '#title_display' => 'invisible', + '#markup' => check_plain($source_array[0]), + ); } else { - // Fallback for unknown number of plurals. + // Add original text value and mark as plural. + $form['strings'][$string->lid]['plural'] = array( + '#type' => 'value', + '#value' => 1 + ); + $form['strings'][$string->lid]['original_singular'] = array( + '#type' => 'item', + '#title' => t('Singular form'), + '#markup' => check_plain($source_array[0]), + ); + $form['strings'][$string->lid]['original_plural'] = array( + '#type' => 'item', + '#title' => t('Plural form'), + '#markup' => check_plain($source_array[1]), + ); + } + if (!empty($string->context)) { + $form['strings'][$string->lid]['context'] = array( + '#type' => 'value', + '#value' => check_plain($string->context), + ); + } + $form['strings'][$string->lid]['location'] = array( + '#type' => 'value', + '#value' => $string->location, + ); + + // Approximate the number of rows to use in the default textarea. + $rows = min(ceil(str_word_count($source_array[0]) / 12), 10); + if (empty($form['strings'][$string->lid]['plural']['#value'])) { $form['strings'][$string->lid]['translations'][0] = array( '#type' => 'textarea', - '#title' => t('Sigular form'), + '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], ); - $form['strings'][$string->lid]['translations'][1] = array( - '#type' => 'textarea', - '#title' => t('Plural form'), - '#rows' => $rows, - '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', - ); + } + else { + // Dealing with plural strings. + if (isset($plural_formulas[$langcode]['plurals']) && $plural_formulas[$langcode]['plurals'] > 2) { + // Add a textarea for each plural variant. + for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) { + $form['strings'][$string->lid]['translations'][$i] = array( + '#type' => 'textarea', + '#title' => ($i == 0 ? t('Singular form') : format_plural($i, 'First plural form', '@count. plural form')), + '#rows' => $rows, + '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', + ); + } + } + else { + // Fallback for unknown number of plurals. + $form['strings'][$string->lid]['translations'][0] = array( + '#type' => 'textarea', + '#title' => t('Singular form'), + '#rows' => $rows, + '#default_value' => $translation_array[0], + ); + $form['strings'][$string->lid]['translations'][1] = array( + '#type' => 'textarea', + '#title' => t('Plural form'), + '#rows' => $rows, + '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', + ); + } } } - } - if (count(element_children($form['strings']))) { - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save translations')); + if (count(element_children($form['strings']))) { + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save translations')); + } } return $form; only in patch2: --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -105,11 +105,25 @@ // 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'); + $search = array( + 'string' => $default_string, + 'langcode' => $langcode_browser_fallback, + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $language_browser_fallback_string, + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + + $search = array( + 'string' => $default_string, + 'langcode' => $langcode, + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; $edit = array( - "translations[$langcode_browser_fallback][0]" => $language_browser_fallback_string, - "translations[$langcode][0]" => $language_string, + $lid => $language_string, ); - $this->drupalPost(NULL, $edit, t('Save translations')); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); only in patch2: --- a/core/modules/locale/locale-rtl.css +++ b/core/modules/locale/locale-rtl.css @@ -1 +0,0 @@ - @@ -6 +5 @@ - padding-left: .8em; + padding-left: 1em; @@ -11 +10 @@ - padding: 3ex 1em 0 0; + padding: 3.5ex 0 0 0;