Changing Site Language "on-the-fly"

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
bfalcao
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 19, 2006 11:41 pm

Changing Site Language "on-the-fly"

Post by bfalcao » Tue Jan 15, 2008 12:30 am

Hi mates,

I am developing a new 1.5RC4 site and I have two "flag" buttons on the main page so the user can change "on-the-fly" the site language. On my situation between Portuguese and English.

What parameters should I transform on the index.php (template file) "J" objects so it can be rendered that way ?

In this case, is for "public" view ok ? For registered users I think I know how to do it ;)

Regards and thanks!!!

User avatar
infograf768
Joomla! Engineer
Joomla! Engineer
Posts: 366
Joined: Fri Aug 12, 2005 3:47 pm
Location: •Translation Matters•

Re: Changing Site Language "on-the-fly"

Post by infograf768 » Tue Jan 15, 2008 8:54 am

The site language can only be changed on a per user basis and only for registered users, as far as I know.
The choice is entered in the database parameters for that user.
As a non-registered user has no entry in the db, how would you change the language?
Change default language? This is also in db and would change for ALL users.
I am not sure that changing the template header has any impact for current strings


As joomfish is not yet available for 1.5, I am curious.
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.

bfalcao
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 19, 2006 11:41 pm

Re: Changing Site Language "on-the-fly"

Post by bfalcao » Tue Jan 15, 2008 2:11 pm

Hi,

The language is analysed on the "initialise" method on the JApplication class.

So, on the index.php file we have:

Code: Select all

$mainframe->initialise();

JPluginHelper::importPlugin('system');


if we enter a parameter on the initialise method we would change it, like shown bellow, for portuguese:

Code: Select all

$A = Array();
$A["language"] = "pt-PT";
$mainframe->initialise($A);

JPluginHelper::importPlugin('system');


I hope this helps other developers that got the same problem as I got. :)

User avatar
infograf768
Joomla! Engineer
Joomla! Engineer
Posts: 366
Joined: Fri Aug 12, 2005 3:47 pm
Location: •Translation Matters•

Re: Changing Site Language "on-the-fly"

Post by infograf768 » Tue Jan 15, 2008 2:54 pm

Are you talking about a system plugin and a module?
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.

bfalcao
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 19, 2006 11:41 pm

Re: Changing Site Language "on-the-fly"

Post by bfalcao » Tue Jan 15, 2008 10:17 pm

Hi "Infograf",

No it's not a module or plugin. It's the main /index.php file that needs to be changed for this, and it needs to be changed on that file because on the template index.php file the JAplication is already being used and we can't change that on that part.

Maybe someone will transform it to a plugin :)

Regards,
BF

User avatar
infograf768
Joomla! Engineer
Joomla! Engineer
Posts: 366
Joined: Fri Aug 12, 2005 3:47 pm
Location: •Translation Matters•

Re: Changing Site Language "on-the-fly"

Post by infograf768 » Wed Jan 16, 2008 9:18 am

A system plugin would let you, I guess, use the "afterInitialize".
And a module specify the variable.
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.


Post Reply