Multilingual : add some infos depending on the language selected

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

  • 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.'
    }
    `
  • flu Member
    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 !
  • 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
  • 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.
  • 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
  • Does zenphoto give you any error messages?
  • no, everything work perfectly, exept this feature. when I set language manually it´s working too
  • 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.
  • Bingo!

    it´s work, many thanks!
  • That is your site? What did you do make your own theme or just add zenphoto functions into your existing page? Its awesome!
  • Yes, that is my site. It is a pure zenphoto. My theme is based on the default-theme (steril-light version)
  • Glad to know it works. This will be a good improvement to zenphoto. Thanks for letting us know.
  • @flu : your example is an insult for all the french people that just said "no" to your illegal war. If you agree all the lies that your president used, and all the iraq people and young american dead for ... nothing (or petrol, choose your best answer), it's up to you.
    End of the conversation
  • acrylian Administrator, Developer
    Even if the example may be a little awkward, I would not take that too serious... Additionally here is not the place for any political statements. (No, I am not American). Thanks.
  • flu Member
    @alex_paris
    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.)
  • ok je m'incline, j'avais pas vraiment repéré le second degré, donc toutes mes excuses :(

    PS : oui, le code m'a également aidé :p

    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
  • flu Member
    ;)
Sign In or Register to comment.