Need a PHP variable for active language code

op351net

Joined: 2009-10-04
Posts: 8
Posted: Sun, 2009-10-25 12:30

I'm using a third-party PHP script in Gallery and I need to define in that script a variable representing the active language code selected for Gallery (in my case 'pt_PT' or 'en_US'). Usually there is something like $locale, $lang, etc but I can't find one in Gallery scripts to use it in the third-party script. I've tried $_SESSION['language'] and similar but doesn't work. Any ideas, please?

---
Roaming... free the image!
http://gallery.op351.net/
Porto - PORTUGAL

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2009-10-25 12:50

This is how I'm doing the same in my geeklog -> Gallery2 bridge:

function G2B_MapLanguage($GL_language) {
    $GL_to_G2_language = array(
        //	'bosnian'			=>	'xx',	// *** No mapping
        'bulgarian'=>'bg',
        'chinese_big5'=>'zh',
        'chinese_gb2312'=>'zh',
        'chinese_simplified_utf-8'=>'zh_TW',
        'chinese_traditional_utf-8'=>'zh',
        //	'croatian_utf-8'	=>	'xx',	// *** No mapping
        //	'croatian'			=>	'xx',	// *** No mapping
        'czech'=>'cs',
        'danish'=>'da',
        'dutch'=>'nl',
        'english_utf-8'=>'en_GB',
        'english'=>'en_GB',
        'finnish_utf-8'=>'fi',
        'finnish'=>'fi',
        'french_canada'=>'fr',
        'french_france'=>'fr',
        'german_formal'=>'de',
        'german_utf-8'=>'de',
        'german'=>'de',
        'hebrew'=>'he',
        'hellenic'=>'el',
        //	'indonesian'		=>	'xx',	// *** No mapping
        'italian'=>'it',
        'japanese_utf-8'=>'ja',
        'japanese'=>'ja',
        'norwegian'=>'no',
        'polish'=>'pl',
        'portuguese_brazil'=>'pt_BR',
        'portuguese'=>'pt_PT',
        //	'romanian'			=>	'xx',	// *** No mapping
        'russian'=>'ru',
        //	'slovak'			=>	'xx',	// *** No mapping
        'slovenian'=>'sl',
        'spanish_argentina'=>'es',
        'spanish'=>'es',
        'swedish'=>'sv',
        'turkish'=>'tr'
        );

    $lang = $GL_to_G2_language[$GL_language];

    if ($lang == '')
        $lang = 'en_GB'; // default to English

    return ($lang);
}

Hope this helps.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
op351net

Joined: 2009-10-04
Posts: 8
Posted: Sun, 2009-10-25 13:02

Maybe I was not clear enough but I just need to know in my script what language is Gallery running on. With that I intend to place some conditions in my script according to Gallery active language.

Thanks anyway for your reply. Was really fast :-)
---
Roaming... free the image!
http://gallery.op351.net/
Porto - PORTUGAL

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2009-10-25 13:15
 
op351net

Joined: 2009-10-04
Posts: 8
Posted: Sun, 2009-10-25 14:06

... and what would be the PHP code to insert in my script? This is because every trial I've made have resulted in

Fatal error: Using $this when not in object context in http://gallery.op351.net/modules/core/classes/Gallery.class on line 561

Thanks
---
Roaming... free the image!
-Gallery v2.3
-Theme 'Carbon'
http://gallery.op351.net/
Porto - PORTUGAL

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2009-10-25 14:33
global $gallery;
list($ret, $lang) = GalleryCoreApi::getActiveLanguageCode();
if($ret){
    print('sorry could not retrieve active language');
}

Strange that you are using gallery as the master app, we usually embed gallery in the third party app. Easier I belive.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
op351net

Joined: 2009-10-04
Posts: 8
Posted: Sun, 2009-10-25 16:59

No success! 'GalleryCoreApi' has not the function you refer to and other classes (like 'GalleryTranslator') give me empty arrays.

Regarding 'embeding', I'm rather for natural beauty of Gallery which is really a great job. Only the translation/localization still need a gooood work out...
Thanks.
---
Roaming... free the image!
-Gallery v2.3
-Theme 'Carbon'
http://gallery.op351.net/
Porto - PORTUGAL

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2009-10-25 17:37

Well, its a method of Gallery.class which should be available via GalleryCoreApi but is certainly available via:
list($ret, $lang) = $gallery->getActiveLanguageCode();
of course I'm assuming you're connected to $gallery via GalleryEmbed or other.

Also you can get the language of the current user by loading the user and using: $user->getLanguage();

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
op351net

Joined: 2009-10-04
Posts: 8
Posted: Tue, 2009-10-27 18:15

My Gallery is not embedded! I'm just using it on a stand-alone mode but I use a PHP script INSIDE Gallery for a particular function. Even being inside Gallery nothing is working in that script to get the active language code available to program some conditions!!

Thanks anyway. You've been great.

POST DAYS OF INVESTIGATION: for those wanting to include a PHP script with current language dependency in a Gallery template file (.tpl) there it goes a possible solution:

- place in the '.tpl' file where you call an external PHP script the following code (or similar):

  {capture name="lang"}{g->language}{/capture}
  {assign var="lang" value=$smarty.capture.lang}
  {if $lang == "pt-PT"}
	{php} include "http://mydomain.com/myscript.php?lng=pt"; {/php}
  {else}
	{php} include "http://mydomain.com/myscript.php?lng=en"; {/php}
  {/if}

Might not be hi-tech but it works for me!

---
Roaming... free the image!
Gallery v2.3 | Theme 'Carbon'
http://gallery.op351.net/
Porto - PORTUGAL