def check_placeholders(str1, str2): """ Checks whether placeholder strings match """ result = True, '' # Find the patterns in source and translation splitter1 = Splitter(str1) splitter2 = Splitter(str2) p1 = text_only([item for item in splitter1.split() if item.genus == 'placeholder']) p2 = text_only([item for item in splitter2.split() if item.genus == 'placeholder']) if len(p1) > 0: result1 = p1[:] result2 = [] for item in p2: if item in result1: result1.remove(item) else: result2.append(item) if result1 == [] and result2 != []: result = False, _(u'The translation contains some more placeholders than the source: %(strings)s.') % {'strings': ', '.join(result2)} elif result1 != [] and result2 == []: result = False, _(u'The source contains some more placeholders the translation is missing: %(strings)s.') % {'strings': ', '.join(result1)} elif result1 != [] and result2 != []: result = False, _(u'The placeholders from translation (%(t_strings)s) do not match those in source (%(s_strings)s).') % {'s_strings': ', '.join(result1), 't_strings': ', '.join(result2)} else: # No patterns in source if len(p2) > 0: result = False, _(u'There are no placeholders in source.') return result
def check_xmltags_PATTERNS(str1, str2): """ Checks that XML/HTML tags have not been translated """ result = True, '' # Find the tags in source and translation splitter1 = Splitter(str1) splitter2 = Splitter(str2) tags1 = text_only([item for item in splitter1.split() if item.genus == 'syntax' and item.species == 'xml']) tags2 = text_only([item for item in splitter2.split() if item.genus == 'syntax' and item.species == 'xml']) if len(tags1) > 0: result1 = tags1[:] result2 = [] for item in tags2: if item in result1: result1.remove(item) else: result2.append(item) if result1 == [] and result2 != []: result = False, _(u'The translation contains some more XML tags than the source: %(strings)s.') % {'strings': ', '.join(result2)} elif result1 != [] and result2 == []: result = False, _(u'The source contains some more XML tags the translation is missing: %(strings)s.') % {'strings': ', '.join(result1)} elif result1 != [] and result2 != []: result = False, _(u'The XML tags from translation (%(t_strings)s) do not match those in source (%(s_strings)s).') % {'s_strings': ', '.join(result1), 't_strings': ', '.join(result2)} else: # No patterns in source if len(tags2) > 0: result = False, _(u'There are no XML tags in source.') return result
def highlight(message, threshold = 3): """ Highlight """ splitnodes = Splitter(message) return ''.join([node.highlight() for node in splitnodes.split()])