Search code examples
phptranslationgettextpoedit

Gettext and poEdit doesn't work


I am trying gettext and poedit for the first time after reading an article about it. Gettext is enabled - that's not the problem. The problem is when I use poEdit. I will start showing you my files:

#localization.php

$locale = "de_DE";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");

#test.php

echo _("Welcome to my test page");

I have opened poEdit and saved a messages.po-file. Now, poEdit should scan files by itself and show all the strings, that should be translated. However, nothing seems to appear. This is my paths:

C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\ <- Files in this folder
C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\locale\de_DE\LC_MESSAGES <- messages.po in this folder

I think that the problem is the path (when saving the catalog). How should the path be like? Or maybe my path inside the bindtextdomain()-function i wrong. I really hope that I can receive some help on this area.

Thanks in advance.


Solution

  • First possibility:

    1. You have to check the catalog properties (Open the .po file in POedit program then choose Menu 'Catalog'->'Properties' or simply just Alt+Enter, and check the Sources Path
    2. Check the base path is correct refer to C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\
    3. Make sure youu already add "." (without quotes) in paths

    Second possibility:

    When you test the code use the lower string parameter for locale (de_de not de_DE) like this htttp:\url\test.php?locale=de_de

    Third possibility:

    Make sure poedit already generate the .mo file and if it's already then try to restart your WAMP server

    Hopefully it will help