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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
9c69949b
Commit
9c69949b
authored
Oct 04, 2022
by
Kazuhiko Shiozaki
Committed by
Jérome Perrin
May 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2/py3: make translation code compatible.
parent
bb0d8a2f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
11 deletions
+13
-11
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_updateTranslationTable.py
...portal_skins/erp5_core/ERP5Site_updateTranslationTable.py
+5
-5
product/ERP5/tests/testTranslation.py
product/ERP5/tests/testTranslation.py
+5
-5
product/Localizer/MessageCatalog.py
product/Localizer/MessageCatalog.py
+3
-1
No files found.
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_updateTranslationTable.py
View file @
9c69949b
from
Products.ERP5Type.Utils
import
getMessageIdWithContext
from
Products.ERP5Type.Utils
import
getMessageIdWithContext
,
str2unicode
,
unicode2str
supported_languages
=
context
.
Localizer
.
get_supported_languages
()
supported_languages
=
context
.
Localizer
.
get_supported_languages
()
translated_keys
=
{}
# This dict prevents entering the same key twice
translated_keys
=
{}
# This dict prevents entering the same key twice
...
@@ -34,7 +34,7 @@ for portal_type in portal_type_list:
...
@@ -34,7 +34,7 @@ for portal_type in portal_type_list:
for
lang
in
supported_languages
:
for
lang
in
supported_languages
:
key
=
(
lang
,
portal_type
.
getId
(),
state_var
,
state_reference
)
key
=
(
lang
,
portal_type
.
getId
(),
state_var
,
state_reference
)
if
key
not
in
translated_keys
:
if
key
not
in
translated_keys
:
translated_message
=
context
.
Localizer
.
erp5_ui
.
gettext
(
state_reference
,
lang
=
lang
).
encode
(
'utf-8'
)
translated_message
=
unicode2str
(
context
.
Localizer
.
erp5_ui
.
gettext
(
state_reference
,
lang
=
lang
)
)
translated_keys
[
key
]
=
None
# mark as translated
translated_keys
[
key
]
=
None
# mark as translated
object_list
.
append
(
dict
(
language
=
lang
,
message_context
=
state_var
,
portal_type
=
portal_type
.
getId
(),
original_message
=
state_reference
,
object_list
.
append
(
dict
(
language
=
lang
,
message_context
=
state_var
,
portal_type
=
portal_type
.
getId
(),
original_message
=
state_reference
,
translated_message
=
translated_message
))
translated_message
=
translated_message
))
...
@@ -43,10 +43,10 @@ for portal_type in portal_type_list:
...
@@ -43,10 +43,10 @@ for portal_type in portal_type_list:
if
state
.
getTitle
()
is
not
None
and
state
.
getTitle
()
!=
''
:
if
state
.
getTitle
()
is
not
None
and
state
.
getTitle
()
!=
''
:
state_var_title
=
'%s_title'
%
state_var
state_var_title
=
'%s_title'
%
state_var
msg_id
=
getMessageIdWithContext
(
state
.
getTitle
(),
'state'
,
wf_id
)
msg_id
=
getMessageIdWithContext
(
state
.
getTitle
(),
'state'
,
wf_id
)
translated_message
=
context
.
Localizer
.
erp5_ui
.
gettext
(
msg_id
,
default
=
''
,
lang
=
lang
).
encode
(
'utf-8'
)
translated_message
=
unicode2str
(
context
.
Localizer
.
erp5_ui
.
gettext
(
msg_id
,
default
=
''
,
lang
=
lang
)
)
if
translated_message
==
''
:
if
translated_message
==
''
:
msg_id
=
state
.
getTitle
()
msg_id
=
state
.
getTitle
()
translated_message
=
context
.
Localizer
.
erp5_ui
.
gettext
(
state
.
getTitle
().
decode
(
'utf-8'
),
lang
=
lang
).
encode
(
'utf-8'
)
translated_message
=
unicode2str
(
context
.
Localizer
.
erp5_ui
.
gettext
(
str2unicode
(
state
.
getTitle
()),
lang
=
lang
)
)
key
=
(
lang
,
portal_type
.
getId
(),
state_var_title
,
state_reference
,
msg_id
)
key
=
(
lang
,
portal_type
.
getId
(),
state_var_title
,
state_reference
,
msg_id
)
if
key
not
in
translated_keys
:
if
key
not
in
translated_keys
:
translated_keys
[
key
]
=
None
# mark as translated
translated_keys
[
key
]
=
None
# mark as translated
...
@@ -67,7 +67,7 @@ for ptype in context.portal_types.objectValues():
...
@@ -67,7 +67,7 @@ for ptype in context.portal_types.objectValues():
if
key
not
in
translated_keys
:
if
key
not
in
translated_keys
:
translated_keys
[
key
]
=
None
# mark as translated
translated_keys
[
key
]
=
None
# mark as translated
object_list
.
append
(
dict
(
language
=
lang
,
message_context
=
'portal_type'
,
portal_type
=
portal_type
,
original_message
=
portal_type
,
object_list
.
append
(
dict
(
language
=
lang
,
message_context
=
'portal_type'
,
portal_type
=
portal_type
,
original_message
=
portal_type
,
translated_message
=
context
.
Localizer
.
erp5_ui
.
gettext
(
portal_type
,
lang
=
lang
).
encode
(
'utf-8'
)))
translated_message
=
unicode2str
(
context
.
Localizer
.
erp5_ui
.
gettext
(
portal_type
,
lang
=
lang
)
)))
if
object_list
:
if
object_list
:
catalog_translation_list
(
object_list
)
catalog_translation_list
(
object_list
)
...
...
product/ERP5/tests/testTranslation.py
View file @
9c69949b
...
@@ -31,7 +31,7 @@ import unittest
...
@@ -31,7 +31,7 @@ import unittest
import
MethodObject
import
MethodObject
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.Utils
import
getMessageIdWithContext
from
Products.ERP5Type.Utils
import
getMessageIdWithContext
,
str2unicode
,
unicode2str
# dependency order
# dependency order
target_business_templates
=
(
target_business_templates
=
(
...
@@ -100,7 +100,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
...
@@ -100,7 +100,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
if
(
result
==
msgid
)
and
(
self
.
lang
!=
'en'
):
if
(
result
==
msgid
)
and
(
self
.
lang
!=
'en'
):
#result = None
#result = None
result
=
self
.
portal
.
Localizer
.
erp5_ui
.
gettext
(
msgid
)
result
=
self
.
portal
.
Localizer
.
erp5_ui
.
gettext
(
msgid
)
return
result
.
encode
(
'utf8'
)
return
unicode2str
(
result
)
def
logMessage
(
self
,
message
):
def
logMessage
(
self
,
message
):
self
.
message
+=
'%s
\
n
'
%
message
self
.
message
+=
'%s
\
n
'
%
message
...
@@ -180,7 +180,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
...
@@ -180,7 +180,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
if
error
:
if
error
:
for
key
,
item_list
in
error_dict
.
items
():
for
key
,
item_list
in
error_dict
.
items
():
if
len
(
item_list
)
!=
0
:
if
len
(
item_list
)
!=
0
:
self
.
logMessage
(
"
\
n
'%s'"
%
key
.
encode
(
'utf-8'
))
self
.
logMessage
(
"
\
n
'%s'"
%
unicode2str
(
key
))
self
.
logMessage
(
'
\
t
### Conflicting workflow with common states (ie, what user can see) ###'
)
self
.
logMessage
(
'
\
t
### Conflicting workflow with common states (ie, what user can see) ###'
)
for
item
in
item_list
:
for
item
in
item_list
:
# XXX Improve rendering
# XXX Improve rendering
...
@@ -250,7 +250,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
...
@@ -250,7 +250,7 @@ class TestWorkflowStateTitleTranslation(ERP5TypeTestCase):
'item_workflow'
),
'item_workflow'
),
add
=
1
)
add
=
1
)
message_catalog
.
message_edit
(
'Validated'
,
self
.
lang
,
message_catalog
.
message_edit
(
'Validated'
,
self
.
lang
,
'Validé'
.
decode
(
'utf8
'
),
''
)
str2unicode
(
'Validé
'
),
''
)
message_catalog
.
message_edit
(
getMessageIdWithContext
(
'Validated'
,
message_catalog
.
message_edit
(
getMessageIdWithContext
(
'Validated'
,
'state'
,
'state'
,
'item_workflow'
),
'item_workflow'
),
...
@@ -433,7 +433,7 @@ class TestTranslation(ERP5TypeTestCase):
...
@@ -433,7 +433,7 @@ class TestTranslation(ERP5TypeTestCase):
</tal:ommit>
</tal:ommit>
"""
%
domain
"""
%
domain
self
.
myzpt
.
pt_edit
(
zpt_template
,
'text/html'
)
self
.
myzpt
.
pt_edit
(
zpt_template
,
'text/html'
)
return
self
.
myzpt
(
words
=
words
).
encode
(
'utf-8'
).
split
()
return
unicode2str
(
self
.
myzpt
(
words
=
words
)
).
split
()
def
test_ZPT_translation
(
self
):
def
test_ZPT_translation
(
self
):
results
=
self
.
translate_by_zpt
(
'erp5_ui'
,
'Person'
,
'Draft'
)
results
=
self
.
translate_by_zpt
(
'erp5_ui'
,
'Person'
,
'Draft'
)
...
...
product/Localizer/MessageCatalog.py
View file @
9c69949b
...
@@ -688,8 +688,10 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
...
@@ -688,8 +688,10 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
def
manage_import
(
self
,
lang
,
file
,
REQUEST
=
None
,
RESPONSE
=
None
):
def
manage_import
(
self
,
lang
,
file
,
REQUEST
=
None
,
RESPONSE
=
None
):
""" """
""" """
# XXX For backwards compatibility only, use "po_import" instead.
# XXX For backwards compatibility only, use "po_import" instead.
if
isinstance
(
file
,
str
):
if
isinstance
(
file
,
str
):
# six.PY2
content
=
file
content
=
file
elif
isinstance
(
file
,
bytes
):
# six.PY3
content
=
file
.
decode
()
else
:
else
:
content
=
file
.
read
()
content
=
file
.
read
()
...
...
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