diff --git a/atom.gyp b/atom.gyp index 335b021c4..3c95bf090 100644 --- a/atom.gyp +++ b/atom.gyp @@ -221,6 +221,15 @@ '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', + '<@(locale_dirs)', + ], + }, ] - }], # OS=="mac" + }, { # OS=="mac" + 'dependencies': [ + 'make_locale_paks', + ], + }], # OS!="mac" ['OS=="win"', { 'copies': [ { @@ -674,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/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..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 { @@ -25,6 +27,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; 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]; 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/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' 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 new file mode 100755 index 000000000..7636b15e6 --- /dev/null +++ b/tools/mac/make_locale_dirs.sh @@ -0,0 +1,39 @@ +#!/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_dirs.sh locale_dir [...] +# +# This script creates the Resources directory for the bundle being built by +# the Xcode target that calls it if the directory does not yet exist. It then +# changes to that directory and creates subdirectories for each locale_dir +# passed on the command line. +# +# This script is intended to create empty locale directories (.lproj) in a +# Cocoa .app bundle. The presence of these empty directories is sufficient to +# convince Cocoa that the application supports the named localization, even if +# an InfoPlist.strings file is not provided. Chrome uses these empty locale +# directoires for its helper executable bundles, which do not otherwise +# require any direct Cocoa locale support. + +set -eu + +if [[ ${#} -eq 0 ]]; then + echo "usage: ${0} locale_dir [...]" >& 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}" ]]; then + mkdir "${dir}" + fi +done 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