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.
Comments
`
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.'
}
`
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 !
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
`
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.
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
it´s work, many thanks!
End of the conversation
Hé mon gars, visiblement l'expression "second degré" t'échappe complètement.
Tu as un problème avec les patates ?
Il faut croire qu'on a pas le même humour et que tu as du temps à perdre. Tant mieux pour toi.
En tout cas j'espère que le code de sbillard t'a été utile.
(translation : Hey, Dude, obviously the word "humor" means nothing to you.
Do you feel uncomfortable with potatoes ?
Visibly we don't laugh about the same things and you seem to have time to waste. Good for you.
Anyway I hope that you found the code given by sbillard useful.)
PS : oui, le code m'a également aidé
Translate : sorry i didn't see the "humor", so i do apologize
PS : yep, the code really helped me, that's the great point of the story