Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
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
nexedi
converse.js
Commits
313ba4b1
Commit
313ba4b1
authored
Mar 12, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Different regexps for different languages
parent
f5a6380f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
trans/checks.py
trans/checks.py
+31
-9
No files found.
trans/checks.py
View file @
313ba4b1
from
django.utils.translation
import
ugettext_lazy
as
_
import
re
PRINTF_MATCH
=
re
.
compile
(
'''
PYTHON_PRINTF_MATCH
=
re
.
compile
(
'''
%( # initial %
(?:
\
((?P<key>
\
w+)
\
))? # Py
t
hon style variables, like %(var)s
(?P<fullvar>
[+#-]* # flags
(?:
\
d+)? # wid
t
h
(?:
\
.
\
d+)? # precision
(hh
\
|h
\
|l
\
|ll)? # le
n
gth formatting
(?P<type>[
\
w%])) #
t
ype (%s, %d, etc.)
)'''
,
re
.
VERBOSE
)
PHP_PRINTF_MATCH
=
re
.
compile
(
'''
%( # initial %
(?:(?P<ord>
\
d+)
\
$)? # variable order, like %1$s
(?P<fullvar>
[+#-]* # flags
(?:
\
d+)? # wid
t
h
(?:
\
.
\
d+)? # precision
(hh
\
|h
\
|l
\
|ll)? # le
n
gth formatting
(?P<type>[
\
w%])) #
t
ype (%s, %d, etc.)
)'''
,
re
.
VERBOSE
)
C_PRINTF_MATCH
=
re
.
compile
(
'''
%( # initial %
(?:(?P<ord>
\
d+)
\
$| # variable order, like %1$s
\
((?P<key>
\
w+)
\
))? # Py
t
hon style variables, like %(var)s
(?P<fullvar>
[+#-]* # flags
(?:
\
d+)? # wid
t
h
...
...
@@ -63,12 +85,12 @@ CHECKS['end_newline'] = (_('Trailing newline'), check_end_newline, _('Source and
# For now all format string checks use generic implementation, but
# it should be switched to language specific
def
check_format_strings
(
source
,
target
):
def
check_format_strings
(
source
,
target
,
regex
):
'''
Generic checker for format strings.
'''
src_matches
=
set
([
x
[
0
]
for
x
in
PRINTF_MATCH
.
findall
(
source
)])
tgt_matches
=
set
([
x
[
0
]
for
x
in
PRINTF_MATCH
.
findall
(
target
)])
src_matches
=
set
([
x
[
0
]
for
x
in
regex
.
findall
(
source
)])
tgt_matches
=
set
([
x
[
0
]
for
x
in
regex
.
findall
(
target
)])
if
src_matches
!=
tgt_matches
:
return
True
...
...
@@ -81,7 +103,7 @@ def check_format_strings(source, target):
def
check_python_format
(
source
,
target
,
flags
):
if
not
'python-format'
in
flags
:
return
False
return
check_format_strings
(
source
,
target
)
return
check_format_strings
(
source
,
target
,
PYTHON_PRINTF_MATCH
)
CHECKS
[
'python_format'
]
=
(
_
(
'Python format'
),
check_python_format
,
_
(
'Format string does not match source'
))
...
...
@@ -91,7 +113,7 @@ CHECKS['python_format'] = (_('Python format'), check_python_format, _('Format st
def
check_php_format
(
source
,
target
,
flags
):
if
not
'php-format'
in
flags
:
return
False
return
check_format_strings
(
source
,
target
)
return
check_format_strings
(
source
,
target
,
PHP_PRINTF_MATCH
)
CHECKS
[
'php_format'
]
=
(
_
(
'PHP format'
),
check_php_format
,
_
(
'Format string does not match source'
))
...
...
@@ -101,6 +123,6 @@ CHECKS['php_format'] = (_('PHP format'), check_php_format, _('Format string does
def
check_c_format
(
source
,
target
,
flags
):
if
not
'c-format'
in
flags
:
return
False
return
check_format_strings
(
source
,
target
)
return
check_format_strings
(
source
,
target
,
C_PRINTF_MATCH
)
CHECKS
[
'c_format'
]
=
(
_
(
'C format'
),
check_c_format
,
_
(
'Format string does not match source'
))
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