[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 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 | |
| 6 | # TODO: remove this script when GYP has for loops |
| 7 | |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 8 | from __future__ import print_function |
| 9 | |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 10 | import sys |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 11 | import optparse |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 12 | |
| 13 | def main(argv): |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 14 | |
| 15 | parser = optparse.OptionParser() |
| 16 | usage = 'usage: %s [options ...] format_string locale_list' |
| 17 | parser.set_usage(usage.replace('%s', '%prog')) |
| 18 | parser.add_option('-d', dest='dash_to_underscore', action="store_true", |
[email protected] | e2260ed | 2009-11-04 14:42:19 | [diff] [blame] | 19 | default=False, |
| 20 | help='map "en-US" to "en" and "-" to "_" in locales') |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 21 | |
| 22 | (options, arglist) = parser.parse_args(argv) |
| 23 | |
| 24 | if len(arglist) < 3: |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 25 | print('ERROR: need string and list of locales') |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 26 | return 1 |
| 27 | |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 28 | str_template = arglist[1] |
| 29 | locales = arglist[2:] |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 30 | |
| 31 | results = [] |
| 32 | for locale in locales: |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 33 | # For Cocoa to find the locale at runtime, it needs to use '_' instead |
[email protected] | e2260ed | 2009-11-04 14:42:19 | [diff] [blame] | 34 | # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented |
| 35 | # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 36 | if options.dash_to_underscore: |
[email protected] | e2260ed | 2009-11-04 14:42:19 | [diff] [blame] | 37 | if locale == 'en-US': |
| 38 | locale = 'en' |
[email protected] | 464dca7 | 2009-09-02 21:31:57 | [diff] [blame] | 39 | locale = locale.replace('-', '_') |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 40 | results.append(str_template.replace('ZZLOCALE', locale)) |
| 41 | |
| 42 | # Quote each element so filename spaces don't mess up GYP's attempt to parse |
| 43 | # it into a list. |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 44 | print(' '.join(["'%s'" % x for x in results])) |
| 45 | |
[email protected] | a2126d5e | 2009-08-24 16:43:04 | [diff] [blame] | 46 | |
| 47 | if __name__ == '__main__': |
| 48 | sys.exit(main(sys.argv)) |