l10n Gotcha: Missing charset in Content-Type Header

I ran into an l10n gotcha that consumed a couple of hours of my afternoon, hopefully this saves somebody a few minutes of trouble in the future. Tools like po2json and grunt-po2json make it easy to convert .po files to .json files, but the default character encoding is expected to be iso-8859-1. This is fine, if your files are indeed encoded using iso-8859-1. Frequently, utf8 is used instead. When your .po files are utf8 encoded and the Content-Type header is set to only “text/plain”, the resulting .json files are full of garbage.

The fix is easy, ensure the Content-Type specifies which charset is used for encoding, for utf8, append charset=UTF-8.

Now your json files should contain translations that make sense.

Leave a Reply