Skip to content

Drush commands

The module provides two Drush commands. Both ask for confirmation, with no as the default answer, so scripts must pass -y. Both refuse an entity type that the settings do not enable.

Terminal window
drush ecdl:cdl <entity_type_id> <entity_id> <langcode>

The long name is entity_change_default_language:change-default-language. The command checks the entity type, the entity and the language, refuses an entity that is already in that language, and then changes it at once. The entity id can be a number or a string.

The demo site has an English article, Getting started, with Spanish and French translations. Its translations page shows English as the original language.

The translations table of the Getting started article with English as the original language

Make Spanish the default.

$ drush ecdl:cdl node 1 es -y
// Do you want to change the node Getting started default language to Spanish?:
// yes.
[OK] Entity default language changed successfully!

The translations table of the Getting started article with Spanish as the original language

Spanish is now the original language, and English and French are translations. Every translation is kept.

The entity must already have a translation in the new default language. Hidden gems is an English article with no Spanish translation, so the command refuses it.

$ drush ecdl:cdl node 4 es -y
Entity has no "Spanish" translation. Use --create-missing to create it from
the current default values.

Add --create-missing to create the Spanish translation from the current values first.

$ drush ecdl:cdl node 4 es --create-missing -y
// Do you want to change the node Hidden gems default language to Spanish?:
// yes.
[OK] Entity default language changed successfully!

The translations table of the Hidden gems article with Spanish as the original language and English as a translation

Paragraphs and other composites always follow the entity. Content that a plain reference field points to keeps its own default language, unless you name the field with --follow-fields. The field must target an enabled entity type. The demo article Latest news references Travel tips in field_related_article.

$ drush ecdl:cdl node 3 es --follow-fields=field_related_article -y
// Do you want to change the node Latest news default language to Spanish?:
// yes.
[OK] Entity default language changed successfully!

The translations table of the Travel tips article with Spanish as the original language, changed through the reference

Travel tips changed with Latest news. The field names apply at every level, so the same field on Travel tips is followed too.

Getting started is now Spanish, with English and French translations. Make French the default, keep English, and drop Spanish, the old default.

$ drush ecdl:cdl node 1 fr --preserve-languages=en --no-preserve-legacy-default-language -y
// Do you want to change the node Primeros pasos default language to French?:
// yes.
[OK] Entity default language changed successfully!

The translations table of the Getting started article with French as the original language, English as a translation and no Spanish translation

French is the original language now, English is a translation, and the Spanish values are gone.

Both commands accept these options.

Option Meaning
--preserve-languages=en,es The translations to keep. Without it every translation is kept. With it, only the listed ones stay, and the old default language too, unless you turn that off.
--preserve-legacy-default-language On by default. Keeps the old default language as a translation, even when --preserve-languages does not list it.
--no-preserve-legacy-default-language Drops the old default language, unless --preserve-languages lists it. Without --preserve-languages every other translation is kept.
--create-missing Creates the new default translation from the current values when the entity has none. Off by default.
--follow-fields=field_a,field_b Reference fields whose targets change their default language too. A field that targets an entity type the settings do not enable is refused. Paragraphs always follow.

Warning: Listing languages in --preserve-languages removes every translation that is not listed, apart from the old default. Leave the option out to keep everything.

Note: The whole change runs in one database transaction. If any part fails, nothing is stored and the command says so.

Terminal window
drush ecdl:dlet <entity_type_id> <langcode>

The long name is entity_change_default_language:change-default-language-entity-type. It does not change anything itself: it adds one queue item for every entity of the type whose default language is not yet the new one, and leaves the work to cron or to drush queue:run. See The queue for a full run.

It takes the options above, and --bundle.

Option Meaning
--bundle=article Only the entities of that bundle. It filters on the bundle key of the type, type for nodes and vid for taxonomy terms. An entity type without bundles, such as users, and a bundle the type does not have are refused.
Terminal window
drush ecdl:dlet node es --bundle=article --create-missing -y