Skip to content

Routing/Language: Refactoring the language system to simplify the code#5140

Closed
Hackwar wants to merge 56 commits intojoomla:stagingfrom
Hackwar:languagerefactor
Closed

Routing/Language: Refactoring the language system to simplify the code#5140
Hackwar wants to merge 56 commits intojoomla:stagingfrom
Hackwar:languagerefactor

Conversation

@Hackwar
Copy link
Copy Markdown
Member

@Hackwar Hackwar commented Nov 19, 2014

The code for the current multi-language system is unnecessarily complex. This PR tries to improve on #5135 and simplify the code further.

Goal

This PR tries to achieve 4 goals:

  1. Remove a few inconsistencies in the code that may have resulted in hard-to-find bugs.
  2. Improve performance by moving the language-URL-behavior from several different *HelperRoute classes into the single plugin.
  3. Allow the routing code to work with the language data where necessary in order to simplify the code there, too.
  4. Allow for correct URLs and moving between languages where this is expected.

Especially the last part should be discussed in this PR. The new code does not force you to always use one specific language, but allows you to switch between them. The behavior should be the following:

  • If a user accesses a site for the first time, the plugin looks up if it should simply direct to the default language or try to discover the right language via the browser.
  • The language of the page is always determined by the URL.
  • On each pageload, a cookie is set with the current language. If a page has no attached language information, the data from the cookie is taken, otherwise the URL overrides that cookie.

This means that a user that surfs a french website and then clicks on a link to a specific english page on the site, the user is not redirected to a french page with the english content inside or an error page or similar.

How to test

Simply apply the changes included in here and see that the URLs stay the same and the behavior for language handling is the way you expect it.

Routing changes

The above mentioned routing changes are primarily aimed at easing the code in other parts of Joomla. Currently, a URL is first created via a *HelperRoute class, which replaces the ISO language code from the content item with the corresponding SEF code. The language plugin, which right now is run before every other code in the routing process, takes that SEF code, compares it to the existing SEF codes, looks up the right language for it and then takes the SEF code from that language and adds it as part of the path in the URL. After that, it deletes the language code from the query, so that it is not available to the rest of the routing process anymore. Since the language is an important part of looking up the right Itemid, this means that the lookup of that part has to stay in the *HelperRoute class, instead of moving it to the component router itself.

Notice

I changed the above description massively on January 3rd, 2015 in order to make it better understandable. Between opening the PR with the first description and this updated description, the code was again extensively changed and thus the comments before #5140 (comment) are not valid anymore.

@infograf768
Copy link
Copy Markdown
Member

SEF on: Switcher broken => Switching to another home page impossible

As I have merged #5135, this will anyway need update

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Nov 20, 2014

Its updated. I will have a look at the rest later.

@infograf768
Copy link
Copy Markdown
Member

Anyway, this would not be B/C at all. Also we would have other places in code where the prefix is used and not the language tag. Not for this series imho.

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Nov 21, 2014

Right now, it depends on your definition of BC. Because it still parses the old URLs and it also still processes the old URLs, since there are to many extensions out there, that are using the current Joomla style of generating these URLs. If you can live with the change for the current non-SEF URLs, then this is still BC.

@infograf768
Copy link
Copy Markdown
Member

As long as we propose in Global Configuration SEF as an option, this would not be B/C.

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Nov 21, 2014

As I said earlier: The old URLs still work. We would only be introducing new URLs for the future.

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Dec 1, 2014

If existing URLs and features continue to work as they are today, there's no need for a config option IMO.

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Dec 1, 2014

With these latest changes, this would be B/C. These changes require #5264 to be applied, too.

Besides these changes, I just wanted to make you aware of it that we are not using the language parameter of any article in our system right now in the routing... Actually, I searched the whole system and out of 35 files, we are only using the language parameter in 3 of those and there are maybe 10 files where we are not even using the category ID, thus making the resulting URL complete garbage. Will write a PR for that...

@infograf768
Copy link
Copy Markdown
Member

Test: not good here
I first applied #5264

SEF on:
Switching between homes does not work (When url lang code is set to off for default site lang)
Switching between associations => 404
SEF off:
we don't even get the site url:
http://localhost:8888/?lang=en-GB

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Dec 2, 2014

Please check this again. I invested several hours into this now to work mostly through it and this should be good now. I would call this merge-ready right now. Again, as I wrote earlier, this requires #5264 to work.

@weeblr-dev Please have a look over this, too. Would this still work properly with your system?

@zero-24
Copy link
Copy Markdown
Contributor

zero-24 commented Feb 9, 2015

@zero-24 Please do CS stuff afterwards. As long as Travis is okay with the current code, I'd rather not change it again and enforce another round of tests just because of that.

ok. I will add a PR after the merge here.

Regarding the search bug: Fixed it.

Thanks looks fixed with: Hackwar@b8127ed

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Feb 9, 2015

Regarding the bug: Again the old implementation gets us here. In the old implementation, the first part of the URL was always parsed as a language and in the actual parsing routine, nothing could majorly be broken. Now however, I was first checking if we were called via a POST request. If that is the case, the rest would not be checked. But a POST URL also contains a SEF part and thus we first need to discover that part and then check if we are called via POST.

Please note that the last commit is really simply just a codestyle commit and does not require new tests.

Now that we have 2 tests by @richard67 and @zero-24, could this be set to RTC? 😉

@richard67
Copy link
Copy Markdown
Member

Hmm, from my point of view it is not only code style to remove this unused if, it is a refactoring. I trust you, but I know by experience from myself that errors can happen even with simple things. So I will retest anyway and let you know the result.
Regarding RTC: I also want to have this into 3.4, but as we have seen it is such a interdependent thing and - even after your large cleanup, millions of thanks for this - still some kind of complex, so I would feel safer if @infograf768 had a successful test, too. Just my opinion.

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Feb 9, 2015

@richard67 The code was the following:

$found = false;
if (!$found) {
//do stuff
}

That if will always execute, come hail or storm, so it was simply a useless line of code. 😉

@richard67
Copy link
Copy Markdown
Member

@Hackwar Yes, I just have checked it with Beyond Compare, which is a bit more useful than the stupid GitHub diff, and it looks safe.

@richard67
Copy link
Copy Markdown
Member

@Hackwar You know the code change above was clear to me also by the GitHub diff, but it was not so obvious if not accidently anything else had been changed within the if beside indention, e.g. because you have hit the del key with your head when falling asleep after this much work in this PR ;-) Maybe call me paranoid ;-)


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5140.

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Feb 9, 2015

No problem.

@Gitjk
Copy link
Copy Markdown

Gitjk commented Feb 9, 2015

@test successful - on my bilingual site everything still works after the latest change. Didn't detect any issue when switching languages with SEF enabled/disabled.

@bembelimen
Copy link
Copy Markdown
Contributor

@test tested it on a site with three different languages. Couldn't find any issues while looking around and testing the language stuff. Looks good to me.

@infograf768
Copy link
Copy Markdown
Member

@test

looks fine now here with my usual tests.

@zero-24
Copy link
Copy Markdown
Contributor

zero-24 commented Feb 12, 2015

Based on several testing i think we can move it to RTC now. Thanks to all for the hard work on this!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5140.

@infograf768 infograf768 added this to the Joomla! 3.4.0 milestone Feb 17, 2015
@infograf768 infograf768 added the RTC This Pull Request is Ready To Commit label Feb 17, 2015
@infograf768
Copy link
Copy Markdown
Member

Thanks. Merged with a9c7eb2

@Hackwar
Copy link
Copy Markdown
Member Author

Hackwar commented Feb 17, 2015

Thank you

infograf768 added a commit to infograf768/joomla-cms that referenced this pull request Jun 12, 2015
Bakual pushed a commit that referenced this pull request Jun 14, 2015
Regression: remaining code from #5140 breaks multilanguage
johanjanssens pushed a commit to joomlatools/joomla-fork that referenced this pull request Jun 19, 2015
@zero-24 zero-24 removed the RTC This Pull Request is Ready To Commit label Oct 14, 2015
@Hackwar Hackwar deleted the languagerefactor branch April 27, 2019 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.