Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78599243
i18n-update-wml.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 21, 21:38
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Aug 23, 21:38 (2 d)
Engine
blob
Format
Raw Data
Handle
20073112
Attached To
R3600 invenio-infoscience
i18n-update-wml.py
View Options
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""This tool updates a file containing sentences to be translated. The
sentences to translate are marked with the following tag:
Blah blah _(To be translated)_ blah.
These tags can span several lines. Extra whitespace is discarded.
"""
import
sys
import
os
import
re
import
gettext
msgdir
=
sys
.
argv
[
1
]
lang
=
sys
.
argv
[
2
]
files
=
sys
.
argv
[
3
:]
charset
=
'utf-8'
translation_file
=
os
.
path
.
join
(
msgdir
,
lang
+
'.mo'
)
translation
=
gettext
.
GNUTranslations
(
open
(
translation_file
))
# This matches the strings to be translated
_tag_re
=
re
.
compile
(
r'_\((.*?)\)_'
,
re
.
DOTALL
)
_ws_re
=
re
.
compile
(
'\s+'
)
# we perform the substitution on the whole file at once, as they are
# not expected to be multi-gigabyte long.
def
replace
(
match
):
"""This function is called for each replacement, and fetches the
translation from the gettext catalog.
"""
text
=
match
.
group
(
1
)
.
decode
(
charset
)
text
=
_ws_re
.
sub
(
' '
,
text
.
strip
())
return
translation
.
ugettext
(
text
)
.
encode
(
'utf-8'
)
for
filename
in
files
:
content
=
open
(
filename
)
.
read
()
content
=
_tag_re
.
sub
(
replace
,
content
)
open
(
filename
,
'w'
)
.
write
(
content
)
Event Timeline
Log In to Comment