apply_locales.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # TODO: remove this script when GYP has for loops
  6. import sys
  7. import optparse
  8. def main(argv):
  9. parser = optparse.OptionParser()
  10. usage = 'usage: %s [options ...] format_string locale_list'
  11. parser.set_usage(usage.replace('%s', '%prog'))
  12. parser.add_option('-d', dest='dash_to_underscore', action="store_true",
  13. default=False,
  14. help='map "en-US" to "en" and "-" to "_" in locales')
  15. (options, arglist) = parser.parse_args(argv)
  16. if len(arglist) < 3:
  17. print 'ERROR: need string and list of locales'
  18. return 1
  19. str_template = arglist[1]
  20. locales = arglist[2:]
  21. results = []
  22. for locale in locales:
  23. # For Cocoa to find the locale at runtime, it needs to use '_' instead
  24. # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented
  25. # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578).
  26. if options.dash_to_underscore:
  27. if locale == 'en-US':
  28. locale = 'en'
  29. locale = locale.replace('-', '_')
  30. results.append(str_template.replace('ZZLOCALE', locale))
  31. # Quote each element so filename spaces don't mess up GYP's attempt to parse
  32. # it into a list.
  33. print ' '.join(["'%s'" % x for x in results])
  34. if __name__ == '__main__':
  35. sys.exit(main(sys.argv))