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
08cd0274
Commit
08cd0274
authored
Oct 15, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly handle locale specific extensions to format string
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
7a6ea1d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
weblate/trans/checks/format.py
weblate/trans/checks/format.py
+9
-3
weblate/trans/tests/test_format_checks.py
weblate/trans/tests/test_format_checks.py
+9
-0
No files found.
weblate/trans/checks/format.py
View file @
08cd0274
...
...
@@ -57,7 +57,7 @@ C_PRINTF_MATCH = re.compile(
%( # initial %
(?:(?P<ord>\
d+)
\$)? # variable order, like %1$s
(?P<fullvar>
[+#-
]*
# flags
[+#-
']*
# flags
(?:\
d+)? # wid
th
(?:\
.
\d+)? # precision
(hh\
|h
\|l\
|ll)? # le
ngth formatting
...
...
@@ -152,6 +152,12 @@ class BaseFormatCheck(TargetCheck):
# Check did not fire
return
False
def
cleanup_string
(
self
,
text
):
"""Removes locale specific code from format string"""
if
'
\
'
'
in
text
:
return
text
.
replace
(
'
\
'
'
,
''
)
return
text
def
check_format
(
self
,
source
,
target
,
unit
,
cache_slot
,
ignore_missing
):
'''
Generic checker for format strings.
...
...
@@ -176,7 +182,7 @@ class BaseFormatCheck(TargetCheck):
# Cache miss, so calculate value
if
src_matches
is
None
:
src_matches
=
[
x
[
0
]
self
.
cleanup_string
(
x
[
0
])
for
x
in
self
.
regexp
.
findall
(
source
)
if
x
[
0
]
!=
'%'
]
...
...
@@ -187,7 +193,7 @@ class BaseFormatCheck(TargetCheck):
self
.
set_cache
(
unit
,
(
uses_position
,
src_matches
),
cache_slot
)
tgt_matches
=
[
x
[
0
]
self
.
cleanup_string
(
x
[
0
])
for
x
in
self
.
regexp
.
findall
(
target
)
if
x
[
0
]
!=
'%'
]
...
...
weblate/trans/tests/test_format_checks.py
View file @
08cd0274
...
...
@@ -340,6 +340,15 @@ class CFormatCheckTest(TestCase):
False
))
def
test_locale_delimiter
(
self
):
self
.
assertFalse
(
self
.
check
.
check_format
(
u'lines: %6.3f'
,
u'radky: %
\
'
6.3f'
,
MockUnit
(
'c_locale_delimiter'
),
0
,
False
))
class
PythonBraceFormatCheckTest
(
TestCase
):
def
setUp
(
self
):
...
...
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