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.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan’s picture

Status: Active » Needs review
FileSize
1.8 KB

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

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

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

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
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
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
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

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

Gábor Hojtsy’s picture

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.