tools/translation/helper/translation_helper.py
def _parse_translation_expectations(path):
  """Parses a translations expectations file.

  Example translations expectations file:
  {
    "desktop_grds": {
      "languages": ["es", "fr"],
      "files": [
        "ash/ash_strings.grd",
        "ui/strings/ui_strings.grd",
      ],
    },
    "android_grds": {
      "languages": ["de", "pt-BR"],
      "files": [
        "chrome/android/android_chrome_strings.grd",
      ],
    },
    "untranslated_grds": {
      "chrome/locale_settings.grd": "Not UI strings; localized separately",
      "chrome/locale_settings_mac.grd": "Not UI strings; localized separately",
    },
    "internal_grds": [
      "chrome/internal.grd",
    ],
  }

  Returns:
    A tuple (grd_to_langs, untranslated_grds, internal_grds).
    grd_to_langs maps each grd path to the list of languages into which
    that grd should be translated. untranslated_grds is a list of grds
    that "appear translatable" but should not be translated.
    internal_grds is a list of grds that are internal only and should
    not be read by this helper (since they might contain parts not
    available publicly).
  """
  with open(path) as f:
    file_contents = f.read()

  def assert_list_of_strings(l, name):
    assert isinstance(l, list) and all(isinstance(s, basestring) for s in l), (
        '%s must be a list of strings' % name)

  try:
    translations_expectations = ast.literal_eval(file_contents)
    assert isinstance(translations_expectations, dict), (
        '%s must be a python dict' % path)

    grd_to_langs = {}
    untranslated_grds = []
    internal_grds = []

    for group_name, settings in translations_expectations.items():
      if group_name == 'untranslated_grds':
        untranslated_grds = list(settings.keys())
        assert_list_of_strings(untranslated_grds, 'untranslated_grds')
        continue

      if group_name == 'internal_grds':
        internal_grds = settings
        assert_list_of_strings(internal_grds, 'internal_grds')
        continue

      languages = settings['languages']
      files = settings['files']
      assert_list_of_strings(languages, group_name + '.languages')
      assert_list_of_strings(files, group_name + '.files')
      for grd in files:
        grd_to_langs[grd] = languages

    return grd_to_langs, untranslated_grds, internal_grds

  except Exception:
    print('Error: failed to parse', path)
    raise
Parses a translations expectations file.

  Example translations expectations file:
  {
    "desktop_grds": {
      "languages": ["es", "fr"],
      "files": [
        "ash/ash_strings.grd",
        "ui/strings/ui_strings.grd",
      ],
    },
    "android_grds": {
      "languages": ["de", "pt-BR"],
      "files": [
        "chrome/android/android_chrome_strings.grd",
      ],
    },
    "untranslated_grds": {
      "chrome/locale_settings.grd": "Not UI strings; localized separately",
      "chrome/locale_settings_mac.grd": "Not UI strings; localized separately",
    },
    "internal_grds": [
      "chrome/internal.grd",
    ],
  }

  Returns:
    A tuple (grd_to_langs, untranslated_grds, internal_grds).
    grd_to_langs maps each grd path to the list of languages into which
    that grd should be translated. untranslated_grds is a list of grds
    that "appear translatable" but should not be translated.
    internal_grds is a list of grds that are internal only and should
    not be read by this helper (since they might contain parts not
    available publicly).
  
Parses a translations expectations file.
Parses a translations expectations file .
def _parse_translation_expectations(path):
  with open(path) as f:
    file_contents = f.read()
  def assert_list_of_strings(l, name):
    assert isinstance(l, list) and all(isinstance(s, basestring) for s in l), (
        '%s must be a list of strings' % name)
  try:
    translations_expectations = ast.literal_eval(file_contents)
    assert isinstance(translations_expectations, dict), (
        '%s must be a python dict' % path)
    grd_to_langs = {}
    untranslated_grds = []
    internal_grds = []
    for group_name, settings in translations_expectations.items():
      if group_name == 'untranslated_grds':
        untranslated_grds = list(settings.keys())
        assert_list_of_strings(untranslated_grds, 'untranslated_grds')
        continue
      if group_name == 'internal_grds':
        internal_grds = settings
        assert_list_of_strings(internal_grds, 'internal_grds')
        continue
      languages = settings['languages']
      files = settings['files']
      assert_list_of_strings(languages, group_name + '.languages')
      assert_list_of_strings(files, group_name + '.files')
      for grd in files:
        grd_to_langs[grd] = languages
    return grd_to_langs, untranslated_grds, internal_grds
  except Exception:
    print('Error: failed to parse', path)
    raise
def _parse_translation_expectations ( path ) : with open ( path ) as f : file_contents = f . read ( ) def assert_list_of_strings ( l , name ) : assert isinstance ( l , list ) and all ( isinstance ( s , basestring ) for s in l ) , ( '%s must be a list of strings' % name ) try : translations_expectations = ast . literal_eval ( file_contents ) assert isinstance ( translations_expectations , dict ) , ( '%s must be a python dict' % path ) grd_to_langs = { } untranslated_grds = [ ] internal_grds = [ ] for group_name , settings in translations_expectations . items ( ) : if group_name == 'untranslated_grds' : untranslated_grds = list ( settings . keys ( ) ) assert_list_of_strings ( untranslated_grds , 'untranslated_grds' ) continue if group_name == 'internal_grds' : internal_grds = settings assert_list_of_strings ( internal_grds , 'internal_grds' ) continue languages = settings [ 'languages' ] files = settings [ 'files' ] assert_list_of_strings ( languages , group_name + '.languages' ) assert_list_of_strings ( files , group_name + '.files' ) for grd in files : grd_to_langs [ grd ] = languages return grd_to_langs , untranslated_grds , internal_grds except Exception : print ( 'Error: failed to parse' , path ) raise
Parses a translations expectations file.
Parses a translations expectations file .
"""Parses a translations expectations file.

  Example translations expectations file:
  {
    "desktop_grds": {
      "languages": ["es", "fr"],
      "files": [
        "ash/ash_strings.grd",
        "ui/strings/ui_strings.grd",
      ],
    },
    "android_grds": {
      "languages": ["de", "pt-BR"],
      "files": [
        "chrome/android/android_chrome_strings.grd",
      ],
    },
    "untranslated_grds": {
      "chrome/locale_settings.grd": "Not UI strings; localized separately",
      "chrome/locale_settings_mac.grd": "Not UI strings; localized separately",
    },
    "internal_grds": [
      "chrome/internal.grd",
    ],
  }

  Returns:
    A tuple (grd_to_langs, untranslated_grds, internal_grds).
    grd_to_langs maps each grd path to the list of languages into which
    that grd should be translated. untranslated_grds is a list of grds
    that "appear translatable" but should not be translated.
    internal_grds is a list of grds that are internal only and should
    not be read by this helper (since they might contain parts not
    available publicly).
  """
A tuple (grd_to_langs, untranslated_grds, internal_grds).
grd_to_langs maps each grd path to the list of languages into which
that grd should be translated. untranslated_grds is a list of grds
that "appear translatable" but should not be translated.
internal_grds is a list of grds that are internal only and should
not be read by this helper (since they might contain parts not
available publicly).
A tuple ( grd_to_langs untranslated_grds internal_grds ) . grd_to_langs maps each grd path to the list of languages into which that grd should be translated . untranslated_grds is a list of grds that " appear translatable " but should not be translated . internal_grds is a list of grds that are internal only and should not be read by this helper ( since they might contain parts not available publicly ) .
path