A translation already exists for the specified language

Created on 9 April 2020, over 4 years ago
Updated 18 September 2024, 2 months ago

Follow-up issue for #2829283: Language support in Feed import β†’

Problem/Motivation

When mapping to the target "Language (langcode)" in some situations this results in the following error:

A translation already exists for the specified language

This could be the steps to reproduce the issue, taken from #2829283-85: Language support in Feed import β†’ :

  1. Install Drupal, standard profile, default language set to English.
  2. Enable Language, Content translation and Feeds module.
  3. Add Finnish as 2nd language, enable Basic page content to be translated.
  4. Create a Feed type with mappings to feeds item, title, body and langcode. Title and body set to English.
  5. Create a feed.
  6. Import a CSV file that has one row with langcode set to "en" and one row with langcode set to "fi".

Result: "Import failed. A translation already exists for the specified language (fi).

The CSV file could look like this:

"guid","title","body","langcode"
1,"Lorem ipsum","Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.","en"
2,"Ut wisi enim ad minim veniam","Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.","fi"

Thanks @artis.bajars for providing these steps.

Proposed resolution

To be determined.

Remaining tasks

  1. Identify when the error occurs.
  2. Write a test that demonstrates the issue.
  3. Fix the issue.
  4. Review.
  5. Commit.

User interface changes

Probably none.

API changes

To be determined.

Data model changes

To be determined.

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands megachriz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands megachriz

    Tagging issue with "multilanguage", so I can find this issue back as soon as I plan to focus on Feeds multilingual issues again.

  • First commit to issue fork.
  • πŸ‡¨πŸ‡¦Canada nikathone Ontario

    I tried to reproduce the issue following the steps in the description but I couldn't. I ended up with two basic page content with two different languages. The two content are not connected as in being the same content with two different translation.

  • Status changed to Needs review 5 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    Patch Failed to Apply
  • πŸ‡΅πŸ‡ΉPortugal tmiguelv

    Hello!
    I was having the same problem as #9 and I did a little patch for importing content in the existing translations that worked for my site.
    I needed to make the feeds_item field translatable.
    For the translations to work, you need to:

    • Copy the steps from the description
    • Allow translations in the feed settings
    • Add a mapping field for an unique target (it can be ID, title, or something that will be used to relate both translations)
    • Enable translation for feeds_item field in the Content Type Settings

    Please feel free to review it and upgrade it

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    Patch Failed to Apply
  • πŸ‡΅πŸ‡ΉPortugal tmiguelv

    Added a validation to check if the language exists

  • πŸ‡«πŸ‡·France Julien Tekrane

    julien tekrane β†’ made their first commit to this issue’s fork.

  • Merge request !1953126351 : Allow translations β†’ (Open) created by Julien Tekrane
  • Pipeline finished with Failed
    2 months ago
    Total: 362s
    #285228
  • Pipeline finished with Failed
    2 months ago
    Total: 301s
    #285236
  • Status changed to Needs work 2 months ago
  • πŸ‡³πŸ‡±Netherlands megachriz

    @julien tekrane
    Thanks for putting the code from the patch in a merge request.

    Unfortunately, this cannot be merged as is because:

    • It is failing current tests.
    • It fails coding standards, spelling and PHPStan.
    • There is no test coverage for the bug it is trying to solve.

    I think that adding an automated test that demonstrates the bug is the most important one to do first.

  • Pipeline finished with Failed
    2 months ago
    Total: 245s
    #285443
  • Pipeline finished with Failed
    2 months ago
    Total: 298s
    #285465
  • Pipeline finished with Failed
    2 months ago
    Total: 252s
    #285508
  • Pipeline finished with Failed
    2 months ago
    Total: 293s
    #285515
  • Pipeline finished with Failed
    2 months ago
    Total: 366s
    #285578
  • Pipeline finished with Canceled
    2 months ago
    Total: 295s
    #285646
  • Pipeline finished with Success
    2 months ago
    Total: 355s
    #285648
  • Pipeline finished with Success
    2 months ago
    #285656
  • Pipeline finished with Failed
    2 months ago
    Total: 594s
    #285719
  • Pipeline finished with Failed
    2 months ago
    Total: 261s
    #285770
  • Pipeline finished with Failed
    2 months ago
    Total: 795s
    #285781
  • Pipeline finished with Failed
    2 months ago
    Total: 793s
    #285786
  • Status changed to Needs review 2 months ago
  • πŸ‡«πŸ‡·France Julien Tekrane

    Dear @megachriz,

    As maintainer can you please take a look into my Tests ?

  • πŸ‡³πŸ‡±Netherlands megachriz

    @julien tekrane
    Thanks for your work! I gave some initial feedback on the tests alone, I hope to find time to execute your test as well to check if it can demonstrate the issue.

  • πŸ‡³πŸ‡±Netherlands megachriz

    Review new test TranslationMultilineTest::testTranslationMultiline()

    Without the code applied, I've tried to run an import manually by looking what the test is trying to do:

    1. Create a feed type, set to only create items, do not update existing.
    2. Map to guid, title, langcode. Set "guid" as unique.
    3. Import the following CSV:
      "guid","title","langcode"
      1,"HELLO WORLD",en
      1,"HOLA MUNDO",es
      

    And I see that the first item gets imported and the second item gets ignored.

    More tests needed

    It's a good thing to test, so we should definitely keep that one. But there should also be a test that results into the error message "A translation already exists for the specified language". It looks like this can happen when you try to update an existing translation. So I think that there should be a test where a node already exists in two languages. And then try to update the translation.

    There is also an interesting issue in the following situation:

    1. A node exists in two languages (English and Spanish), but the Spanish version is set as original language. Assume that ID of the node is 1.
    2. Create a feed type to update existing nodes.
    3. Map to nid, title, langcode. Set "nid" as unique.
    4. Import the following CSV:
      "nid","title","langcode"
      1,"HELLO WORLD",en
      

    You now get the message "The translation language cannot be changed (en).".

    Might be useful to add a test for too.

    Solution review

    I only briefly glanced through the solution code and I wonder if importing translations should be optional. Shouldn't Feeds by default check for mapping to language? Or would there be a use case where you want Feeds to ignore translations, even when mapping to language?
    In the solution I also see that there's overlap with the patch provided in πŸ› Setting a target for "langcode" field will sometimes throw "this field cannot hold more than 1 values" Needs work . So perhaps these two issues should be combined into one. The scope would become bigger in this case, but I'm not sure if it's possible to fix issues related to the langcode target in smaller steps.

    My approach would be to first add all the test cases, see if they demonstrate the issues that we face. And then work further on polishing the solution.

Production build 0.71.5 2024