Gotchas with gettext in PHP

Be careful when you first try gettext in PHP, it can be very unreliable/unpredictable because of different naming conventions.

MyApp.po vs MyApp.mo

PO is the human-readable and you perform the translation in here. MO is the binary file and it’s cached by Apache. Thus, you need to restart Apache (XAMPP) after each change to MyApp.po, then recompile it via “msgfmt MyApp.po -o MyApp.mo”. If you forgot to recompile, it won’t have any of the new modifications.

Folder Structure

/MyApp/locale/vi_VN/LC_MESSAGES/MyApp.mo
/MyApp/locale/da_DK/LC_MESSAGES/MyApp.mo
/MyApp/locale/en_US/LC_MESSAGES/MyApp.mo

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *