Detecting Errors in .po files
Asked Answered
O

3

12

I'm using a set of .po files generated by the company translation system (with Pootle, if that's relevant). I'm having trouble converting these files to .mo (the binary counterpart to .po files) using the msgfmt utility (with the -C operator, which checks the format of the file), I get the following error:

$ msgfmt -v -C default.po
default.po:1:2: syntax error
msgfmt: found 1 fatal error

I've Googled pretty extensively for a way to get more information on what, exactly, is causing msgfmt to throw this error.

I've also tried removing the first couple of lines of the file (which were not part of the catalog, but just comments or empty translation strings).

I'm inclined to think that it's a file encoding issue, but I've not dealt much with this type of thing, so I'm more than willing to admit that this is user error.

Does anybody know how I can more specifically diagnose the error with these files? Also, the same behavior is exhibited across all of the localized files, not just one specific file.

Obstinacy answered 26/3, 2012 at 21:39 Comment(0)
C
8

It sounds almost definitely like an issue with BOM, PO files should not contain them. An alternative would be to run pocompile from the Translate Toolkit, since you are already using Pootle pocompile should already be installed on your system.

Cosmotron answered 13/9, 2012 at 8:15 Comment(0)
T
8

My guess would also be that this is an encoding issue. Since the error already appears in the first few characters of the file the culprit is probably a byte order mark, which in utf-8 is encoded as the byte sequence 0xEF, 0xBB, 0xBF. The best way to check this would be to look at the file with a hex editor, or use an editor that can tell you whether the file contains a byte order mark.

For example in vim you can use set bomb? and it will tell you either bomb or nobomb.

Edit: Here is a blog entry of someone having the exact same error message caused by an utf-8 encoded file starting with a byte order mark.

Tamica answered 3/4, 2012 at 15:21 Comment(1)
Windows users: The suggestion in the linked article suggested using Notepad++'s menu option: Encoding > Convert to UTF-8 without BOMArchenteron
C
8

It sounds almost definitely like an issue with BOM, PO files should not contain them. An alternative would be to run pocompile from the Translate Toolkit, since you are already using Pootle pocompile should already be installed on your system.

Cosmotron answered 13/9, 2012 at 8:15 Comment(0)
S
0

Open your file in vim and type :set bomb? and keep entering it will all those error prone lines one by one.

Sheehy answered 5/3, 2019 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.