The core language switcher lists all enabled languages even when viewing a node that is not translated to those languages.
The behaviour I would expect is to hide all the languages that specific node isn't translated to, or make it an option from the language switcher block settings.
For the moment, in case anybody stomps on the same behavior and isn't happy with it, a workaround could be implementing something like this in a theme:
function THEMENAME_preprocess_links__language_block(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if(!$node) {
return;
}
foreach(array_keys($variables['links']) as $lang) {
if(!$node->hasTranslation($lang)) {
unset($variables['links'][$lang]);
}
}
}
Comments
Comment #2
entuland CreditAttribution: entuland commentedComment #3
penyaskitoHi @entuland, thanks for reporting!
Adding some issue tags, adjusting priority (most issues are normal, see https://www.drupal.org/core/issue-priority), adjusting version (features go against last version; probably this should even be 8.4.x-dev, but I'm not sure)
Comment #7
esolitosComment #8
leymannxMinor description change, switched double quotes with single quotes for consistent quotes.
Comment #9
esolitosFor those in need of a solution, look at this module: https://www.drupal.org/project/language_switcher_extended
Comment #15
farse CreditAttribution: farse at Zoocha commentedThanks, this snippet is just what I was looking for.
Comment #16
Ruuds CreditAttribution: Ruuds at Groowup Digital Agency commentedI solved this using the hook_language_switch_links_alter hook, which checks if the entity has a translation, if the user has access and if not, changes the link to the language's page.
Comment #19
kevinvanhove CreditAttribution: kevinvanhove commented@Ruuds, this fixes it for nodes, not for views...
Comment #20
AnybodyAs of my comment here: https://www.drupal.org/forum/support/translations/2016-08-28/language-sw...
I think core needs settings to let the admin decide how to handle untranslated nodes. It should combine the fixed from the listed modules, which are acting as workaround currently, but that should be done in core as combined setting in one single place:
All solve different things for the same need: Define behavior for untranslated nodes.
Comment #21
l-laziz CreditAttribution: l-laziz commentedaccidental comment.
Comment #22
l-laziz CreditAttribution: l-laziz as a volunteer commentedComment #23
l-laziz CreditAttribution: l-laziz as a volunteer commentedComment #24
l-laziz CreditAttribution: l-laziz as a volunteer commented