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

Comments (0)

› No comments yet.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pingbacks (0)

› No pingbacks yet.