PHP Localization Best Practices? gettext?

You basically asked and answered your own question, the answer might just be having a slightly better understanding of how PO files work.

Within the PO file you have a msgid and a msgstr. The msgid is the value which is replaced with the msgstr within the PHP file depending on the localization.

Now you can make those msgid’s anything you would like, you could very well make it:

<?php echo _("web.home.featured.HelloWorld"); ?>

And then you would never touch this string again within the source, you only edit the string through the PO files.

So basically the answer to your question is you make the gettext values identifiers for what the string should say, however the translators typically use the default language files text as the basis for conversion, not the identifier itself.

I hope this is clear.

Leave a Comment