Importing or reverting a view from configurtion deletes interface translations

Created on 15 February 2018, almost 7 years ago
Updated 17 November 2024, 2 months ago

At the moment I'm not sure if this is a bug, something I'm doing wrong, assumptions I'm making that are wrong, or anything else.
So I'm posting it as support so we can figure out what this behaviour is.

Problem/Motivation

The problem is that an interface translation that was added for a string coming from a custom module was reverted (deleted) after importing an untranslated views configuration that had the same string as a translatable label in it.

To reproduce the issue:
1/ Install Drupal and make sure you have enabled views and file modules and setup at least 2 languages. (this is very specific for this example, but in theory any view would have this issue)
The view "views.view.files" (/admin/content/files) needs to exist and not be translated.
2/ Export your configuration (in my case this is always done so we can deploy the configuration to other environments and/or developer)
3/ Create a custom module that includes "anything" that outputs a translatable string "Name". In my case I had a custom form with the below element in it:

    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Name'),
      '#required' => TRUE,
    ];

4/ Visit the page that shows the custom form from step 3 in another language so the "Name" label becomes translatable.
5/ Go to the interface translation administration screen, search for "Name" and translate it to another language.
6/ Visit the page that shows the custom form from step 3 in another language and verify that "Name" is indeed translated. (it will be :))
7/ Import the config exported in step 2. (this simulates a deploy to another environment) This config import will indicate that "views.view.files" needs to be reverted, although no changes were made to it. Accept this and continue.
8/ Do 6/ again and you will see that the translation for "Name" is lost.

The above example is very specific to the view "views.view.files" and the translatable label "Name". But the same principle will apply to any label in any view that is also used elsewhere.

I know that the config import warns about the change, but this is really confusing since no changes were made to the view and the translation that was added is (at least to me) totally unrelated.

I fixed my problem by adding a context to my custom "Name" label in the form.

    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Name', [], [ 'context' => 'my_module' ]),
      '#required' => TRUE,
    ];

But this feels really wrong to me... That would mean that any custom module (even contrib) that wants to translate anything should always add a context to prevent views module from interfering if you import config.

Proposed resolution

We need to clarify first if this is me doing something wrong or not. This is just a support request for now ;)

To the best of my knowledge, translations of view labels should never go through the interface translation, but only live in configuration. (just like field labels for example)

Remaining tasks

Figure out if this is bug, needs documentation, ...

💬 Support request
Status

Closed: works as designed

Version

11.0 🔥

Component

views.module

Created by

🇧🇪Belgium weseze

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    Since this has steps to reproduce I used them today on a fresh install of Drupal 11.x. I was able to reproduce this but I also think this is working as designed. The comment that "views.view.files" needs to be reverted, although no changes were made to it", is incorrect. The view has been changed because the translation is stored in the config for the second language version of the config. Therefor, I am closing this as working as designed.

  • 🇧🇪Belgium weseze

    Sorry for not getting back on this issue.

    It is caused by core adding some lines to config files imported during install of core and modules.

    It adds: (hash will vary offcourse)

    _core:
      default_config_hash: xpDeWNLzjX4dDB9YyBlO9y9FR4vHwMv0GKsuqDYy0Bc
    

    This in turn causes translatable labels from the config to go through interface translation rather then translated config files.
    There is a valid use case for this scenario, but for me it is an extremely annoying and useless system...

    Anyway, simple deleting those 2 lines in all config files fixes all of my issues.

Production build 0.71.5 2024