ZenphotoCMS Forum
Multilingual : add some infos depending on the language selected - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: Translating (https://forum.zenphoto.org/forum-8.html)
+--- Thread: Multilingual : add some infos depending on the language selected (/thread-3619.html)

Pages: 1 2


Multilingual : add some infos depending on the language selected - flu - 27-08-2008

Hi,
I was wondering if it's possible to add directly in the php theme files some additionnal infos depending on the selected language. Let's get clearer, for example :
"freedom fries" but only if the english language is selected
"gut kartofel" for german language
"we don't call it "french fries" anymore, you bloody bastard" if the french language is selected
"learn english, you moron, anyway there's no potato in your damn insignificant country, I can't believe you can even use a computer" for any other language selected, etc.

1.Is this technically possible ? (no need to store these datas in the database, it would just be added directly in the index.php theme file)
2.If it's possible, what would be the regular expression to use it ?

Note : If you don't speak english, german or french, well, this is just an example, huhuhu ! Sorry.




Multilingual : add some infos depending on the language selected - sbillard - 27-08-2008

You can certainly do that. There is an option--locale which tells you which language (actually locale) is selected. So you can just insert a switch statement into your theme:

switch (getOption('locale')) { default: case 'en_US': echo Me gusta las patatas fritas.'; break; case 'fr_FR': echo 'eh bien les pommes frits.'; break; case 'de_DE': echo 'Bratkartoffein sint fur den hunden.' }




Multilingual : add some infos depending on the language selected - flu - 28-08-2008

Hi,
thank you, thank you, thank you Stephen, this is just wonderful !
I can't even remember how I published my pictures before I use ZP !
Woaw !




Multilingual : add some infos depending on the language selected - suxab - 10-09-2008

Hi all,

I have problem with automatic language selection (HttpAcceptLanguage). I want to make an alias "hu" or "sk" for ISO standards (hu_HU, sk_SK) becouse not configured browsers of visitors returning just the brief code (hu, sk)
So, is it posibble to use this method for switching language of zenphoto by this way?

switch (getOption('locale')) { case 'hu': setlocale(LC_ALL, hu_HU); break; case 'sk': setlocale(LC_ALL, sk_SK); break;
thanks




Multilingual : add some infos depending on the language selected - sbillard - 10-09-2008

Here is how I would do it:
function getUserLocale() { if (DEBUG_LOCALE) debugLogBackTrace("getUserLocale()"); $cookiepath = WEBPATH; if (WEBPATH == '') { $cookiepath = '/'; } if (isset($_POST['dynamic-locale'])) { $locale = sanitize($_POST['dynamic-locale'], 0); zp_setCookie('dynamic_locale', $locale, time()+5184000, $cookiepath); if (DEBUG_LOCALE) debugLog("dynamic_locale post: $locale"); } else { $localeOption = getOption('locale'); $locale = zp_getCookie('dynamic_locale'); if (DEBUG_LOCALE) debugLog("locale from option: ".$localeOption.'; dynamic locale='.$locale); if (empty($localeOption) && ($locale === false)) { // if one is not set, see if there is a match from 'HTTP_ACCEPT_LANGUAGE' $languageSupport = generateLanguageList(); $userLang = parseHttpAcceptLanguage(); foreach ($userLang as $lang) { $l = strtoupper($lang['fullcode']); foreach ($languageSupport as $key=>$value) { if (strtoupper($key) == $l) { // we got a match $locale = $key; if (DEBUG_LOCALE) debugLog("locale set from HTTP Accept Language: ".$locale); break; } } } if ($locale === false) { // try partal matches foreach ($userLang as $lang) { $l = strtoupper($lang['fullcode']); foreach ($languageSupport as $key=>$value) { if (preg_match('/^'.strtoupper($key).'/', $l)) { // we got a partial match $locale = $key; if (DEBUG_LOCALE) debugLog("locale set from HTTP Accept Language (partial match): ".$locale); break; } } } } } } if ($locale !== false) { setOption('locale', $locale, false); } return $locale; }
This is a more general solution which will match up a language based on a partial match of the perfered local to the list of locales.

I will add this to the nightly build. Let us know if it does the job.




Multilingual : add some infos depending on the language selected - suxab - 10-09-2008

Hi sbillard!

No, it´s not working for me, my primary detected language is still english.
my site is: http://wallpaperstock.sk
My output from list_locales.php :

`
Http Accept Languages:
Key code coef morecode fullcode
1.0-hu hu 1.0 hu
0.5-sk sk 0.5 sk

Supported locales:
Warning: system() has been disabled for security reasons in /domains1/do909200/public/www_root/list_locales.php on line 4
`
many thanks




Multilingual : add some infos depending on the language selected - sbillard - 10-09-2008

Does zenphoto give you any error messages?




Multilingual : add some infos depending on the language selected - suxab - 10-09-2008

no, everything work perfectly, exept this feature. when I set language manually it´s working too




Multilingual : add some infos depending on the language selected - sbillard - 10-09-2008

Ok, I have determined the problem. But the fix hits some more files than just functions-i18n. You can either download the complete SVN or wait for tonight's build. Again, let me know if it works for you.




Multilingual : add some infos depending on the language selected - suxab - 11-09-2008

Bingo!

it´s work, many thanks!