New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translated Nodes do not switch languages properly when set as the home page. #4785
Comments
Well, I'm not sure what fixed it but my site seems to be switching languages properly now. (I know edited the both translations of the content and both menu entries. Not sure what else...) |
Related: I'm not sure what has changed recently, but I've been often testing PRs with RTL languages by doing the following:
This doesn't seem to work as before anymore ("before" being 2-3 bug releases back maybe?), in that I now have to specifically add the language code in the URL to have things switch to RTL. |
...scratch all the above; I just tested again and it seems that we've fixed that in the latest 1.x. Everything works as expected again 👍 |
I wonder if something recently caused an extra cache-clear to be necessary, when it wasn't before? (Maybe entity cache? No, that wouldn't make sense, these are different entities...) |
Well, everything stopped working as expected again on my site. Re-opening with new STR (in OP). |
@jenlampton A quick question: I suppose you do have the Redirect module turned on? Did you change the title (and/or alias) of the node between the time it seemed to work and the time it stopped working? Anyway, I can confirm that the language switcher does not switch the node translation if the node is set to be the front page. |
I'm not sure where I need to fix this problem in core, but I've added a work-around to my site as follows: /**
* Implements hook_url_inbound_alter().
*/
function HOOK_url_inbound_alter(&$path, $original_path, $path_language) {
if (backdrop_is_front_page()) {
global $language;
if ($language->langcode != $path_language) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
$translations = translation_node_get_translations($node->tnid);
if (!empty($translations[$language->langcode])) {
$path = 'node/' . $translations[$language->langcode]->nid;
}
}
}
}
} |
I'm also clueless. 🤷 Maybe something in translation_language_switch_links_alter fails? Or the config item "site_frontpage" overrides it again at a later point? |
I suspect it is actually something in how it determines what to load for the home page. When my site is on "/es" it always loads the English version of the home page instead of the Spanish, because that is what's set in What it needs to do is retrieve I spent some time poking around in |
Seems plausible. Then it's rather a bug in the translation module, which fails to load the proper nid for the current tnid? This is also broken in Drupal 7, BTW. Fancy that I never realized that. |
Hey, @jenlampton, you know what... your "workaround" implemented as Mind to create a PR from it? Or are there any concerns? |
I've created a PR. My only concern was if adding a |
Posting mostly to sort out in my head: the process goes roughly bootstrap loads the saved front page from config to See:
Somehow I dont see where the translation system gets involved here at all. So |
This is how I tested:
Works like a charm. @docwilmot did you miss that there's already a PR? |
@jenlampton mind to add "Fixes" to your PR comment? It's much easier to find if the link, if it appears here in the sticky header. 😉 |
No, the line about "So hook_url_inbound_alter() is actually called in backdrop_get_normal_path(); so maybe ..." is with reference to that PR. We usually try to directly fix the origin of the process, rather than calling alters. Ideally altering should be for contrib, or if other modules are accessing a core API, I think. |
IMO it has to be fixed in the translation module, translations are only available, when it's enabled. I don't think that menu_get_object() is the right place - why should it deal with |
I was considering avoiding the node load. |
I see. But I don't think it does any harm. |
Description of the bug
Translated Nodes do not switch languages properly when they are set as the front page.
If I create an English about page, then translate into Spanish, I can click the "English" link to see the English version, or the "Spanish" link to see the Spanish version -- no problem.
However, if I then navigate to
admin/config/system/site-information
and set my Default home page to beabout
that breaks the language switching.Now when I go to the about page (used for home) and click the "Spanish" link to see the Spanish version of the page, the page remains in English. The only way I can view the Spanish version of the page is to navigate directly to the Spanish node.
Steps To Reproduce
admin/config/system/site-information
and set the Default home page to beabout
Actual behavior
Front page remains in primary language, regardless of which language was selected.
Expected behavior
Front page should show in selected language.
The text was updated successfully, but these errors were encountered: