0

I've written a .po file for my wordpress theme. The charset is unicode as I cannot define it as 'utf-8' or it will not open in Poedit (the program I'm currently using to catalog my strings). Unfortunately, strings containing accents (french strings, as my base language is french) will not be rendered correctly by either Peoedit (and consequently it's .mo compilation), or the gettext handlings of __() and _e(). My .php files for my website are currently utf-8, to handle french accents.

Could a charset mismatch between .mo and web files be the culprit here? If so, how do I render my .po and .mo files under utf-8 charset and get it to work? Here is the header of my .po file (including utf-8 encoding that doesn't work):

msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: Patrick <shock_x_trooper@hotmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Prusprus
  • 7,987
  • 9
  • 42
  • 57
  • Did you try a newer version of Poedit? It's kind of uncommon that it would reject valid UTF-8. And if your .po files aren't in that charset, what else did you specify? (Show gettext initialization code.) – mario Nov 11 '11 at 21:05
  • Yes, i'm running version 1.4.6, the newest version. Perhaps the problem is that I can't run Poedit with utf-8 encoding, stoping me from recompiling the .mo file (as i cannot open it). Is there a program that will solely compile .mo files from .po files? – Prusprus Nov 11 '11 at 21:18
  • I've found that using a charset iso-8859-1 works with Poeditor, unfortunately, still not working with french accents. – Prusprus Nov 11 '11 at 21:47
  • Other program: `msgfmt` - You can't expect much help without showing code. This is all too vague and a very localized issue. – mario Nov 11 '11 at 22:06
  • Im not sure what code you'd want to see. i assume this would be more of a configuration issue of my files than actual code. – Prusprus Nov 12 '11 at 21:42

2 Answers2

0

In lieu of any initialization code details or hexdumps of your actual .po or .mo files, the only thing that might be worth looking into is bind_textdomain_codeset. (Also setlocale or adding charset in LANG= or LC_ALL=.)

msgfmt and php2po (via Pootle) are alternatives to Poedit, if you can't manage to make UTF-8 work. (Which is what you need to do.)

mario
  • 144,265
  • 20
  • 237
  • 291
  • 1
    So it seems that by replacing all french accents with their ASCII equivalent, it will not throw any unicode error. I assume this is because PoEdit works with the unicode charset to compile the .mo file, msgfmt or php2po might work differently. I've had a look at both, but it seems that they're much less axed around an interface as PoEdit, and more console-based, which is very cumbersome for me. I'll more likely stick with PoEdit and just replace the accents with ASCII codes whenever needed, as for now the strings translated are very much static and small. – Prusprus Nov 14 '11 at 14:23
  • Fix your page encoding. And try another version of Poedit. There is no good reason that it shouldn't work with UTF-8. – mario Nov 14 '11 at 14:24
  • Will attempt to fix it, but if PoEdit uses the unicode charset, there's not much to do... – Prusprus Nov 14 '11 at 14:52
0

You need to define "Content-Type: text/plain; charset=utf-8\n" as you said, but you also need to convert your file to UTF-8 (no BOM) (notepad++ does that).

When you reopen it in poedit, the accents should show OK. Save and upload to your WP theme folder.