5

I use PHP Gettext extension for localizing a Web app. When you do:

bindtextdomain("example", "/locales");

If you're setting the locale to fr_FR, it will look for the MO in:

/locales/fr_FR/LC_MESSAGES/example.mo

Is there a way to customize that path? For instance I would like to use the following structure:

/locales/example.fr_FR.mo

1 Answer 1

7

The directory structure is fixed by gettext.

Because many different languages for many different packages have to be stored we need some way to add these information to file message catalog files. The way usually used in Unix environments is have this encoding in the file name. This is also done here. The directory name given in bindtextdomains second argument (or the default directory), followed by the name of the locale, the locale category, and the domain name are concatenated:

dir_name/locale/LC_category/domain_name.mo

3
  • 2
    Thanks! I looked for the source of this, here it is for future reference: gnu.org/software/gettext/manual/gettext.html#Locating-Catalogs
    – gou1
    Mar 1, 2012 at 13:38
  • This is great to know, although inconsistent with WordPress, which allows you to do this in any directory: dir_name/domain-xx_XX.mo
    – daveagp
    Aug 29, 2012 at 19:16
  • 1
    Seems like in wordpress they implemented their own 'gettext' in php - they don't rely on php's gettext module, so they can use any directory tree they like
    – itsmeee
    Jun 18, 2013 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.