izimobil / polib

Pure python library to manipulate, create, modify gettext files (pot, po and mo files).
MIT License
103 stars 29 forks source link

OSError: Syntax error in po file (line 1) #110

Closed SLey3 closed 3 years ago

SLey3 commented 3 years ago

When testing a class that utilizes the pofile function, I got the traceback below:

Traceback (most recent call last):
  File "c:\Users\ghub4\OneDrive\Desktop\polib example\polibtest.py", line 39, in <module>
    translator = PoFileAutoTranslator("./pofile.po", "es")
  File "c:\Users\ghub4\OneDrive\Desktop\polib example\polibtest.py", line 13, in __init__
    self.pfile = pofile(file, encoding=encoding, check_for_duplicates=True)
  File "C:\Users\ghub4\AppData\Local\Programs\Python\Python39\lib\site-packages\polib.py", line 130, in pofile
    return _pofile_or_mofile(pofile, 'pofile', **kwargs)
  File "C:\Users\ghub4\AppData\Local\Programs\Python\Python39\lib\site-packages\polib.py", line 78, in _pofile_or_mofile
    instance = parser.parse()
  File "C:\Users\ghub4\AppData\Local\Programs\Python\Python39\lib\site-packages\polib.py", line 1428, in parse
    raise IOError('Syntax error in po file %s(line %s)' %
OSError: Syntax error in po file (line 1)

I am new to pofiles and from I've seen in a an example of a po file, the below was correct:

msgid "" 
msgstr ""
"Project-Id-Version Lingohub 1.0.1\n"
"Language es\n"
"MIME-Version 1.0\n"
"Content-Type textplain; charset=UTF-8\n"
"Content-Transfer-Encoding 8bit\n"

msgid "Let’s make the web multilingual.""
msgstr ""

msgid "We connect developers and translators around the globe 
on Lingohub for a fantastic localization experience."
msgstr ""

I should also mention that my Python version is 3.9 Did I miss something, especially in line 1, that triggered the OSError?

izimobil commented 3 years ago

Your pofile is invalid, event "msgfmt" can't parse it. here's the correct msgid:

msgid ""
"We connect developers and translators around the globe " 
"on Lingohub for a fantastic localization experience."
msgstr ""

https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html