4

I made a mistake during the development of my Drupal 8 site. Some time ago I changed the default language (to german) - but I continued to create the configuration entities (like fields and so on) in English.

Now I found out that this was not really smart - and I want to change the default language of all existing configuration entities.

First of all, I just tried to delete the german language - so Drupal 8 switches back to English as default. Now every new configuration entity (new field) is defined in English. That's fine. But every existing configuration entity shows "Unknown (de) (original)" as the default language. And when I open it to save it again nothing changes.

I took a look into the database considering to change it directly there - but unfortunately, the configuration is stored binary.

Is there any other way to solve this problem?

2 Answers 2

2

I changed the configuration directly in the MySQL table "config" (In my case table names has a prefix ("something_config") so change the example below if necessary).

The configuration values are in the column "data".

First I cast the content to a string.

Then I replace the definition of the wrong langcode. In my case I replace 's:8:"langcode";s:2:"de"' with 's:8:"langcode";s:2:"en"'.

In the end I cast the result of this replace operation back to binary and save it in "data".

These three steps can be managed in one single SQL statement:

UPDATE `config` SET data = cast(
 replace(
    cast( data AS char ) , 's:8:"langcode";s:2:"de"', 's:8:"langcode";s:2:"en"'
 )
 AS BINARY ) 

Then clear the cache and you are done.

0
1

Export the full configuration in admin/config/development/configuration. You get the untranslated yaml files in the main folder. The translated yaml files are in languages/[languagecode].

The untranslated yaml files have the line

langcode: [languagecode]

You can change the language code in each yaml file and then import the full configuration back.

If you have translated text in the untranslated yaml files you can move this text to the translated yaml files in the language folder.

For a better workflow put the configuration in the sync folder (sites/default/files/config_HASH/sync) and import all in synchronize.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.