def match_to_source(source, *translations):
 first = True
 best_crc = None
 for translation in translations:
  if (translation is None):
   continue
  if translation.number_replacement:
   current_string = number_replace(source.string, translation.string)
   current_source = number_replace(source.string, translation.source)
   current_crc = crc(current_source)
  elif ('{num}' in translation.string):
   print((u'Warning: {num} appears in %s, but not marked for number replacement. Discarding!' % translation))
   continue
  else:
   current_string = translation.string
   current_source = translation.source
   current_crc = translation.source_crc
  if translation.fuzzy:
   match = False
  elif translation.official:
   match = True
  elif current_source:
   match = (source.string == current_source)
  else:
   match = (current_crc == crc(source.string))
  if (first or match):
   best_string = current_string
   best_crc = current_crc
  if match:
   break
  first = False
 if best_crc:
  return (source, best_crc, best_string, match)
 else:
  return (source, None, None, None)

def match_to_source ( source , * translations ) : first = True best_crc = None for translation in translations : if ( translation is None ) : continue if translation . number_replacement : current_string = number_replace ( source . string , translation . string ) current_source = number_replace ( source . string , translation . source ) current_crc = crc ( current_source ) elif ( '{num}' in translation . string ) : print ( ( u'Warning: {num} appears in %s, but not marked for number replacement. Discarding!' % translation ) ) continue else : current_string = translation . string current_source = translation . source current_crc = translation . source_crc if translation . fuzzy : match = False elif translation . official : match = True elif current_source : match = ( source . string == current_source ) else : match = ( current_crc == crc ( source . string ) ) if ( first or match ) : best_string = current_string best_crc = current_crc if match : break first = False if best_crc : return ( source , best_crc , best_string , match ) else : return ( source , None , None , None )
matches translated string(s) to source the first translation whose source matches the source message .