Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Lu Xu
erp5
Commits
526cafce
Commit
526cafce
authored
Jun 15, 2012
by
Leonardo Rochael Almeida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Localizer, Parse .po files with polib
Instead of itools.gettext
parent
8aabfd28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
product/Localizer/MessageCatalog.py
product/Localizer/MessageCatalog.py
+16
-14
No files found.
product/Localizer/MessageCatalog.py
View file @
526cafce
# -*- coding:
UTF
-8 -*-
# -*- coding:
utf
-8 -*-
# Copyright (C) 2000-2007 Juan David Ibáñez Palomar <jdavid@itaapy.com>
# Copyright (C) 2003 Roberto Quero, Eduardo Corrales
# Copyright (C) 2004 Søren Roug
...
...
@@ -28,11 +28,8 @@ from re import compile
from
time
import
gmtime
,
strftime
,
time
from
urllib
import
quote
# Import from itools
from
itools.datatypes
import
LanguageTag
import
itools.gettext
from
itools.tmx
import
TMXFile
,
Sentence
,
TMXUnit
,
TMXNote
from
itools.xliff
import
XLFFile
,
XLFNote
# Import from polib
import
polib
# Import from Zope
from
AccessControl
import
ClassSecurityInfo
...
...
@@ -66,16 +63,21 @@ def md5text(str):
return
md5
(
str
.
encode
(
'utf-8'
)).
hexdigest
()
def
to_unicode
(
x
):
def
to_unicode
(
x
,
encoding
=
HTTPRequest
.
default_encoding
):
"""In Zope the ISO-8859-1 encoding has an special status, normal strings
are considered to be in this encoding by default.
"""
if
isinstance
(
x
,
unicode
):
return
x
encoding
=
HTTPRequest
.
default_encoding
return
unicode
(
x
,
encoding
)
def
to_str
(
x
):
"""Make sure we have an (utf-8 encoded) string"""
if
isinstance
(
x
,
str
):
return
x
x
.
encode
(
'utf-8'
)
def
message_encode
(
message
):
"""Encodes a message to an ASCII string.
...
...
@@ -620,18 +622,18 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
messages
=
self
.
_messages
# Load the data
po
=
itools
.
gettext
.
POFile
(
string
=
data
)
for
msgid
in
po
.
get_msgids
():
# TODO Keep the context if any
_context
,
msgid
=
msgid
po
=
polib
.
pofile
(
data
)
encoding
=
to_str
(
po
.
encoding
)
for
entry
in
po
:
msgid
=
to_unicode
(
entry
.
msgid
,
encoding
=
encoding
)
if
msgid
:
msgstr
=
po
.
get_msgstr
(
msgid
)
or
''
msgstr
=
to_unicode
(
entry
.
msgstr
or
''
,
encoding
=
encoding
)
if
not
messages
.
has_key
(
msgid
):
messages
[
msgid
]
=
PersistentMapping
()
messages
[
msgid
][
lang
]
=
msgstr
# Set the encoding (the full header should be loaded XXX)
self
.
update_po_header
(
lang
,
charset
=
po
.
get_encoding
()
)
self
.
update_po_header
(
lang
,
charset
=
encoding
)
security
.
declareProtected
(
'Manage messages'
,
'manage_import'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment