PDA

View Full Version : Getting current language in Templates?



Hal9000
02-26-10, 08:00 AM
Hello!
My WHMCS is running with several languages, and I want to customize a template file in that it loads a different image depending on the current language.
However, is there a variable I can use in the template that contains the current language name?

m00
02-26-10, 08:39 AM
{$language}

Hal9000
02-26-10, 09:08 AM
lol that was easy :) thank you!

HostRW
03-20-10, 02:31 PM
Has the $language variable changed in the latest WHMCS version?

I am using following to select either Dutch or the standard language when calling a template:


# Define the template filename to be used without the .tpl extension

if ($language == "NL-Dutch")
{
$templatefile = "aboutus-nl";
}
else
{
$templatefile = "aboutus";
}

outputClientArea($templatefile);


This worked fine until the latest version. Now after displaying the Dutch once it switches back to the default language.

Any ideas how to fix this?

m00
03-21-10, 06:49 PM
Try this:

if ($smarty->_tpl_vars['language'] == "Dutch")
$templatefile = "aboutus-nl";
else
$templatefile = "aboutus";

outputClientArea($templatefile);

HostRW
03-22-10, 06:47 PM
Hi M00

That works just great, thank you!
I also just found a way to select the language in the template using $language and an if statement.
So now I have 2 ways to do the job... Hm, which one will I take now... ;)

HerrZ
03-23-10, 08:04 AM
additional question:

is the Smarty var $filename new in v4.2.1?

HostRW
03-23-10, 08:13 AM
Not sure, but something must have changed as my solution worked fine before the upgrade to v4.2.1

As I asked Matt the same question as above he answered:


I don't think $language is a variable that would be defined in custom pages. $_SESSION['Language'] is where the currently selected language is stored if different from the default.

Not sure about how to use $_SESSION['Language'] though...

m00
03-23-10, 08:15 AM
Hi M00

That works just great, thank you!
I also just found a way to select the language in the template using $language and an if statement.
So now I have 2 ways to do the job... Hm, which one will I take now... ;)

That was the actual thing I meant in my first reply, but it will work both. :)


additional question:

is the Smarty var $filename new in v4.2.1?

No

EDIT:

Not sure, but something must have changed as my solution worked fine before the upgrade to v4.2.1

As I asked Matt the same question as above he answered:



Not sure about how to use $_SESSION['Language'] though...

I would recommend to use the language defined inside Smarty. This is just the language how it shows it the customer.