Skip to content

Commit

Permalink
Bugfix: update-translations: Allow numerus translations to omit %n sp…
Browse files Browse the repository at this point in the history
…ecifier (usually when it only has one possible value)
  • Loading branch information
luke-jr committed Dec 25, 2015
1 parent da59f28 commit 0d59589
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions contrib/devtools/update-translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ def sanitize_string(s):
'''Sanitize string for printing'''
return s.replace('\n',' ')

def check_format_specifiers(source, translation, errors):
def check_format_specifiers(source, translation, errors, numerus):
source_f = split_format_specifiers(find_format_specifiers(source))
# assert that no source messages contain both Qt and strprintf format specifiers
# if this fails, go change the source as this is hacky and confusing!
assert(not(source_f[0] and source_f[1]))
try:
translation_f = split_format_specifiers(find_format_specifiers(translation))
except IndexError:
errors.append("Parse error in translation '%s'" % sanitize_string(translation))
errors.append("Parse error in translation for '%s': '%s'" % (sanitize_string(source), sanitize_string(translation)))
return False
else:
if source_f != translation_f:
if numerus and source_f == (set(), ['n']) and translation_f == (set(), []) and translation.find('%') == -1:
# Allow numerus translations to omit %n specifier (usually when it only has one possible value)
return True
errors.append("Mismatch between '%s' and '%s'" % (sanitize_string(source), sanitize_string(translation)))
return False
return True
Expand Down Expand Up @@ -148,7 +151,7 @@ def postprocess_translations(reduce_diff_hacks=False):
if translation is None:
continue
errors = []
valid = check_format_specifiers(source, translation, errors)
valid = check_format_specifiers(source, translation, errors, numerus)

for error in errors:
print('%s: %s' % (filename, error))
Expand Down

0 comments on commit 0d59589

Please sign in to comment.