Esempio n. 1
0
def fixupLocales(params, files):
  global defaultLocale

  # Read in default locale data, it might not be included in files
  defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']), defaultLocale)
  reference = {}
  ignoredFiles = getIgnoredFiles(params)
  for file in os.listdir(defaultLocaleDir):
    path = os.path.join(defaultLocaleDir, file)
    if file in ignoredFiles or not os.path.isfile(path):
      continue
    data = localeTools.readFile(path)
    if data:
      reference[file] = data

  for locale in params['locales']:
    for file in reference.iterkeys():
      path = 'chrome/locale/%s/%s' % (locale, file)
      if path in files:
        data = localeTools.parseString(files[path].decode('utf-8'), path)
        for key, value in reference[file].iteritems():
          if not key in data:
            files[path] += localeTools.generateStringEntry(key, value, path).encode('utf-8')
      else:
        files[path] = reference[file]['_origData'].encode('utf-8')
def fixupLocales(params, files):
    global defaultLocale

    # Read in default locale data, it might not be included in package files
    defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']),
                                    defaultLocale)
    reference_files = Files(getPackageFiles(params), getIgnoredFiles(params))
    reference_files.read(defaultLocaleDir,
                         archive_path(defaultLocaleDir, params['baseDir']))
    reference_params = dict(params)
    reference_params['locales'] = [defaultLocale]
    importLocales(reference_params, reference_files)

    reference = {}
    for path, data in reference_files.iteritems():
        filename = path.split('/')[-1]
        data = localeTools.parseString(data.decode('utf-8'), filename)
        if data:
            reference[filename] = data

    for locale in params['locales']:
        for file in reference.iterkeys():
            path = 'chrome/locale/%s/%s' % (locale, file)
            if path in files:
                data = localeTools.parseString(files[path].decode('utf-8'),
                                               path)
                for key, value in reference[file].iteritems():
                    if not key in data:
                        files[path] += localeTools.generateStringEntry(
                            key, value, path).encode('utf-8')
            else:
                files[path] = reference[file]['_origData'].encode('utf-8')
def importLocales(params, files):
    SECTION = 'import_locales'
    if not params['metadata'].has_section(SECTION):
        return

    import localeTools

    for locale in params['locales']:
        for item in params['metadata'].items(SECTION):
            path, keys = item
            parts = [locale if p == '*' else p for p in path.split('/')]
            source = os.path.join(os.path.dirname(item.source), *parts)
            if not os.path.exists(source):
                continue

            with io.open(source, 'r', encoding='utf-8') as handle:
                data = json.load(handle)

            target_name = os.path.splitext(
                os.path.basename(source))[0] + '.properties'
            target = archive_path(
                os.path.join(getLocalesDir(params['baseDir']), locale,
                             target_name), params['baseDir'])

            files[target] = ''
            for key, value in sorted(data.items()):
                message = value['message']
                files[target] += localeTools.generateStringEntry(
                    key, message, target).encode('utf-8')
Esempio n. 4
0
def fixupLocales(params, files):
  global defaultLocale

  # Read in default locale data, it might not be included in package files
  defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']), defaultLocale)
  reference_files = Files(getPackageFiles(params), getIgnoredFiles(params))
  reference_files.read(defaultLocaleDir, archive_path(defaultLocaleDir, params['baseDir']))
  reference_params = dict(params)
  reference_params['locales'] = [defaultLocale]
  importLocales(reference_params, reference_files)

  reference = {}
  for path, data in reference_files.iteritems():
    filename = path.split('/')[-1]
    data = localeTools.parseString(data.decode('utf-8'), filename)
    if data:
      reference[filename] = data

  for locale in params['locales']:
    for file in reference.iterkeys():
      path = 'chrome/locale/%s/%s' % (locale, file)
      if path in files:
        data = localeTools.parseString(files[path].decode('utf-8'), path)
        for key, value in reference[file].iteritems():
          if not key in data:
            files[path] += localeTools.generateStringEntry(key, value, path).encode('utf-8')
      else:
        files[path] = reference[file]['_origData'].encode('utf-8')
Esempio n. 5
0
def importLocales(params, files):
  SECTION = 'import_locales'
  if not params['metadata'].has_section(SECTION):
    return

  import localeTools

  for locale in params['locales']:
    for item in params['metadata'].items(SECTION):
      path, keys = item
      parts = [locale if p == '*' else p for p in path.split('/')]
      source = os.path.join(os.path.dirname(item.source), *parts)
      if not os.path.exists(source):
        continue

      with io.open(source, 'r', encoding='utf-8') as handle:
        data = json.load(handle)

      target_name = os.path.splitext(os.path.basename(source))[0] + '.properties'
      target = archive_path(os.path.join(getLocalesDir(params['baseDir']), locale, target_name), params['baseDir'])

      files[target] = ''
      for key, value in sorted(data.items()):
        message = value['message']
        files[target] += localeTools.generateStringEntry(key, message, target).encode('utf-8')
def fixupLocales(params, files):
  global defaultLocale

  # Read in default locale data, it might not be included in files
  defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']), defaultLocale)
  reference = {}
  ignoredFiles = getIgnoredFiles(params)
  for file in os.listdir(defaultLocaleDir):
    path = os.path.join(defaultLocaleDir, file)
    if file in ignoredFiles or not os.path.isfile(path):
      continue
    data = localeTools.readFile(path)
    if data:
      reference[file] = data

  for locale in params['locales']:
    for file in reference.iterkeys():
      path = 'chrome/locale/%s/%s' % (locale, file)
      if path in files:
        data = localeTools.parseString(files[path].decode('utf-8'), path)
        for key, value in reference[file].iteritems():
          if not key in data:
            files[path] += localeTools.generateStringEntry(key, value, path).encode('utf-8')
      else:
        files[path] = reference[file]['_origData'].encode('utf-8')