Drupal supports the concept of Interface Language and Content Language. I (and every client I have ever asked) seem to have a different opinion of what is "content" and what is "interface" than Drupal does (in most cases). I consider Interface as the items an administrator or editor would use to do their job (admin menu, edit tab, help details on forms, etc) and Content is what non-admins (often this is Anon but not always) would see.
A view that I create to present "content" on the site, I naturally think of as content - but Drupal has an inconsistent and often incorrect idea of what this is.
To start with, I have the site set up so that Interface language is defined by the User's preferred language (as a site admin/editor would set) and Content language is defined by the URL langcode prefix.
An example test view looks like this in FR (url is /fr/test) - Interface language is set to EN:
This is clearly incorrect as can be seen with the proper display when I set the Interface language to FR:
Views has numerous options to set how "content" render language is determined. For my example above it is set to render based on the page's "content language" (and therefore the url). This works for most field data (title, taxonomy terms, translated text fields); but sadly does not work for Datetime fields - they seem to be hard coded to incorrectly translate using Interface. But you can also see the config portions of the view (view title, field labels, etc) are also translated as Interface.
Is there any way to tell a view to translate using the content language?
I have used the following code:
$languageManager = \Drupal::languageManager(); $langcode = $languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); $language = $languageManager->getLanguage($langcode); $languageManager->setConfigOverrideLanguage($language);
within a block preprocess function to allow some of the block pieces which are incorrectly using Interface language to translate with the content language. Is there some similar way to override the interface language that a view uses for translation? I am hoping it is something like the code above but that I am simply not inserting in the right place (I have unsuccessfully tried hooks for pre-build, pre-render, query_alter).
If this is possible to do, I would love to write up a contrib module to use the existing ui in a View to set the render language and have it render everything rather than just certain fields.