Question Marks Instead of Non-ASCII Chars when using Gettext in PHP

Yesterday I’ve ported a PHP website to use Gettext for localizations (l10n). After reading through the Gettext documentation and going through the documentation in the PHP site, I’ve manged to get everything working (almost). I had one problem, all the non-ASCII characters (accented Latin chars, Japanese and Chinese) where displayed as question marks (?) instead of the correct form. This happened despite me using UTF-8 encoded files.

While some people (e.g. this one) suggested that it’s not possible to use non-ASCII characters when using a UTF-8 encoded message files, there is a solution and it’s quiet simple one. All you have to do is to call bind_textdomain_codset and pass it UTF-8 as charset.

3 thoughts on “Question Marks Instead of Non-ASCII Chars when using Gettext in PHP”

  1. You saved my day, thank you.
    I’ve been looking for quite some time for a solution and nobody talked about bind_textdomain_codset.

  2. Thanks a lot dude.
    I had this issue for a long time, try a lot to fix it like :
    – Putting all my files encoding to UTF-8
    – Adding the –no-hash argument in msgfmt

    This fixed it and for some reason no one talked about it anywhere else.
    Thanks again.

  3. Thanks a lot man, six hours searching and trying all solutions, you saved me.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.