Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
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
xpstem
ardublockly
Commits
39b09766
Commit
39b09766
authored
Jun 22, 2015
by
Neil Fraser
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #117 from ensonic/master
Handle non ascii characters in keys with an error.
parents
de30483b
f0c73566
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
i18n/create_messages.py
i18n/create_messages.py
+18
-3
No files found.
i18n/create_messages.py
View file @
39b09766
...
@@ -28,6 +28,14 @@ from common import read_json_file
...
@@ -28,6 +28,14 @@ from common import read_json_file
_NEWLINE_PATTERN
=
re
.
compile
(
'[
\n\r
]'
)
_NEWLINE_PATTERN
=
re
.
compile
(
'[
\n\r
]'
)
def
string_is_ascii
(
s
):
try
:
s
.
decode
(
'ascii'
)
return
True
except
UnicodeEncodeError
:
return
False
def
main
():
def
main
():
"""Generate .js files defining Blockly core and language messages."""
"""Generate .js files defining Blockly core and language messages."""
...
@@ -76,10 +84,17 @@ def main():
...
@@ -76,10 +84,17 @@ def main():
target_lang
=
filename
[:
filename
.
index
(
'.'
)]
target_lang
=
filename
[:
filename
.
index
(
'.'
)]
if
target_lang
not
in
(
'qqq'
,
'keys'
,
'synonyms'
):
if
target_lang
not
in
(
'qqq'
,
'keys'
,
'synonyms'
):
target_defs
=
read_json_file
(
os
.
path
.
join
(
os
.
curdir
,
arg_file
))
target_defs
=
read_json_file
(
os
.
path
.
join
(
os
.
curdir
,
arg_file
))
# Verify that keys are 'ascii'
bad_keys
=
[
key
for
key
in
target_defs
if
not
string_is_ascii
(
key
)]
if
bad_keys
:
print
(
u'These keys in {0} contain non ascii characters: {1}'
.
format
(
filename
,
', '
.
join
(
bad_keys
)))
# If there's a '\n' or '\r', remove it and print a warning.
# If there's a '\n' or '\r', remove it and print a warning.
for
key
,
value
in
target_defs
.
items
():
for
key
,
value
in
target_defs
.
items
():
if
_NEWLINE_PATTERN
.
search
(
value
):
if
_NEWLINE_PATTERN
.
search
(
value
):
print
(
'WARNING: definition of {0} in {1} contained '
print
(
u
'WARNING: definition of {0} in {1} contained '
'a newline character.'
.
'a newline character.'
.
format
(
key
,
arg_file
))
format
(
key
,
arg_file
))
target_defs
[
key
]
=
_NEWLINE_PATTERN
.
sub
(
' '
,
value
)
target_defs
[
key
]
=
_NEWLINE_PATTERN
.
sub
(
' '
,
value
)
...
@@ -118,10 +133,10 @@ goog.require('Blockly.Msg');
...
@@ -118,10 +133,10 @@ goog.require('Blockly.Msg');
synonym_keys
=
[
key
for
key
in
target_defs
if
key
in
synonym_defs
]
synonym_keys
=
[
key
for
key
in
target_defs
if
key
in
synonym_defs
]
if
not
args
.
quiet
:
if
not
args
.
quiet
:
if
extra_keys
:
if
extra_keys
:
print
(
'These extra keys appeared in {0}: {1}'
.
format
(
print
(
u
'These extra keys appeared in {0}: {1}'
.
format
(
filename
,
', '
.
join
(
extra_keys
)))
filename
,
', '
.
join
(
extra_keys
)))
if
synonym_keys
:
if
synonym_keys
:
print
(
'These synonym keys appeared in {0}: {1}'
.
format
(
print
(
u
'These synonym keys appeared in {0}: {1}'
.
format
(
filename
,
', '
.
join
(
synonym_keys
)))
filename
,
', '
.
join
(
synonym_keys
)))
outfile
.
write
(
synonym_text
)
outfile
.
write
(
synonym_text
)
...
...
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