Problem/Motivation

The export service excludes the default language of the site from the translation list.
But the entity defaultLangcode and defaultLangcode of the site are different cases and they could be different.
For example - the default language of the site could be EN, but the default language could be NL at the same time.

The issue caused by #3282218: Importing content with translations not in standard language environment throws error if translation already exists

Steps to reproduce

- Make a clean Drupal site.
- Add several languages to the site: EN, NL, FR, where EN is the default
- Create new content in the NL language - it means that NL is the default language now.
- Make translations into EN and FR
- Install single_content_sync module
- Export created content with all translations
EXPECTED RESULT: The content must be exported with 2 translations: EN and FR
ACTUAL RESULT: Content exported only with 2 translations - FR and NL

Example of the wrong result:

site_uuid: <uuid>
uuid: <uuid>
entity_type: node
bundle: blog
base_fields:
  title: 'Test NL'
  status: true
  langcode: nl
  created: '1680701082'
  author: swift+dstny@dropsolid.com
  url: /blog/test-nl
  revision_log_message: null
  revision_uid: '1'
custom_fields:
  body:
    -
      value: "<p>Test NL</p>\r\n"
      summary: ''
      format: full_html
......................................................
translations:
  nl:
    base_fields:
      title: 'Test NL'
      status: true
      langcode: nl
      created: '1680701082'
      author: swift+dstny@dropsolid.com
      url: /blog/test-nl
      revision_log_message: null
      revision_uid: '1'
    custom_fields:
      body:
        -
          value: "<p>Test NL</p>\r\n"
          summary: ''
          format: full_html
......................................................
  fr:
    base_fields:
      title: 'Test FR'
      status: true
      langcode: fr
      created: '1680701107'
      author: swift+dstny@dropsolid.com
      url: /blog/test-fr
      revision_log_message: null
      revision_uid: '1'
    custom_fields:
      body:
        -
          value: "<p>Test FR</p>\r\n"
          summary: ''
          format: full_html
......................................................

Proposed resolution

Use

$translations = $entity->getTranslationLanguages(FALSE);

in doExportToArray() instead of the current solution.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

HitchShock created an issue. See original summary.

hitchshock’s picture

Issue summary: View changes

hitchshock’s picture

Assigned: hitchshock » Unassigned
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new760 bytes

Have done a quick fix

nginex’s picture

Status: Needs review » Fixed

This issue is reproducable if your content type language is different than site default language.

Thanks for the patch, I will release it ASAP

nginex’s picture

Status: Fixed » Closed (fixed)

Available since 1.3.13

shrikant.dhotre’s picture

Thanks for this translation help, but still facing the same issue with 1.3.13 branch.

InvalidArgumentException: A translation already exists for the specified language (fr). in Drupal\Core\Entity\ContentEntityBase->onChange() (line 811 of C:\xampp\htdocs\cmacgm\dev\docroot\core\lib\Drupal\Core\Entity\ContentEntityBase.php).

shrikant.dhotre’s picture

I am having two translations of content and if I am export translated content I am getting above issue.

nginex’s picture

@shrikant.dhotre, Did you re-export the content after you updated the module to the latest version?

shrikant.dhotre’s picture

Yes @nginex, I have updated the module and tried multiple times with clearing cache with drush as well as browser link as well.

shrikant.dhotre’s picture

StatusFileSize
new56.68 KB
nginex’s picture

@shrikant.dhotre, thanks for the screenshot, I could reproduce the issue, I'm going to provide a fix right now and create a new release ASAP

nginex’s picture

@shrikant.dhotre, I provided the fix in the new release:

https://www.drupal.org/project/single_content_sync/releases/1.3.14

Please update the module first, re-export content and import again

shrikant.dhotre’s picture

Hi @nginex , Thanks fix now its working for all the translation

nginex’s picture

@shrikant.dhotre, this is great, thanks for reporting