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, ...