Problem/Motivation

There is sometimes a need to override a configuration based on interface language. Good examples are homepage, 403, 404 pages. Even though pages typically should use entity translation, some limitations like Paragraphs not being translatable force alternative node pages per language.

There is an issue for core (#2275865: Per language settings (vs translated settings) are not directly supported) but discussions mention this could be solved in contrib, even if it probably should go in core at some point, there is some need to have it in contrib as there is some demand.

Proposed resolution

I propose to implement language overrides using Config Override module, essentially we can mimic the structure of config_translation in core but no UI.

Example of usage:
Include language_override config key in settings.php

$config_directories['language_override'] = '../config_override/language';

Place an override file in 'language_override' folder following core's config_translation structure:
[language_override]/en/system.site.yml

page:
  front: /node/123

Remaining tasks

Add tests

User interface changes

None

API changes

New way to override configs, no changes to exiting APIs

Data model changes

None

CommentFileSizeAuthor
#3 2914987-3.patch4.35 KBasgorobets
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

asgorobets created an issue. See original summary.

asgorobets’s picture

Issue summary: View changes
asgorobets’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new4.35 KB

Providing an initial patch and added example of usage.

dawehner’s picture

Nice feature! It would be indeed really cool to have some test coverage for it as well.

marjina-constantin’s picture

Used "Config overrride" module and patch from #3 on a production site to override some configs based on language + based on environment. Saved me a lot of time. Great work, thanks @asgorobets!

dawehner’s picture

@asgorobets Is there any way I can help you with adding a test coverage?

asgorobets’s picture

Assigned: Unassigned » asgorobets

Thanks @dawehner, I will work on tests for it, will let you know if I need any help

sic’s picture

i have trouble getting this to work. i want to define another front node id for a specific language so in /sites i added the "config_override" folder, in it the "language" folder, and in it the language-code named folder ("de") for instance. and in it is the yml file from your example.

in /sites/default/settings.php i added the path from your example as well, no luck. any tipps?

lamp5’s picture

I have got similar problem. When use this module with site prefix. All works properly! But now i using domains and for example if i override lang "de" to node/654 and in the rest of sites I using node/123 like a front page, override only works when i go to node/654 "de" and change language. Now i am on node/123 "en", but when i now change language to "de", a am on node/123 "de" instead node/654. I had a problem with domains and use this patch https://www.drupal.org/project/drupal/issues/2643466

jas1988’s picture

Is this patch still valid ie: allow language overrides, With Drupal 8.9.1 it gives below error :

Service 'config_override.override_language' for consumer 'config.factory' does not implement Drupal\Core\Config\ConfigFactoryOverrideInterface

But editing config file directly is working fine : https://www.drupal.org/project/drupal/issues/3097497

tetem’s picture

Hello,

I had some issue when I try to override config usig "Config Override Module"

The reason why is not working for me because I set my class AdamConfigOverrides outside the "src" folder

before : to /modules/custom/my_module/AdamConfigOverrides.php=> KO

error:

 Service 'my_module_name.config_overrider' for consumer 'config.factory' does not implement Drupal\Core\Config\ConfigFa
  ctoryOverrideInterface.

after /modules/custom/my_module/src/AdamConfigOverrides.php => OK
It worked for me

markie made their first commit to this issue’s fork.

markie’s picture

Started this MR because #5 uses deprecated code which was removed in D9.

jascote’s picture

A couple notes that may be helpful for others...

The most recent PR in #14 alters the location of the language override directories from what is stated in the issue description. Instead of placing your files in [language_override]/en/system.site.yml you need to place them inside the config directory you have set in $settings['config_sync_directory']

This seems to be a result of https://www.drupal.org/node/3018145 and is related to this issue https://www.drupal.org/project/config_override/issues/3243107

Despite making these changes this patch doesn't seem to work. Running drush cim appears to create the new configs but the changes are not reflected on the site.

In my case my config directory is this:
$settings['config_sync_directory'] = '../config/sync';

My translation override files are here:
config/sync/en-ca/system.site.yml

With the file contents of

page:
  front: /node/11

Yet after running config import the global homepage node is still used.

dpagini’s picture

Status: Needs review » Needs work

Given the above comments, I think the "Needs work" tag is most appropriate here. I also don't have a lot of multi-lingual experience in Drupal, so tests would really be helpful to see this issue get more traction.