Bugfix: update-translations: Allow numerus translations to omit %n specifier (usually when it only has one possible value)
Github-Pull: #7253 Rebased-From: 0d595894f028248a1a1b00491dad95320844c685
This commit is contained in:
parent
bdd0f9e286
commit
a75a03a5f2
@ -72,7 +72,7 @@ def sanitize_string(s):
|
|||||||
'''Sanitize string for printing'''
|
'''Sanitize string for printing'''
|
||||||
return s.replace('\n',' ')
|
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))
|
source_f = split_format_specifiers(find_format_specifiers(source))
|
||||||
# assert that no source messages contain both Qt and strprintf format specifiers
|
# 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!
|
# if this fails, go change the source as this is hacky and confusing!
|
||||||
@ -80,10 +80,13 @@ def check_format_specifiers(source, translation, errors):
|
|||||||
try:
|
try:
|
||||||
translation_f = split_format_specifiers(find_format_specifiers(translation))
|
translation_f = split_format_specifiers(find_format_specifiers(translation))
|
||||||
except IndexError:
|
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
|
return False
|
||||||
else:
|
else:
|
||||||
if source_f != translation_f:
|
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)))
|
errors.append("Mismatch between '%s' and '%s'" % (sanitize_string(source), sanitize_string(translation)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -150,7 +153,7 @@ def postprocess_translations(reduce_diff_hacks=False):
|
|||||||
if translation is None:
|
if translation is None:
|
||||||
continue
|
continue
|
||||||
errors = []
|
errors = []
|
||||||
valid = check_format_specifiers(source, translation, errors)
|
valid = check_format_specifiers(source, translation, errors, numerus)
|
||||||
|
|
||||||
for error in errors:
|
for error in errors:
|
||||||
print('%s: %s' % (filename, error))
|
print('%s: %s' % (filename, error))
|
||||||
|
Loading…
Reference in New Issue
Block a user