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