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 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')