Language Switcher: Remove the language code for the default language#5109
Language Switcher: Remove the language code for the default language#5109smanzi wants to merge 11 commits intojoomla:stagingfrom
Conversation
…renderModal
An optional argument is added to JHtmlBootstrap::renderModal that allows
to select if the close button ("x") should be displayed or not.
The functionality of the "backdrop" parameter in JHtmlBootstrap::modal
is extended to allow displaying a 'static' (no close on click) backdrop.
…tstrap::renderModal" This reverts commit 8eb2da5.
|
Sorry: there are some "spurious" commits above this one as I did some mistake in my local repo, but it seems to me that, having reverted the spurious ones, everything should be OK here. Is there a way to get rid of that garbage I involuntary created? Thanks to whomever will help... |
How to test:Have a multilingual site, with at least two languages and two menu hierarchies, one for each language. At least some of the different languages menu items have to be associated. First try with "Remove URL Language Code" option switched off. Navigate throughout the site and inspect the links generated by the language switcher. Change language back and forth. Now do the same with the "Remove URL Language Code" option switched on. What will go wrong:Once in the home page (and probably in every page whose alias is the same for the two languages) and you switch out of the default language, you'll be caught in: no way to go back to the default language! WTF, why do you publish a buggy PR??IMHO it is not my PR that is buggy, but something else (I'm putting my bet on the router...). Want a demonstration? Turn off this PR and do the same: navigate out off the default language (e.g. English) home page (http://example.com) and into the corresponding one in a different language (e.g Italian, http://example.com/it/). Now try to navigate back to the English page by typing its canonical address (http://example.com) in the address bar of your browser: no way! You are caught in! But the original language switcher does work...Yes, because it always add the language code, even when you have said no to that in the language filter and this allows you to go back. This is, IMHO, a kludge Oh, well, and is this a problem?Yes, because spiders find also the bogus URL for the default language and index them as well. Result: duplicated content in Google, which is a bad-bad thing. This is exacerbated by the fact that redirects to the canonical URL are done with a 303 status code and not a 301 Is there more?Yes, when switching back from another language to the default language, we always get at least a redirect (and I swear I have seen cases with two redirects!). This does not happen when switching from the default to another language. The server is hit at least twice and (for small pages) it takes twice the time to load. Beware: don't think only at users interacting with your site: think at the spiders as well... |
|
This does not work when switching to the default language home page because a cookie is set. |
|
how about if the home page is assosiated? |
|
Association will not change anyhting. It is done looking at the lang prefix (and its associated lang_code). |
|
@infograf768 have you actually read my comment, and particularly the "What will go wrong:" paragraph? I know that "This does not work when switching to the default language home page because a cookie is set" (actually, in the "How to test" section, I forgot to mention that you must clear your cookies before switching from a test to another...) The question now is: why do we need a bloody language cookie? An URI is an URI and should always bring to a specific resource independently of any set cookie. I suspect (but I'm not sure) spiders do not accept cookies. This can bring to the situation where the site structure as perceived by a spider differs from the structure as perceived by a human being. This is bad for SEO. I don't know exactly why we need that cookie: the code is complicated enough that I'm unable to understand it, but my feeling is that the cookie is needed for when we also have the Language Selection for new Visitors option set to Browser Settings. Am I on the right way? |
|
The cookie is also used so that if a visitor sets a specific language they On 15 November 2014 15:38, Sergio Manzi (smz) notifications@github.com
Brian Teeman |
|
Fair enough, Brian: that kind of usage is acceptable, but this (if I'm not mistaken) is needed only if we have resources (URI) that responds differently depending on the set language. Is that correct? |
|
What I mean is: if we had an option saying "Remove language code from every language, be it the default one or any other", then we surely need a cookie to differentiate. But (happily enough) we don't have that. The edge case is only the home page, I guess. |
|
Think of this:
Guys, this is sick! |
|
My 2c here: I agree with Sergio, that the only point of truth should ALWAYS be the url. Now about the preselected (or prefered if you like) language there should be some check (onAfterInitialize I guess) for the cookie and redirect accordingly. Only thing that needs to be mandatory, otherwise this won’t work, is to stet up properly the associations. |
|
Can somebody please tell me where the cookie is set and where is it tested? I would like to give a look at the code... |
|
I also agree with @smanzi. There is no actual need for language cookie, the url should be the answer. @smanzi about the problem you have with same alias. How is it possible to have the same alias for associated items? Joomla doesn't allow me to create same alias, and for example in the Greek site i use /app/ and in English /apps/. ABOUT SEO: I am not sure if this bug is related to this one. But google has index about 8 times, article urls with wrong language code. So it gave me at Webmaster Tools a 404 Error for this urls. |
|
@ManuxGR wait... which "same alias"? In my example I used different aliases... |
|
My Bad, sorry, was confused by categories. |
|
@ManuxGR Ah, yes, that's correct, although I would say it would be nice |
|
@ManuxGR this is OT, but anyway... your problem (and probably many others) can be solved by creating two top level categories ("en" and "gr") and then have every category for a particular language created as a sub-category of the "language category" and associated to the corresponding language. Maybe if we treat language associations just as "above-the-top-level" categories we can solve a lot of issues... |
|
You know? "Maybe if we treat language associations just as "above-the-top-level" categories we can solve a lot of issues..." The more I think to this the more I feel I've just had a damn good bright idea. Myabe not for 3.4, but... Prove me wrong and I'll eat quite a lot of "Humble pie"... |
|
Ah, to be clear, in the above when I talk about association I mean the association of an item to a particular language or "All" languages. I don't mean the association between two different items belonging to different languages. |
|
In this case the "All" language should be seen just as another language, with the restriction that its aliases cannot appear in any other language (otherwise we will have a routing nightmare...) |
|
If you look at the multilingual does that @infograf768 woe you will see
|
|
See #5110 (comment) |
This is wrong! We have solved that kind of issue for ages. Whether you enter in the same browser window "http://example.com/test-page" or use the link from the other site in the same browser, you will get to "http://example.com/test-page" |
|
Folks, we "could" implement my code ( #4911 (comment) , and NOT #5110 which is wrong) to get rid of the cookie when set such in the plugin. Then if this condition is set, sef on, url language code off for the site default language, this PR here to the switcher implemented adding the new conditional for the cookie, a user will always be redirected to the default site language OR the Browser language (depending on the parameter for new visitors) when going to the bare url Most of the time this is NOT the desired purpose of a multilanguage site. Thus the reason of the lang cookie. Therefore, once again, the matter is a decision for 301 or 303 for most joomla multilingual users |
This was breaking everything! I can't understand what was wrong with this test, but after all it should be useless: according to what I've read around if we get an object from JPluginHelper::getPlugin(), that means that the plugin is enabled.
Apparently you are totally correct... I'm puzzled... I swear I've seen this behavior while testing... I don't know what to say... sorry! 😕 I just pushed a new commit because the test I introduced to check if the language_filter plugin was enabled was always returning I'm now going to test this PR with #4911. Should I incorporate your proposed diff #4911 (comment), or use it "as it is"? |
|
TBH, I think this is not the right solution. |
|
So far this PR seems to work nicely with #4911 Now, for this PR: How to test (amended):
|
Can you elaborate the reasons why? The only problem I see is that if the "Remove URL Language Code" option is switched on, then the Cookie Lifetime" in the "Language Filter" must be set (or forced to) "none" |
|
Concerning this PR.
|
|
Ah, OK, I see! Point 1: Do you want to transform your proposed code in a PR so we can test it? Do you want me to include it into this one? Point 2: As I said above, yes, you're right. I've also doubt about the possibility of setting the cookie lifetime to none without setting the "Remove URL Language Code" option. Will it work? Do you have an advice for me about the testing of the language_filter plugin being enabled? (see my comment above, just after the last commit) Thanks! Sergio |
|
I was thinking of this too: |
|
PR for no cookie is here: |
|
@infograf768 Thanks! 👍 |
if (JLanguageMultilang::isEnabled()) is already used line 99 |
|
OK! I'll move the removal of the default language code inside that |
also moved the removal of the default language code to a better place
|
@infograf768 It seems to be alright... 😉 |
|
@infograf768
|
|
Wait... there are issues... 😞 |
|
@infograf768 I've seen that the "language" cookie is set only in languagefilter.php and never if lang_cookie == 2, so... I really don't understand! I've spent hours looking at languagefilter.php but I can't figure out what's wrong with it... 😭 |
|
... and the issue is present also if I revert this PR, apply #5126 only, login with non default language user and then type in the browser address bar or access via bookmark an URL without the default language code |
|
I have proposed here a PR which implements the 301 when all conditions are met. |
OK, but:
I've asked on a Google SEO group about the situation (not citing J!...). I'll let you know if I get any answer... |
|
I've think it over again (a good shower does magic in cases like this! 😄) and came to the conclusion that this PR is just a kludge and thus I'm retracting it. Probably the right place where to fix this all is where the route is built and parsed and not trying to fake anything in something else. Unhappily this is something that at this time goes beyond my capabilities. Partially unrelated, but I still think that having the possibility of not storing the 'language' cookie is an option we should offer. Sorry to everybody if I wasted your time, but after all I think something good can come out of this (I mean discussing this, not the PR which is a real kludge!) |
This will remove the language code for the default language when needed, i.e. when using sef URLs and when the "Remove URL Language Code" option is set in the language filter