简体   繁体   中英

Joomla language switcher override

I'm trying to force the language swither module not to redirect to the home page if there is no menu item associations in Joomla 2.5. I would just like to change country code in the current URL.

So that 'my-domain.com/ en /menu?view=cat&id=1' translate to: 'my-domain.com/ de /menu?view=cat&id=1' and so on ...

I guess I should modify modLanguagesHelper class but do not know how to create a required $language->link to work properly through JRoute.

Any help is appreciated!

Joomla usually does that by default. It seems strange that it doesn't with the approach you have followed.

Although, reading the comments you left, I understand it's not an easy task and you have already built quite a big part of the website, to go back to structure.

If I were you, I would write a small custom module to change the lang=xx or /xx/ in the URL, and redirect the user to the language they want. If you need help on that, feel free to comment below.

As per your question, I would personally go with simple string manipulation. Since you are really familiar with PHP (taking into consideration that you have written your own custom component), it should be a piece of cake for you, to:

  • Get the current URL
  • Get the current language tag
  • Replace the instances of lang=en with lang=de (example languages, you get the point)
  • Replace the instances of yoursite.com/en/ with yoursite.com/de/
  • Print the custom links, flags or whatever you are going to use.

It's not the suggested scenario, but you can really make a usable module if you also add:

  • An option for the administrator to write the language codes to use (to allow for later additions)

And make sure that you get the site name dynamically, and then you may also have a module that could be published in the JED to help others in the same situation like you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM