def extract_translations(file_obj):
 xpi = get_filepath(file_obj)
 messages = {}
 try:
  with zipfile.ZipFile(xpi, 'r') as source:
   file_list = source.namelist()
   locales = {name.split('/')[1] for name in file_list if (name.startswith('_locales/') and name.endswith('/messages.json'))}
   for locale in locales:
    corrected_locale = find_language(locale)
    if (not corrected_locale):
     continue
    fname = '_locales/{0}/messages.json'.format(locale)
    try:
     data = source.read(fname)
     messages[corrected_locale] = decode_json(data)
    except KeyError:
     continue
 except IOError:
  pass
 return messages

def extract_translations ( file_obj ) : xpi = get_filepath ( file_obj ) messages = { } try : with zipfile . ZipFile ( xpi , 'r' ) as source : file_list = source . namelist ( ) locales = { name . split ( '/' ) [ 1 ] for name in file_list if ( name . startswith ( '_locales/' ) and name . endswith ( '/messages.json' ) ) } for locale in locales : corrected_locale = find_language ( locale ) if ( not corrected_locale ) : continue fname = '_locales/{0}/messages.json' . format ( locale ) try : data = source . read ( fname ) messages [ corrected_locale ] = decode_json ( data ) except KeyError : continue except IOError : pass return messages
extract all translation messages from file_obj .