user2348684
user2348684

Reputation: 371

Encoding problems using PHP Gettext

I am trying to start using Gettext for my php project.

However, I have some encoding problems. If I use UTF-8 encoding in the .mo files and use "bind_textdomain_codeset('messages', 'UTF-8');" I don't see the accents properly in the browser. In Firefox, in order to see them OK, I have to change the browser codification to UTF-8 (it is not the default encoding). As I can't expect my visitators to change their browser encoding, what should I do?

I also tried changing everything to ISO-8859-15 and, although accents work OK (even with the browser default encoding), the € sign doesn't work. And I have also read there are problemas when using languages like russian, so it doesn't seem to be the right way.

How should I proceed?

Thank you :)

Upvotes: 0

Views: 928

Answers (1)

Jon
Jon

Reputation: 437614

You should instruct the browser that the page you are sending is encoded in UTF-8. Do this using header before you actually output any content:

header('Content-Type: text/html; charset=utf-8');

Of course this assumes that the page is in UTF-8 in the first place.

In general, the one law that you can never disregard is that all content in your page must be in the same encoding (and that's the encoding you use when declaring the Content-Type).

If all sources for the content (e.g. your hardcoded stuff, what comes from gettext, what comes from a database) are in that encoding, everything is fine. If not then you have to manually convert all content from sources that diverge to the encoding of the page, which is possible through iconv or mb_convert_encoding.

Upvotes: 1

Related Questions