0

I'm using gettext to localize my web app. So far, I was able to get it working with a simple example, as follows :

<?php
    $dir = "../locale";
    $lang="fr_FR";
    $domain="messages";
    putenv("LANG=$lang");
    setlocale(LC_ALL, $lang);
    bindtextdomain ($domain, $dir);
    textdomain ($domain);
    echo gettext("TEST 1") . "\n";
    echo __("Test 2"); // works if using gettext("Test 2");
?>

As you see, the last line tries using "__" instead of "gettext" which I read in several posts to be equivalent... So why is it not translating when using echo __("Test 2");?

Should I do a global replace in my source to replace all __(" with gettext("?

neggenbe
  • 1,697
  • 2
  • 24
  • 62
  • There is no standard `__` function, `_` exists which is alias of `gettext`. Have you defined own function? – mleko May 19 '18 at 12:54
  • Nope, but `echo __("test");` works just fine and also, see e.g. this post...https://stackoverflow.com/q/2677229/2490877 – neggenbe May 19 '18 at 12:55
  • I assume this is wordpress related ?https://developer.wordpress.org/reference/functions/__/ – mleko May 19 '18 at 13:05
  • Nope this is standard `php`... I tried adding the `$domain` (i.e. `messages`) and still no success... So what I wrote above is, I guess, true - I need to globally replace `__` with either `_` or `gettext`?! – neggenbe May 19 '18 at 13:14

0 Answers0