Skip to content

Redesign load_po to use Lex/Yacc state transitions style, to ease mai… #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions sphinx_intl/catalog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from babel.messages import pofile, mofile
from babel.messages import pofile, mofile, poparse


def load_po(filename, **kwargs):
Expand All @@ -10,15 +10,16 @@ def load_po(filename, **kwargs):
:param kwargs: keyword arguments to forward to babel's read_po call
:return: catalog object
"""
# pre-read to get charset
with open(filename, "rb") as f:
cat = pofile.read_po(f)
charset = cat.charset or "utf-8"

# To decode lines by babel, read po file as binary mode and specify charset for
# read_po function.
with open(filename, "rb") as f: # FIXME: encoding VS charset
return pofile.read_po(f, charset=charset, **kwargs)
return poparse.load_po(filename, **kwargs)
# # pre-read to get charset
# with open(filename, "rb") as f:
# cat = pofile.read_po(f)
# charset = cat.charset or "utf-8"
#
# # To decode lines by babel, read po file as binary mode and specify charset for
# # read_po function.
# with open(filename, "rb") as f: # FIXME: encoding VS charset
# return pofile.read_po(f, charset=charset, **kwargs)


def dump_po(filename, catalog, **kwargs):
Expand Down
Loading