From 3501a9666c7b220a64efed3f37b7f6a89f49e76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Wed, 1 Apr 2015 15:25:07 +0200 Subject: [PATCH] 6403: add a rule for checking mapping key --- po/check_po | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) mode change 100755 => 100644 po/check_po diff --git a/po/check_po b/po/check_po old mode 100755 new mode 100644 index 15deca2d7..92b720957 --- a/po/check_po +++ b/po/check_po @@ -115,6 +115,38 @@ class Check_named_fmt( Check ): msgstr = msg.msgstr[1] self.__process( msg, msgid, msgstr ) +class Check_mapping_fmt( Check ): + # A pattern to find all {} + find_map_pat = re.compile('\{ \w+ \} \d* \D', re.VERBOSE) + + def __init__( self ): + Check.__init__( self ) + self.diag_header = "-------- {} name mismatches --------------" + self.summary_text = "{} name mismatches:" + + def __process( self, msg, msgid, msgstr ): + # Same number of named formats? + fmts1 = self.find_map_pat.findall( msgid ) + fmts2 = self.find_map_pat.findall( msgstr ) + if len( fmts1 ) != len( fmts2 ): + self.msgs.append( msg ) + else: + # Do we have the same named formats? + fmts1.sort() + fmts2.sort() + if fmts1 != fmts2: + self.msgs.append( msg ) + + def process( self, msg ): + msgid = msg.msgid + msgstr = msg.msgstr[0] + self.__process( msg, msgid, msgstr ) + + if msg.msgidp and len(msg.msgstr) >= 2: + msgid = msg.msgidp + msgstr = msg.msgstr[1] + self.__process( msg, msgid, msgstr ) + class Check_missing_sd( Check ): # A pattern to find %() without s or d # Here is a command to use for testing @@ -512,6 +544,7 @@ def analyze_msgs( options, fname, msgs, nr_templates = None, nth = 0 ): checks.append( Check_fmt( '%s' ) ) checks.append( Check_fmt( '%d' ) ) checks.append( Check_named_fmt() ) + checks.append( Check_mapping_fmt() ) checks.append( Check_missing_sd() ) checks.append( Check_runaway() ) checks.append( Check_xml_chars() )