Problem/Motivation

When a language is added using the Add language page (admin/config/regional/language/add) a batch process is started to perform configuration translation. However when a language is added upon importing a po file new translation (admin/config/regional/translate/import) this process is not initiated.

Steps to reproduce

  1. Have a fresh Drupal installation with standard profile.
  2. Enable the Language and Interface Translation modules.
  3. Download a Dutch translation file from http://ftp.drupal.org/files/translations/8.x/drupal/drupal-8.0-alpha3.nl.po onto you own computer
  4. Import this translation file at admin/config/regional/translate/import
  5. Look for a batch process with the text "Completed x of 11". You will not find it.
  6. Add a language at admin/config/regional/language
  7. Look for a batch process with the text "Completed x of 11". You will find it.
Files: 
CommentFileSizeAuthor
#22 locale-import-with-config-update-2095787-22-same-as-20.patch3.36 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,321 pass(es). View
#22 locale-import-with-config-update-2095787-22-TEST-ONLY.patch1.52 KBGábor Hojtsy
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,173 pass(es), 1 fail(s), and 0 exception(s). View
#21 locale-import-with-config-update-2095787-20-TEST-ONLY.patch1.84 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,196 pass(es). View
#20 interdiff.txt1.05 KBGábor Hojtsy
#20 locale-import-with-config-update-2095787-20.patch3.36 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,208 pass(es). View
#19 interdiff-9-19.txt1.51 KBfran seva
#19 locale-import-with-config-update-2095787-19.patch3.35 KBfran seva
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,218 pass(es). View
#17 2095787-draft-test.txt1.65 KBfran seva
#9 interdiff-2095787-6-9.txt1.16 KBadci_contributor
#9 locale-import-with-config-update-2095787-9.patch1.84 KBadci_contributor
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,905 pass(es). View
#6 2095787-6.patch1.92 KBrpayanm
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,880 pass(es), 117 fail(s), and 5 exception(s). View
#4 locale-import-with-config-update-2095787-4.patch1.75 KBSutharsan
PASSED: [[SimpleTest]]: [MySQL] 59,443 pass(es). View
#4 interdiff-2095787-3-4.txt6.07 KBSutharsan
#3 locale-import-with-config-update-2095787-3-test-must-fail.patch5.93 KBSutharsan
PASSED: [[SimpleTest]]: [MySQL] 58,932 pass(es). View
#3 locale-import-with-config-update-2095787-3.patch7.68 KBSutharsan
PASSED: [[SimpleTest]]: [MySQL] 59,168 pass(es). View
#3 interdiff-2095787-1-3.txt7.58 KBSutharsan
#1 locale-import-with-config-update-2095787-1.patch1.8 KBSutharsan
FAILED: [[SimpleTest]]: [MySQL] 59,254 pass(es), 9 fail(s), and 0 exception(s). View

Comments

Sutharsan’s picture

Status: Active » Needs review
FileSize
1.8 KB
FAILED: [[SimpleTest]]: [MySQL] 59,254 pass(es), 9 fail(s), and 0 exception(s). View

This fixes the problem.
TODO Test: Needs an additional assertion in the manual import test to check for updated configuration.

Status: Needs review » Needs work

The last submitted patch, locale-import-with-config-update-2095787-1.patch, failed testing.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
7.58 KB
7.68 KB
PASSED: [[SimpleTest]]: [MySQL] 59,168 pass(es). View
5.93 KB
PASSED: [[SimpleTest]]: [MySQL] 58,932 pass(es). View

Fixed the failing tests and added additional test assertions to detect the config update.
The patch locale-import-with-config-update-2095787-3-test-must-fail.patch only contains the new tests, not the patch.

Sutharsan’s picture

Issue tags: +Needs tests
FileSize
6.07 KB
1.75 KB
PASSED: [[SimpleTest]]: [MySQL] 59,443 pass(es). View

I currently can not figure out how to test whether the config translation is imported or not. Back to 'Needs tests'.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.92 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,880 pass(es), 117 fail(s), and 5 exception(s). View

Status: Needs review » Needs work

The last submitted patch, 6: 2095787-6.patch, failed testing.

Gábor Hojtsy’s picture

Issue tags: +sprint
adci_contributor’s picture

Status: Needs work » Needs review
FileSize
1.84 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,905 pass(es). View
1.16 KB

Trying to fix Fatal Error in #6

Gábor Hojtsy’s picture

Thanks! This should be possible to write tests for very similarly to InstallerTranslationMultipleLanguageTest in the current codebase. Take a string like 'Anonymous' and translate it in the imported .po file. Then verify it was updated. Without this patch it should not be, with this patch it should be. Look for the .po file snippet in InstallerTranslationMultipleLanguageTest and the test snippet at the bottom. Those should suffice to prove this test works in a .po import test.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Needs work for tests.

Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2015Queue
fran seva’s picture

Assigned: Unassigned » fran seva
Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2015

Tagging for sprint weekend.

develCuy’s picture

Issue tags: -SprintWeekend2015Queue
develCuy’s picture

Issue tags: +SprintWeekend2015Queue

Removed tag by mistake.

fran seva’s picture

FileSize
1.65 KB

@Gabor I've been working in the test but I'm having problems getting the translated word.
Attach a draft with the patch.

Gábor Hojtsy’s picture

I think there are some minor problems that surely make this fail now and that will make this work :) Basically use the right source string in the .po and get() the right key from the config and you should be set. The rest are to remove extra stuff that you don't use:

  1. +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
    @@ -334,6 +334,25 @@ public function testConfigPoFile() {
    +  public function testConfigtranslationImportingPoFile() {
    

    Should have a short docblock.

  2. +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
    @@ -334,6 +334,25 @@ public function testConfigPoFile() {
    +    $language_name = 'German';
    +    $languages = array(
    +      'de' => '',
    +    );
    

    You don't use these values, no need for them.

  3. +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
    @@ -334,6 +334,25 @@ public function testConfigPoFile() {
    +    // Verify the strings from the translation files were imported.
    +    $sample = 'Anonymous user';
    

    No need for this, see below.

  4. +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
    @@ -334,6 +334,25 @@ public function testConfigPoFile() {
    +    $this->assertEqual($config->get($sample), 'Anonymous German');
    

    Well you would get('anonymous'), the key of the value not the value :)

  5. +++ b/core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
    @@ -592,4 +611,22 @@ public function getPoFileWithConfig() {
    +msgid "Anonymous user"
    

    Should be "Anonymous" which is the shipped value in user.settings.yml, so it matches with the file.

fran seva’s picture

Status: Needs work » Needs review
FileSize
3.35 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,218 pass(es). View
1.51 KB

Attach test.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +blocker
FileSize
3.36 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,208 pass(es). View
1.05 KB

Fixed some minor code style and typos. Otherwise looked all good :) Thanks! Blocker for #2397281: Languages not translated when you add them.

Gábor Hojtsy’s picture

Title: Configuration translation not loaded when importing a po file » Configuration translations not updated when manually importing a .po file
FileSize
1.84 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,196 pass(es). View

Test only patch also. Also fixing title to be more accurate.

Gábor Hojtsy’s picture

FileSize
1.52 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,173 pass(es), 1 fail(s), and 0 exception(s). View
3.36 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,321 pass(es). View

Lol, that was a fix only, not a test only. Heh. Sorry.

The last submitted patch, 22: locale-import-with-config-update-2095787-22-TEST-ONLY.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

The is quite an ugly fix but given the state of the helper functions in the locale module I think it is acceptable. It is fixing the bug and adds tests. Tidying up the locale is separate and bigger issue. This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed c4990fc and pushed to 8.0.x. Thanks!

  • alexpott committed c4990fc on 8.0.x
    Issue #2095787 by Sutharsan, Gábor Hojtsy, fran seva, adci_contributor,...
Gábor Hojtsy’s picture

Issue tags: -sprint

Indeed, the fix is ugly but that is as far as our current locale batch update API allows us to go. While it would be nice to refactor that (and batch building in general), that does not get us closer to Drupal 8 release, so we'll need to live with it for Drupal 8.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.