From 649730244b6b17a86f0132c68fd51400192d28b6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 15:21:15 +0800 Subject: [PATCH 1/7] Override application locale with system default locale. --- atom/browser/atom_browser_client.cc | 5 +++++ atom/browser/atom_browser_client.h | 1 + 2 files changed, 6 insertions(+) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index c70b6812e..74b38d6b3 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -13,6 +13,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" +#include "ui/base/l10n/l10n_util.h" #include "webkit/common/webpreferences.h" namespace atom { @@ -88,6 +89,10 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation( return true; } +std::string AtomBrowserClient::GetApplicationLocale() { + return l10n_util::GetApplicationLocale(""); +} + void AtomBrowserClient::AppendExtraCommandLineSwitches( CommandLine* command_line, int child_process_id) { diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 89360fa95..8111af472 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -25,6 +25,7 @@ class AtomBrowserClient : public brightray::BrowserClient { content::SiteInstance* site_instance, const GURL& current_url, const GURL& new_url) OVERRIDE; + virtual std::string GetApplicationLocale() OVERRIDE; virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, int child_process_id) OVERRIDE; From 162e47ca15d11fc14cc403d54dcceb6e7dcd512d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 15:54:25 +0800 Subject: [PATCH 2/7] Initialize locale on mac. --- atom/browser/atom_browser_main_parts_mac.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/atom/browser/atom_browser_main_parts_mac.mm b/atom/browser/atom_browser_main_parts_mac.mm index 6174cfb52..d5b23aef4 100644 --- a/atom/browser/atom_browser_main_parts_mac.mm +++ b/atom/browser/atom_browser_main_parts_mac.mm @@ -8,11 +8,15 @@ #import "atom/browser/mac/atom_application_delegate.h" #include "base/files/file_path.h" #import "base/mac/foundation_util.h" +#include "ui/base/l10n/l10n_util_mac.h" #import "vendor/brightray/common/mac/main_application_bundle.h" namespace atom { void AtomBrowserMainParts::PreMainMessageLoopStart() { + // Initialize locale setting. + l10n_util::OverrideLocaleWithCocoaLocale(); + // Force the NSApplication subclass to be used. NSApplication* application = [AtomApplication sharedApplication]; From 7bd0c8aa06103b2767496219f5f712423b14b6ae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 15:54:45 +0800 Subject: [PATCH 3/7] mac: Create .lproj files for each locale. --- atom.gyp | 22 +++++++++++++++++++- tools/mac/make_locale_dirs.sh | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 tools/mac/make_locale_dirs.sh diff --git a/atom.gyp b/atom.gyp index 335b021c4..ddc2a6b37 100644 --- a/atom.gyp +++ b/atom.gyp @@ -221,6 +221,7 @@ 'atom/app/atom_library_main.cc', 'atom/app/atom_library_main.h', ], + 'atom_source_root': '& 2 + exit 1 +fi + +RESOURCES_DIR="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ ! -d "${RESOURCES_DIR}" ]]; then + mkdir "${RESOURCES_DIR}" +fi + +cd "${RESOURCES_DIR}" + +for dir in "${@}"; do + if [[ ! -d "${dir}.lproj" ]]; then + mkdir "${dir}.lproj" + fi +done From f57bcfc4294bafb72fad9d264c33b3e68d8f9422 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 17:13:24 +0800 Subject: [PATCH 4/7] mac: Fix en-US locale. --- atom.gyp | 24 ++++++++++++------- tools/mac/apply_locales.py | 45 +++++++++++++++++++++++++++++++++++ tools/mac/make_locale_dirs.sh | 4 ++-- 3 files changed, 62 insertions(+), 11 deletions(-) create mode 100755 tools/mac/apply_locales.py diff --git a/atom.gyp b/atom.gyp index ddc2a6b37..211e0347f 100644 --- a/atom.gyp +++ b/atom.gyp @@ -221,6 +221,14 @@ 'atom/app/atom_library_main.cc', 'atom/app/atom_library_main.h', ], + 'locales': [ + 'am', 'ar', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en-GB', + 'en-US', 'es-419', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'gu', 'he', + 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'kn', 'ko', 'lt', 'lv', + 'ml', 'mr', 'ms', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', + 'sk', 'sl', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tr', 'uk', + 'vi', 'zh-CN', 'zh-TW', + ], 'atom_source_root': '!@(<(apply_locales_cmd) -d ZZLOCALE.lproj <(locales))', + ], + }, 'action': [ 'tools/mac/make_locale_dirs.sh', - '<@(locales)', + '<@(locale_dirs)', ], }, ] diff --git a/tools/mac/apply_locales.py b/tools/mac/apply_locales.py new file mode 100755 index 000000000..a657aa7ef --- /dev/null +++ b/tools/mac/apply_locales.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# TODO: remove this script when GYP has for loops + +import sys +import optparse + +def main(argv): + + parser = optparse.OptionParser() + usage = 'usage: %s [options ...] format_string 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) < 3: + print 'ERROR: need string and list of locales' + return 1 + + str_template = arglist[1] + locales = arglist[2:] + + results = [] + 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). + if options.dash_to_underscore: + if locale == 'en-US': + locale = 'en' + locale = locale.replace('-', '_') + results.append(str_template.replace('ZZLOCALE', locale)) + + # Quote each element so filename spaces don't mess up GYP's attempt to parse + # it into a list. + print ' '.join(["'%s'" % x for x in results]) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) \ No newline at end of file diff --git a/tools/mac/make_locale_dirs.sh b/tools/mac/make_locale_dirs.sh index c479b653d..7636b15e6 100755 --- a/tools/mac/make_locale_dirs.sh +++ b/tools/mac/make_locale_dirs.sh @@ -33,7 +33,7 @@ fi cd "${RESOURCES_DIR}" for dir in "${@}"; do - if [[ ! -d "${dir}.lproj" ]]; then - mkdir "${dir}.lproj" + if [[ ! -d "${dir}" ]]; then + mkdir "${dir}" fi done From 16bc7f10c165160632ad2e5c300eb773edbabdfa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 19:08:59 +0800 Subject: [PATCH 5/7] Generate .pak for each locale. --- atom.gyp | 32 ++++++++++++++++++++++++++++++-- script/create-dist.py | 2 ++ tools/posix/make_locale_paks.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 tools/posix/make_locale_paks.sh diff --git a/atom.gyp b/atom.gyp index 211e0347f..3c95bf090 100644 --- a/atom.gyp +++ b/atom.gyp @@ -344,7 +344,11 @@ ], }, ] - }], # OS=="mac" + }, { # OS=="mac" + 'dependencies': [ + 'make_locale_paks', + ], + }], # OS!="mac" ['OS=="win"', { 'copies': [ { @@ -700,7 +704,31 @@ }, }, # target helper ], - }], # OS==Mac + }, { # OS=="mac" + 'targets': [ + { + 'target_name': 'make_locale_paks', + 'type': 'none', + 'actions': [ + { + 'action_name': 'Make Empty Paks', + 'inputs': [ + 'tools/posix/make_locale_paks.sh', + ], + 'outputs': [ + '<(PRODUCT_DIR)/locales' + ], + 'action': [ + 'tools/posix/make_locale_paks.sh', + '<(PRODUCT_DIR)', + '<@(locales)', + ], + 'msvs_cygwin_shell': 0, + }, + ], + }, + ], + }], # OS!="mac" ['OS=="win"', { 'targets': [ { diff --git a/script/create-dist.py b/script/create-dist.py index 3354b65cc..ba9b0f526 100755 --- a/script/create-dist.py +++ b/script/create-dist.py @@ -62,9 +62,11 @@ TARGET_DIRECTORIES = { ], 'win32': [ 'resources', + 'locales', ], 'linux': [ 'resources', + 'locales', ], } diff --git a/tools/posix/make_locale_paks.sh b/tools/posix/make_locale_paks.sh new file mode 100755 index 000000000..6f66a04e8 --- /dev/null +++ b/tools/posix/make_locale_paks.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# usage: make_locale_paks locale_dir [...] +# +# This script creates the .pak files under locales directory, it is used to fool +# the ResourcesBundle that the locale is available. + +set -eu + +if [[ ${#} -eq 0 ]]; then + echo "usage: ${0} build_dir [locale_pak...]" >& 2 + exit 1 +fi + +PRODUCT_DIR="$1" +shift + +LOCALES_DIR="${PRODUCT_DIR}/locales" +if [[ ! -d "${LOCALES_DIR}" ]]; then + mkdir "${LOCALES_DIR}" +fi + +cd "${LOCALES_DIR}" + +for pak in "${@}"; do + if [[ ! -f "${pak}.pak" ]]; then + touch "${pak}.pak" + fi +done From b073d35918ad8c898883630aa7c406cfcb33188c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 20:23:28 +0800 Subject: [PATCH 6/7] Add spec for application locale. --- spec/chromium-spec.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index 5e5d37595..e0695b58e 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -27,6 +27,10 @@ describe 'chromium feature', -> -> done() -> done() + describe 'navigator.language', -> + it 'should not be empty', -> + assert.notEqual navigator.language, '' + describe 'window.open', -> it 'returns a BrowserWindow object', -> b = window.open 'about:blank', 'test', 'show=no' From 2da5bcb0b8839efac3660876c97437ca4bb9d3d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 May 2014 21:24:22 +0800 Subject: [PATCH 7/7] Fix cpplint warning. --- atom/browser/atom_browser_client.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 8111af472..10ae1b0c7 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -5,6 +5,8 @@ #ifndef ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_ #define ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_ +#include + #include "brightray/browser/browser_client.h" namespace atom {