Merge pull request #363 from atom/application-locale
Implement navigator.language
This commit is contained in:
commit
c7d0da2cfd
9 changed files with 192 additions and 3 deletions
60
atom.gyp
60
atom.gyp
|
@ -221,6 +221,15 @@
|
||||||
'atom/app/atom_library_main.cc',
|
'atom/app/atom_library_main.cc',
|
||||||
'atom/app/atom_library_main.h',
|
'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': '<!(python tools/atom_source_root.py)',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS=="win"', {
|
['OS=="win"', {
|
||||||
'app_sources': [
|
'app_sources': [
|
||||||
|
@ -230,8 +239,10 @@
|
||||||
'<(libchromiumcontent_src_dir)/content/app/startup_helper_win.cc',
|
'<(libchromiumcontent_src_dir)/content/app/startup_helper_win.cc',
|
||||||
],
|
],
|
||||||
}], # OS=="win"
|
}], # OS=="win"
|
||||||
|
['OS=="mac"', {
|
||||||
|
'apply_locales_cmd': ['python', 'tools/mac/apply_locales.py'],
|
||||||
|
}], # OS=="mac"
|
||||||
],
|
],
|
||||||
'atom_source_root': '<!(python tools/atom_source_root.py)',
|
|
||||||
},
|
},
|
||||||
'target_defaults': {
|
'target_defaults': {
|
||||||
'mac_framework_dirs': [
|
'mac_framework_dirs': [
|
||||||
|
@ -317,8 +328,27 @@
|
||||||
'<(product_name)',
|
'<(product_name)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
# The application doesn't have real localizations, it just has
|
||||||
|
# empty .lproj directories, which is enough to convince Cocoa
|
||||||
|
# atom-shell supports those languages.
|
||||||
|
{
|
||||||
|
'postbuild_name': 'Make Empty Localizations',
|
||||||
|
'variables': {
|
||||||
|
'locale_dirs': [
|
||||||
|
'>!@(<(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"', {
|
['OS=="win"', {
|
||||||
'copies': [
|
'copies': [
|
||||||
{
|
{
|
||||||
|
@ -674,7 +704,31 @@
|
||||||
},
|
},
|
||||||
}, # target helper
|
}, # 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"', {
|
['OS=="win"', {
|
||||||
'targets': [
|
'targets': [
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/site_instance.h"
|
#include "content/public/browser/site_instance.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
#include "ui/base/l10n/l10n_util.h"
|
||||||
#include "webkit/common/webpreferences.h"
|
#include "webkit/common/webpreferences.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -88,6 +89,10 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AtomBrowserClient::GetApplicationLocale() {
|
||||||
|
return l10n_util::GetApplicationLocale("");
|
||||||
|
}
|
||||||
|
|
||||||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
CommandLine* command_line,
|
CommandLine* command_line,
|
||||||
int child_process_id) {
|
int child_process_id) {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
|
#ifndef ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
|
||||||
#define ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
|
#define ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "brightray/browser/browser_client.h"
|
#include "brightray/browser/browser_client.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -25,6 +27,7 @@ class AtomBrowserClient : public brightray::BrowserClient {
|
||||||
content::SiteInstance* site_instance,
|
content::SiteInstance* site_instance,
|
||||||
const GURL& current_url,
|
const GURL& current_url,
|
||||||
const GURL& new_url) OVERRIDE;
|
const GURL& new_url) OVERRIDE;
|
||||||
|
virtual std::string GetApplicationLocale() OVERRIDE;
|
||||||
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
|
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
|
||||||
int child_process_id) OVERRIDE;
|
int child_process_id) OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,15 @@
|
||||||
#import "atom/browser/mac/atom_application_delegate.h"
|
#import "atom/browser/mac/atom_application_delegate.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#import "base/mac/foundation_util.h"
|
#import "base/mac/foundation_util.h"
|
||||||
|
#include "ui/base/l10n/l10n_util_mac.h"
|
||||||
#import "vendor/brightray/common/mac/main_application_bundle.h"
|
#import "vendor/brightray/common/mac/main_application_bundle.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
||||||
|
// Initialize locale setting.
|
||||||
|
l10n_util::OverrideLocaleWithCocoaLocale();
|
||||||
|
|
||||||
// Force the NSApplication subclass to be used.
|
// Force the NSApplication subclass to be used.
|
||||||
NSApplication* application = [AtomApplication sharedApplication];
|
NSApplication* application = [AtomApplication sharedApplication];
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,11 @@ TARGET_DIRECTORIES = {
|
||||||
],
|
],
|
||||||
'win32': [
|
'win32': [
|
||||||
'resources',
|
'resources',
|
||||||
|
'locales',
|
||||||
],
|
],
|
||||||
'linux': [
|
'linux': [
|
||||||
'resources',
|
'resources',
|
||||||
|
'locales',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,10 @@ describe 'chromium feature', ->
|
||||||
-> done()
|
-> done()
|
||||||
-> done()
|
-> done()
|
||||||
|
|
||||||
|
describe 'navigator.language', ->
|
||||||
|
it 'should not be empty', ->
|
||||||
|
assert.notEqual navigator.language, ''
|
||||||
|
|
||||||
describe 'window.open', ->
|
describe 'window.open', ->
|
||||||
it 'returns a BrowserWindow object', ->
|
it 'returns a BrowserWindow object', ->
|
||||||
b = window.open 'about:blank', 'test', 'show=no'
|
b = window.open 'about:blank', 'test', 'show=no'
|
||||||
|
|
45
tools/mac/apply_locales.py
Executable file
45
tools/mac/apply_locales.py
Executable file
|
@ -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))
|
39
tools/mac/make_locale_dirs.sh
Executable file
39
tools/mac/make_locale_dirs.sh
Executable file
|
@ -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
|
33
tools/posix/make_locale_paks.sh
Executable file
33
tools/posix/make_locale_paks.sh
Executable file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue