def _create_lang_script_to_names(lang_script_data):
  """Generate a map from lang-script to English (and possibly native) names.
  Whether the script is included in the name depends on the number of used
  and unused scripts.  If there's one used script, that script is omitted.
  Else if there's no used script and one unused script, that script is
  omitted.  Else the script is included.  If there's no English name for
  the lang_script, it is excluded.
  """

  lang_to_names = {}
  for lang in lang_script_data:
    used, unused = lang_script_data[lang]
    if len(used) == 1:
      exclude_script = iter(used).next()
    elif not used and len(unused) == 1:
      exclude_script = iter(unused).next()
    else:
      exclude_script = ''

    for script in (used | unused):
      lang_script = lang + '-' + script
      target = lang if script == exclude_script else lang_script
      # special case, not generally useful
      if target.startswith('und-'):
        en_name =  cldr_data.get_english_script_name(target[4:]) + ' script'
      else:
        en_name = cldr_data.get_english_language_name(target)
      if not en_name:
        # Easier than patching the cldr_data, not sure I want to go there.
        if lang_script == 'tlh-Piqd':
          en_name = u'Klingon'
        else:
          _log('No english name for %s' % lang_script)
          continue
      native_name = cldr_data.get_native_language_name(
          lang_script, exclude_script)
      if native_name == en_name:
        native_name = None
      lang_to_names[lang_script] = (
          [en_name, native_name] if native_name else [en_name])

  return lang_to_names
dataset/ETHPy150Open googlei18n/nototools/nototools/lang_data.py/_create_lang_script_to_names/original