Active language code in template

stephenju
stephenju's picture

Joined: 2005-07-05
Posts: 172
Posted: Tue, 2006-02-28 23:18

Is there a way to get the current language code in a template? Like 'en_GB' or 'zh_TW'?

-
東方之朱

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-03-01 05:27

You'd have to add that value into the $template in your theme.inc. It is not in the tpl data by default.

$gallery->getActiveLanguageCode();

 
stephenju
stephenju's picture

Joined: 2005-07-05
Posts: 172
Posted: Wed, 2006-03-01 05:52

OK. That will do. Thanks.

-
東方之朱

 
stephenju
stephenju's picture

Joined: 2005-07-05
Posts: 172
Posted: Thu, 2006-03-02 02:17

I am trying to add lang into <html> element so the browser will render it correctly. But to do that, I have to mock with each theme I use. And I might (OK, I will) forget to update the changed theme files after each upgrade.

Will it be possible to have 'Content-Language' in the HTML header? This way the browser will know which language it is and render the page corrently (if the browser does it right) without mocking with the templates.
-
東方之朱

 
stephenju
stephenju's picture

Joined: 2005-07-05
Posts: 172
Posted: Thu, 2006-03-02 02:19

BTW. The language code used in HTML header is kind of different from G2 locale code. For example, HTML requires 'zh-TW' for Traditional Chinese while G2 is using 'zh_TW'. But a simple str_replace will do just fine.
-
東方之朱

 
yauyau

Joined: 2006-01-06
Posts: 8
Posted: Thu, 2006-03-02 18:51

can anyone explain more how it's work as i am so stupid?
I means in the .inc
$gallery->getActiveLanguageCode();

and
in the .tpl

THANKS!

 
stephenju
stephenju's picture

Joined: 2005-07-05
Posts: 172
Posted: Thu, 2006-03-02 21:31

Create a directory called 'local' in the same directory as theme.tpl file then copy the theme.tpl file into the new 'local' directory and edit that copy.

Now at the begining of theme.tpl add the following code:

{php}
if (!headers_sent()) {
	global $gallery;
	list ($ret, $languageCode) = $gallery->getActiveLanguageCode();
	header('Content-Language: '. str_replace('_', '-', $languageCode));
}
{/php}

right before:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

-
東方之朱

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Wed, 2006-11-22 04:54

If you have a look at http://gallery.felixsalomon.net/mtbuffalo you can see the actual language highlighted in the upper menu. But as soon as you view a photo (eg http://gallery.felixsalomon.net/mtbuffalo/Buffalo_30a.jpg.html) the highlighting doesn't work anymore. Although I'm using the same php in theme.inc/theme.tpl both times.

Any suggestions why that happens?

Cheers

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-11-22 18:29

Nice UI!
i guess you only added the template variable to album but not to photo pages.

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Wed, 2006-11-22 22:25

Hi Valiant!
Thank you!

Actually it's all done in the theme.tpl... so it shouldn't really make a difference whether I'm viewing a photo or an album.

Uuups, I've just noticed that the important piece of code is the one in theme.inc - and there it is in fact only in the showAlbumPage section defined!
Now it works after I've copied the code to the showPhotoPage function.

Thanx