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