def get_sample_and_attrib(lang_scr):
  """Return a tuple of:
  - a short sample text string
  - an attribution key, one of
    UN: official UN translation, needs attribution
    other: not an official UN translation, needs non-attribution
    original: public domain translation, does not need attribution
    none: we have no attribution info on this, does not need attribution
  - source key"""
  assert '-' in lang_scr
  DEBUG = lang_scr.startswith('tab-')

  sample_text = get_sample_from_sample_file(lang_scr)
  if sample_text is not None:
    attr = get_attribution(lang_scr)
    src_key = 'txt-' + lang_scr
    return sample_text, attr, src_key

  exemplar, src_key = cldr_data.get_exemplar_and_source(lang_scr)
  if exemplar is not None:
    return sample_text_from_exemplar(exemplar), 'none', src_key

  _, script = lang_scr.split('-')
  src_key = 'und-' + script
  sample_text = get_sample_from_sample_file(src_key)
  if sample_text is not None:
    return sample_text, 'none', src_key

  print 'No sample for %s' % lang_scr
  return '', 'none', 'none'
Esempio n. 2
0
def get_sample_and_attrib(lang_scr):
    """Return a tuple of:
  - a short sample text string
  - an attribution key, one of
    UN: official UN translation, needs attribution
    other: not an official UN translation, needs non-attribution
    original: public domain translation, does not need attribution
    none: we have no attribution info on this, does not need attribution
  - source key"""
    assert '-' in lang_scr
    DEBUG = lang_scr.startswith('tab-')

    sample_text = get_sample_from_sample_file(lang_scr)
    if sample_text is not None:
        attr = get_attribution(lang_scr)
        src_key = 'txt-' + lang_scr
        return sample_text, attr, src_key

    exemplar, src_key = cldr_data.get_exemplar_and_source(lang_scr)
    if exemplar is not None:
        return sample_text_from_exemplar(exemplar), 'none', src_key

    _, script = lang_scr.split('-')
    src_key = 'und-' + script
    sample_text = get_sample_from_sample_file(src_key)
    if sample_text is not None:
        return sample_text, 'none', src_key

    print 'No sample for %s' % lang_scr
    return '', 'none', 'none'
Esempio n. 3
0
def get_sample_infos(lang_scr):
  """Return a list of tuples of:
  - a short sample text string
  - an attribution key, one of
    UN: official UN translation, needs attribution
    other: not an official UN translation, needs non-attribution
    original: public domain translation, does not need attribution
    none: we have no attribution info on this, does not need attribution
  - source key.
  The list is in order of priority: language texts, udhr samples, exemplars for
  the language, sample text for the script, exemplars for the script."""

  assert '-' in lang_scr

  sample_infos = []
  sample_text = get_sample_from_sample_file(lang_scr + '_text')
  if sample_text is not None:
    src_key = lang_scr + '_text'
    attr = get_attribution(src_key)
    sample_infos.append((sample_text, attr, src_key))

  sample_text = get_sample_from_sample_file(lang_scr + '_udhr')
  if sample_text is not None:
    src_key = lang_scr + '_udhr'
    attr = get_attribution(src_key)
    sample_infos.append((sample_text, attr, src_key))

  lang, script = lang_scr.split('-')
  if lang != 'und':
    exemplar, src_key = cldr_data.get_exemplar_and_source(lang_scr)
    if exemplar is not None:
      sample_infos.append(
          (sample_text_from_exemplar(exemplar), 'none', src_key))

  src_key = 'und-' + script + '_chars'
  sample_text = get_sample_from_sample_file(src_key)
  if sample_text is not None:
    sample_infos.append((sample_text, 'none', src_key))

  exemplar, src_key = cldr_data.get_exemplar_and_source('und-' + script)
  if exemplar is not None:
    sample_infos.append((sample_text_from_exemplar(exemplar), 'none', src_key))

  if not sample_infos:
    print '!No sample info for %s' % lang_scr

  return sample_infos
def get_sample_infos(lang_scr):
  """Return a list of tuples of:
  - a short sample text string
  - an attribution key, one of
    UN: official UN translation, needs attribution
    other: not an official UN translation, needs non-attribution
    original: public domain translation, does not need attribution
    none: we have no attribution info on this, does not need attribution
  - source key.
  The list is in order of priority: language texts, udhr samples, exemplars for
  the language, sample text for the script, exemplars for the script."""

  assert '-' in lang_scr

  sample_infos = []
  sample_text = get_sample_from_sample_file(lang_scr + '_text')
  if sample_text is not None:
    src_key = lang_scr + '_text'
    attr = get_attribution(src_key)
    sample_infos.append((sample_text, attr, src_key))

  sample_text = get_sample_from_sample_file(lang_scr + '_udhr')
  if sample_text is not None:
    src_key = lang_scr + '_udhr'
    attr = get_attribution(src_key)
    sample_infos.append((sample_text, attr, src_key))

  lang, script = lang_scr.split('-')
  if lang != 'und':
    exemplar, src_key = cldr_data.get_exemplar_and_source(lang_scr)
    if exemplar is not None:
      sample_infos.append(
          (sample_text_from_exemplar(exemplar), 'none', src_key))

  src_key = 'und-' + script + '_chars'
  sample_text = get_sample_from_sample_file(src_key)
  if sample_text is not None:
    sample_infos.append((sample_text, 'none', src_key))

  exemplar, src_key = cldr_data.get_exemplar_and_source('und-' + script)
  if exemplar is not None:
    sample_infos.append((sample_text_from_exemplar(exemplar), 'none', src_key))

  if not sample_infos:
    print '!No sample info for %s' % lang_scr

  return sample_infos