0

I am trying to build a multilingual site with PHP (Linux Mint in German, XAMPP) and I am not able to switch between languages.

To rule out all other potential problems, I broke the whole code down to the minimal example.

Index.php:

session_start();

$locale = "en_GB.utf8";
//To switch languages, (un)comment the following:
//$locale = "es_ES.utf8"; 
//$locale = "de_DE.utf8";

    putenv("LANG=" . $locale);
    setlocale(LC_ALL, $locale); 

    $domain = "strings";
    bindtextdomain($domain, "locale");
    bind_textdomain_codeset($domain, 'UTF-8');

    textdomain($domain);

echo _("Hello World!");

This code always shows me as output "Hallo Welt!" (the German translation), even if the locale is set to English or Spanish (hardcoded to simplify it).

Things I have done so far:

  • Checked the folder structure (I tried with /locale/ll_CC/LC_MESSAGES/strings.po and /locale/ll_CC.utf8/LC_MESSAGES/strings.po)
  • Checked installed locales on my system with locale -a
  • Restarted Apache after switching language

Thank you for your help!

tom123
  • 1

1 Answers1

0

echo __("Hello World!"); with 2 underscores not 1

Jelle Keizer
  • 723
  • 5
  • 9
  • Thank you, but unfortunately, that doesn't do the trick. It seems that one underscore is the correct alias (at least in PHP: http://php.net/manual/en/function.gettext.php). Also, the function DOES work (and translates into German), it just doesn't fetch the correct strings (or doesn't respect the correct locale or...?) – tom123 Oct 26 '14 at 12:34
  • k odd, i always use __ have to look that up then. When i look at other examples i see putenv("LC_ALL=$lang"); instead of your putenv("LANG=$lang"); – Jelle Keizer Oct 26 '14 at 12:45