Problem/Motivation
The switching default language does not account for configuration translations, locale_modules_installed() and \Drupal\locale\LocaleConfigSubscriber.
Steps to reproduce
- Install Drupal standard in English
- Enable the locale module
- Add another language (for example German) on admin/config/regional/language
- Change the default language to the one you just added
Changing the default language will not make any changes to configuration. If you export at this point you will have a language/de folder in your configuration sync. If you export before step 4 and then export after you will only see that only system.site and language.negotiation need re-exporting.
If you then install a module (for example jsonapi) massive configuration change will occur. A language/en folder will be created. All default configuration will be changed to 'de' and translated.
Also, if you switch default language back to English, the configuration language for existing config never switches back, not even when you install more modules.
Proposed resolution
Fix up configuration after changing the default language. Say the old default language was 'en' and the new language default language is 'de' - we will need to start a batch that:
- Creates a language/en collection and moves the current english strings from the default collection there.
- Changes the langcode of all default collection configuration to 'de' - see locale_system_set_config_langcodes()
- Merges the translations that are in language/de to the default collection.
- Removes the language/de collection
Comments
Comment #2
tsotoodeh commentedThe same issue observed in 9.5.x, it is a core design issue, I opened a multilingual support issue:
Multilingual support of strings in second language website
I Tried using configuration update manager module to adjust langcode from default language to primary language, time consuming process! Although the content is translated but it would not shown correctly in second language. Same issue here!
Comment #3
jose reyero commentedComment #4
jose reyero commentedUpdated task description to account for the fact that when you switch default language back to English, nothing happens, existing config language is never updated.
I guess we need to make locale_config_batch_set_config_langcodes() behave the same for all languages and not to make an exception if default language is "en", or maybe keep track of the last language set for configuration, and whether the default langcode has been changed or not...
Comment #5
tsotoodeh commentedWell, as far as I can see the Drupal multilingual efforts has come a long way from the time that i18n or internationalization and localization modules was once were.
To be truly multilingual the configuration translation and interface translation should be taken a second thought.
As you said, the the language switch should be respected both in terms of configuration of the elements of the site and also the contents. An architectural plan should be devised for this task. Currently the configuration in consistency after switching the language from default language are many to account.
Comment #7
almador commentedI don't know if this is the right topic to share my issue, but it's also related to switching the original language.
What I did - while upgrading Drupal 8 to Drupal 9 by mistake I changed my default language from English to Spanish. When I realized this (after the upgrade) I switched my default language back to English from this page:
admin/config/regional/languageBut now, when I'm trying to edit any of my translations related things it still says "Español (original)".
Is there any way to switch every translation option back to English (original)?
Comment #8
gábor hojtsyMade the title more specific.
Comment #9
gábor hojtsyLooking at why this happens. When a module is installed after the default language is changed:
All in all I think the logic protects the existing language changes in active config if they were made prior to the default language change. So if you already have a Swedish site let's say, you switch to Finnish, the active config items that were previously Swedish will remain Swedish. Newly installed modules will get their config in Finnish in active config, so you end up with a mix of config items with Swedish and Finnish. But the integrity of your config is maintained.
If you built out a part of the website in English and then switch the default langcode, this indeed ends up doing more dramatic changes later because English is considered special. (When the default language is set back to English, I think the data protection logic does what it was supposed to do).
Now as to what happens when default language is changed, I'll post another comment, this is already quite long :D
Comment #10
gábor hojtsyDefault language change on the UI is implemented in LanguageListBuilder::submitForm(), and does this essentially:
Language module reacts on the config save of the default langcode in its ConfigSubscriber but that of course is not related to interface translation.
Finally locale has its own LocaleConfigSubscriber but that does not consider a default language code change as something to care about.
Comment #11
gábor hojtsyI'm a bit torn as to how to resolve this. For one, we want to make default language changing as easy as possible. The intent of the code is to consider config similar to content, where the existing language and overrides of configs is kept, except in the English special case that it assumes belongs to the default config that needs changing. There is no such logic for content entities either to swap their default language and translations when a site default language changes.
At the same time, users likely expect to edit configuration in the site's default language by default, which the current logic attempts to ensure, at least as long as that default is English and after the first transition from English to non-English. It does not maintain that user experience once you want to make the second language transition, whether back to English or to something else. It does leave your config intact but it does not maintain the assumed user experience. Also, if the first language transition happens later in the site's life, a massive config change happens then. That in itself is expected, but not when you install a new module :D So the problems are:
Comment #12
drupaldope commentedIt seems that someone has been changing some things in how languages work.
I am now unable to rename a certain language (D 10.2.4).
I wanted to name English en and German de.
The YML configuration is correct, but when the page is shown in the default original language German, it will just say "Deutsch" no matter what.
I guess the new code changes fail to retrieve and display the correct label.
Comment #13
drupaldope commentedActually I had it working correctly on a site where I did the following :
Installed the site in English
Added German
Added British English
Deleted English
works.
Comment #14
drupaldope commentedthere is actually more to this issue.
languages need a translatable label, which would resolve the present issue and a dozen more related issues I have found today when going down this rabbit hole.
BUT
languages also need editable labels that will be displayed in translations, verbose translations and abbreviated translations, URLs ...
So for example, a site could have installed British English and it would display the following way :
"en-gb" (non translatable) in any technical-related stuff such as hreflang, html, etc.
"British English" (translatable) in any configuration dialog in the admin interface, translation forms, etc.
"en" (translatable) as a label for language switcher links
and potentially, the site owner would want something else (translatable) to be displayed in the URL, such as /eng/ or /english/ or ... whatever
so the short ISO language code would be used by Drupal to identify the language and source translations, and would be untranslatable.
and then there should be 3 translatable labels on top.
Comment #15
drupaldope commentedI can now also confirm the workaround to correct this issue on running sites.
First, install an additional language.
Then change the language of all localized content to that new language you just installed.
That may be nodes, blocks, media, redirects and URLs, etc.
Then delete the language of which you can't change the name (be careful, this will delete all content you forgot to switch to the new language).
Purge the cache and then re-install the language you just deleted.
Edit the name of that language to what you wanted and then change the contents' language back to what it was.
So it seems like something screws up the language settings when installing the site or when declaring a language default.
Comment #16
drupaldope commentednever mind the workaround, one of the language labels reverted back to original after doing something else on the site.
Comment #17
claudiu.cristeaI don't know whether is related to this. I set the default language to other than English. Then I've exported the config (drush cex). Reinstalled the site from config but the English language is gone. Checked the config sync directory, I can see thelanguage.entity.en.ymlfile. Checked the{config}table, nolanguage.entity.enat all. It just vanished.EDIT: Ignore this comment. I just discovered that I need to set
keep_english: truein the installed profile. Maybe this deserves to be better documented, even by showing a warning message to the site builder when they are changing the default language?EDIT2: I have created #3545306: Show a warning when default language is switched from English for this issue
Comment #18
anybodyNice, just found this and I think it's very similar to this one: #3568743: Convert / unify all default configs to the site default language (which has a possible solution).
For the future I'd vote to always store the default config in English by design, so we can't have such cases any more and treat any other language as translations in their respective collection / folder!
That will also simplify importing (typically English) config from modules etc...