Search code examples
phpgettext

how to use gettext in php?


I have a file dk.po and dk.mo in folder lang in my webdir.

How can I use this file? I have tried all, but I can not get it to work.

// Lang
putenv('LC_ALL=dk');
setlocale(LC_ALL, 'dk');

// Specify location of translation tables
bindtextdomain("dk", ROOT .'lang');

// Choose domain
textdomain("dk");

Solution

  • I am working with this already:

    setlocale(LC_ALL, 'ar_LY.utf8');
    bindtextdomain("trans", $_SERVER["DOCUMENT_ROOT"].'/trans/locale');
    textdomain("trans"); 
    

    the language file path:

    /var/www/trans/locale/ar_LY/LC_MESSAGES/trans.mo
    

    and I think (not sure) that you have to use the same paths!