From 5514e8927666ce499248726c66a2132ff04f87a3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 8 Jan 2016 12:38:00 +0800 Subject: [PATCH] Copy locales in Cocoa format --- atom.gyp | 11 +++++++- tools/mac/copy-locales.py | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 tools/mac/copy-locales.py diff --git a/atom.gyp b/atom.gyp index 83605eedbc0d..eb4302d74c27 100644 --- a/atom.gyp +++ b/atom.gyp @@ -432,7 +432,6 @@ 'mac_bundle': 1, 'mac_bundle_resources': [ 'atom/common/resources/mac/MainMenu.xib', - '<(libchromiumcontent_dir)/locales', '<(libchromiumcontent_dir)/content_shell.pak', '<(libchromiumcontent_dir)/icudtl.dat', '<(libchromiumcontent_dir)/natives_blob.bin', @@ -501,6 +500,16 @@ 'Libraries', ], }, + { + 'postbuild_name': 'Copy locales', + 'action': [ + 'tools/mac/copy-locales.py', + '-d', + '<(libchromiumcontent_dir)/locales', + '${BUILT_PRODUCTS_DIR}/<(product_name) Framework.framework/Resources', + '<@(locales)', + ], + }, ], 'conditions': [ ['mas_build==0', { diff --git a/tools/mac/copy-locales.py b/tools/mac/copy-locales.py new file mode 100755 index 000000000000..30d478800694 --- /dev/null +++ b/tools/mac/copy-locales.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# Copyright (c) 2013 GitHub, Inc. +# Use of this source code is governed by the MIT license that can be +# found in the LICENSE file. + +import errno +import optparse +import os +import shutil +import sys + +def main(argv): + parser = optparse.OptionParser() + usage = 'usage: %s [options ...] src dest locale_list' + parser.set_usage(usage.replace('%s', '%prog')) + parser.add_option('-d', dest='dash_to_underscore', action="store_true", + default=False, + help='map "en-US" to "en" and "-" to "_" in locales') + + (options, arglist) = parser.parse_args(argv) + + if len(arglist) < 4: + print 'ERROR: need src, dest and list of locales' + return 1 + + src = arglist[1] + dest = arglist[2] + locales = arglist[3:] + + for locale in locales: + # For Cocoa to find the locale at runtime, it needs to use '_' instead + # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented + # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). + dirname = locale + if options.dash_to_underscore: + if locale == 'en-US': + dirname = 'en' + else: + dirname = locale.replace('-', '_') + + dirname = os.path.join(dest, dirname + '.lproj') + safe_mkdir(dirname) + shutil.copy2(os.path.join(src, locale + '.pak'), + os.path.join(dirname, 'locale.pak')) + + +def safe_mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +if __name__ == '__main__': + sys.exit(main(sys.argv))