Force language switch

108 views
Skip to first unread message

Samuel Mehrbrodt

unread,
Feb 12, 2015, 11:42:12 AM2/12/15
to joomla-de...@googlegroups.com
Is there a way to force a certain language via PHP code?
I have a template and I want all menu items where this template is assigned to use English content.

So I'm looking for something like this (I would place this in my template's index.php):

$config =& JFactory::getConfig();
$config->setLanguage('en');

Does anyone know a way to achieve this?

Samuel

Hannes Papenberg

unread,
Feb 12, 2015, 12:09:12 PM2/12/15
to joomla-de...@googlegroups.com
Set the language of those menu items to english.

Hannes
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to joomla-dev-gene...@googlegroups.com
> <mailto:joomla-dev-gene...@googlegroups.com>.
> To post to this group, send email to
> joomla-de...@googlegroups.com
> <mailto:joomla-de...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/joomla-dev-general.
> For more options, visit https://groups.google.com/d/optout.

Samuel Mehrbrodt

unread,
Feb 13, 2015, 12:24:15 PM2/13/15
to joomla-de...@googlegroups.com
Well I have some reasons why I can't use the language switcher plugin.
I have multiple sites with Virtual Domains and when I activate the
language switcher plugin, it breaks my links.

Maybe this is better with the router fixes in 3.4, but currently I am on
2.5.

So I still need some hack or something to change the language in a
template without using default Joomla methods.

Hannes Papenberg

unread,
Feb 16, 2015, 11:53:01 AM2/16/15
to joomla-de...@googlegroups.com
I don't have to tell you that 2.5 is not so good. There are also not
many router changes in 3.4. However, there are several changes here
https://github.com/joomla/joomla-cms/pull/5140 that should allow you to
use the languagefilter plugin from Joomla with your multi-domain site.
You can simply move your multi-domain plugin before the languagefilter
plugin.

If that still does not work for you, take a look at the end of the
parse() method in that PR how I change the language there. That is the
only way that that is possible. However, if you do that in the template,
you will fail. You have to do that VERY early in the process, either in
onAfterInitialise or onAfterRoute or during routing with a routing rule
like the language filter plugin. Otherwise all language strings in
plugins and the component will already be loaded and translated in the
wrong language and they will be lost after the new language has been
created.

JLanguage::setLanguage() does not work.

Hannes

Samuel Mehrbrodt

unread,
Jun 10, 2015, 2:48:11 AM6/10/15
to joomla-de...@googlegroups.com, hack...@googlemail.com
Am 16.02.2015 um 17:52 schrieb Hannes Papenberg:
> I don't have to tell you that 2.5 is not so good. There are also not
> many router changes in 3.4. However, there are several changes here
> https://github.com/joomla/joomla-cms/pull/5140 that should allow you to
> use the languagefilter plugin from Joomla with your multi-domain site.
> You can simply move your multi-domain plugin before the languagefilter
> plugin.
Thanks!
I (finally) had the time to do the upgrade to 3.4 and it seems your work
on the router indeed fixed a few bugs - I was able to use the
languagefilter plugin with my multi-domain site.
I had to set the access level of the languagefilter plugin to be used
only on my English site. If I didn't do that, I got endless redirects on
one of my other sites.

However, my contribution to your campaign has already paid off - many
thanks for your work! Hope you will be able to fully complete it.

Samuel
Reply all
Reply to author
Forward
0 new messages