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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
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) 2000-2007 Juan David Ibáñez Palomar <jdavid@itaapy.com>
# Copyright (C) 2003 Roberto Quero, Eduardo Corrales
# Copyright (C) 2003 Roberto Quero, Eduardo Corrales
# Copyright (C) 2004 Søren Roug
# Copyright (C) 2004 Søren Roug
...
@@ -28,11 +28,8 @@ from re import compile
...
@@ -28,11 +28,8 @@ from re import compile
from
time
import
gmtime
,
strftime
,
time
from
time
import
gmtime
,
strftime
,
time
from
urllib
import
quote
from
urllib
import
quote
# Import from itools
# Import from polib
from
itools.datatypes
import
LanguageTag
import
polib
import
itools.gettext
from
itools.tmx
import
TMXFile
,
Sentence
,
TMXUnit
,
TMXNote
from
itools.xliff
import
XLFFile
,
XLFNote
# Import from Zope
# Import from Zope
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
...
@@ -66,16 +63,21 @@ def md5text(str):
...
@@ -66,16 +63,21 @@ def md5text(str):
return
md5
(
str
.
encode
(
'utf-8'
)).
hexdigest
()
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
"""In Zope the ISO-8859-1 encoding has an special status, normal strings
are considered to be in this encoding by default.
are considered to be in this encoding by default.
"""
"""
if
isinstance
(
x
,
unicode
):
if
isinstance
(
x
,
unicode
):
return
x
return
x
encoding
=
HTTPRequest
.
default_encoding
return
unicode
(
x
,
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
):
def
message_encode
(
message
):
"""Encodes a message to an ASCII string.
"""Encodes a message to an ASCII string.
...
@@ -620,18 +622,18 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
...
@@ -620,18 +622,18 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
messages
=
self
.
_messages
messages
=
self
.
_messages
# Load the data
# Load the data
po
=
itools
.
gettext
.
POFile
(
string
=
data
)
po
=
polib
.
pofile
(
data
)
for
msgid
in
po
.
get_msgids
():
encoding
=
to_str
(
po
.
encoding
)
# TODO Keep the context if any
for
entry
in
po
:
_context
,
msgid
=
msgid
msgid
=
to_unicode
(
entry
.
msgid
,
encoding
=
encoding
)
if
msgid
:
if
msgid
:
msgstr
=
po
.
get_msgstr
(
msgid
)
or
''
msgstr
=
to_unicode
(
entry
.
msgstr
or
''
,
encoding
=
encoding
)
if
not
messages
.
has_key
(
msgid
):
if
not
messages
.
has_key
(
msgid
):
messages
[
msgid
]
=
PersistentMapping
()
messages
[
msgid
]
=
PersistentMapping
()
messages
[
msgid
][
lang
]
=
msgstr
messages
[
msgid
][
lang
]
=
msgstr
# Set the encoding (the full header should be loaded XXX)
# 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'
)
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