sphinx-doc / sphinx-intl

A Sphinx utility that make it easy to translate and to apply translations.
https://sphinx-intl.readthedocs.io/
BSD 2-Clause "Simplified" License
74 stars 38 forks source link

Build fails with incorrectly formatted time/date #12

Closed ideasman42 closed 7 years ago

ideasman42 commented 7 years ago

We have translations running on a server and if there is some inconsistency, error causes the build to fail.

I ran into a case where a PO file prevents the entire build from running:

PO file:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) : This page is licensed under a CC-BY-SA 4.0 Int. License
# This file is distributed under the same license as the Blender 2.78 Manual
# package.
# urko <xxxx@gmail.com>, 2017.
#
msgid ""
msgstr ""
"Project-Id-Version: Blender 2.78 Manual 2.78\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: 2017-07-20 13:32+0300\n"
"Last-Translator: urko <xxxx@gmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.4.0\n"
"X-Generator: Poedit 2.0.2\n"
"Language: uk\n"

#: ../../manual/index.rst:5
msgid "Blender Reference Manual"
msgstr "Blender Reference Manual"
Build: locale/uk/LC_MESSAGES/index.mo
Traceback (most recent call last):
  File "/usr/local/bin/sphinx-intl", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sphinx_intl/commands.py", line 247, in build
    basic.build(locale_dir, output_dir, languages)
  File "/usr/local/lib/python3.6/site-packages/sphinx_intl/basic.py", line 101, in build
    cat = c.load_po(po_file)
  File "/usr/local/lib/python3.6/site-packages/sphinx_intl/catalog.py", line 17, in load_po
    cat = pofile.read_po(f)
  File "/usr/local/lib/python3.6/site-packages/babel/messages/pofile.py", line 331, in read_po
    parser.parse(fileobj)
  File "/usr/local/lib/python3.6/site-packages/babel/messages/pofile.py", line 265, in parse
    self._process_comment(line)
  File "/usr/local/lib/python3.6/site-packages/babel/messages/pofile.py", line 224, in _process_comment
    self._finish_current_message()
  File "/usr/local/lib/python3.6/site-packages/babel/messages/pofile.py", line 164, in _finish_current_message
    self._add_message()
  File "/usr/local/lib/python3.6/site-packages/babel/messages/pofile.py", line 158, in _add_message
    self.catalog[msgid] = message
  File "/usr/local/lib/python3.6/site-packages/babel/messages/catalog.py", line 603, in __setitem__
    self.mime_headers = _parse_header(message.string).items()
  File "/usr/local/lib/python3.6/site-packages/babel/messages/catalog.py", line 418, in _set_mime_headers
    self.creation_date = _parse_datetime_header(value)
  File "/usr/local/lib/python3.6/site-packages/babel/messages/catalog.py", line 46, in _parse_datetime_header
    tt = time.strptime(match.group('datetime'), '%Y-%m-%d %H:%M')
  File "/usr/local/lib/python3.6/_strptime.py", line 559, in _strptime_time
    tt = _strptime(data_string, format)[0]
  File "/usr/local/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data 'YEAR-MO-DA HO:MI+ZONE' does not match format '%Y-%m-%d %H:%M'
shimizukawa commented 7 years ago

It seems that "POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" is not a proper format. Please provide decimal numbers for each YEAR, MO, ... to fix the problem.

ideasman42 commented 7 years ago

@shimizukawa - right, however this is something that must have been written automatically by some PO translation software (it applies to all files), will have to contact the author. Also as far as I can see this meta-data could be ignored?

It would be useful for us to have the option in sphinx-intl to demote errors in single PO files to warnings (skipping the problematic PO files), so a badly formatted PO file would warn - just as syntax errors in RST files don't prevent sphinx from creating output.

shimizukawa commented 7 years ago

Do you mean you already have found a concrete solution? It seems that the error caused from babel library and I can't find "ignore wrong meta-data", unfortunately.

ideasman42 commented 7 years ago

@shimizukawa, no solution yet (besides local hack to babel not to read time&date metadata).

I've contacted the translator so they can resolve this. However this seems to be a re-occurring problem for us when new translators get involved.

Was thinking there could be an optional (off-by-default) demotion of errors to warnings around pofile.read_po(f) in sphinx-intl.

shimizukawa commented 7 years ago

For now, you and I have no solution. One option I think is: wrapping with try/except to hide traceback and indicate human-readable error message.

shimizukawa commented 7 years ago

There is nothing to do from Sphinx's side. Now I close this issue but please feel free to resume at any time if you have some solution.