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.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | import-issue-with-translation-3352413.jpg | 56.68 KB | shrikant.dhotre |
| #5 | incorrect-export-of-translations-3352413-4.patch | 760 bytes | hitchshock |
Issue fork single_content_sync-3352413
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
Comment #2
hitchshockComment #3
hitchshockComment #5
hitchshockHave done a quick fix
Comment #7
nginex commentedThis issue is reproducable if your content type language is different than site default language.
Thanks for the patch, I will release it ASAP
Comment #8
nginex commentedAvailable since 1.3.13
Comment #9
shrikant.dhotre commentedThanks 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).
Comment #10
shrikant.dhotre commentedI am having two translations of content and if I am export translated content I am getting above issue.
Comment #11
nginex commented@shrikant.dhotre, Did you re-export the content after you updated the module to the latest version?
Comment #12
shrikant.dhotre commentedYes @nginex, I have updated the module and tried multiple times with clearing cache with drush as well as browser link as well.
Comment #13
shrikant.dhotre commentedComment #14
nginex commented@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
Comment #15
nginex commented@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
Comment #16
shrikant.dhotre commentedHi @nginex , Thanks fix now its working for all the translation
Comment #17
nginex commented@shrikant.dhotre, this is great, thanks for reporting