diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:08:39 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:08:39 +0000 |
commit | fc877cf756aca680933305c6cb147feecf63113e (patch) | |
tree | bdbeae4a96bd19176573960f14bbd7223cdcf869 /remoting/base | |
parent | 5365e52c633777ee6dde1edba6258fb502ac205d (diff) | |
download | chromium_src-fc877cf756aca680933305c6cb147feecf63113e.zip chromium_src-fc877cf756aca680933305c6cb147feecf63113e.tar.gz chromium_src-fc877cf756aca680933305c6cb147feecf63113e.tar.bz2 |
Localized Chromoting Host on Mac and Linux.
Re-landing r214379. Two additional fixes:
- HOST_PLUGIN_MIME_TYPE is passed unquoted making the code the uses it responsible for stringizing it.
- msvs_cygwin_shell is set to 0 to avoid cygpath changing "remoting_locales\nl.pak" to "remoting_ocales\nl.pak".
This CL implements generation of localizable strings from remoting_strings.grd file. Depending on the platform the localized resources are placed to:
- Mac: localized .string and .pak resources are added to each application bundle under 'Resources/<locale>.lproj'
- Linux: localized .pak files are placed under 'remoting_locales' directory next to the binary locading them.
- Windows: .rc resources are generated from .jinja2 templates and embedded into a relevant binary.
Chrome l10n and i18n APIs are used to retrieve the current locale and RTL flag (Mac & Linux). The it2me plugin sets the locale to match the locale of the browser.
Collateral changes:
- UiString is not used any more.
- Increased width of disconnect window message on Mac.
- The host plugin version is correctly reported on Mac.
- Dialogs use RTL templates in case of RTL languages. No more updating the templates dynamically (Windows).
- remoting_unittests.ResourcesTest now runs on Mac, LInux and Windows.
- '@' is used for variable substitutions by remoting_localize.py.
- HOST_PLUGIN_MIME_TYPE is defined in one place now.
- Deleted unused commong_resources.grd.
Mac installer and preference panel are not localized yet.
BUG=155204
Review URL: https://chromiumcodereview.appspot.com/21059003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/resources.cc | 35 | ||||
-rw-r--r-- | remoting/base/resources.h | 8 | ||||
-rw-r--r-- | remoting/base/resources_linux.cc | 44 | ||||
-rw-r--r-- | remoting/base/resources_mac.mm | 43 | ||||
-rw-r--r-- | remoting/base/resources_unittest.cc | 44 | ||||
-rw-r--r-- | remoting/base/resources_win.cc | 17 |
6 files changed, 129 insertions, 62 deletions
diff --git a/remoting/base/resources.cc b/remoting/base/resources.cc deleted file mode 100644 index 933be87..0000000 --- a/remoting/base/resources.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 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. - -#include "remoting/base/resources.h" - -#include "base/files/file_path.h" -#include "base/path_service.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/ui_base_paths.h" - -namespace remoting { - -namespace { -const char kLocaleResourcesDirName[] = "remoting_locales"; -const char kCommonResourcesFileName[] = "chrome_remote_desktop.pak"; -} // namespace - -// Loads chromoting resources. -bool LoadResources(const std::string& pref_locale) { - base::FilePath path; - if (!PathService::Get(base::DIR_MODULE, &path)) - return false; - - PathService::Override(ui::DIR_LOCALES, - path.AppendASCII(kLocaleResourcesDirName)); - ui::ResourceBundle::InitSharedInstanceLocaleOnly(pref_locale, NULL); - - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( - path.AppendASCII(kCommonResourcesFileName), ui::SCALE_FACTOR_100P); - - return true; -} - -} // namespace remoting diff --git a/remoting/base/resources.h b/remoting/base/resources.h index b08eb8d..371c533 100644 --- a/remoting/base/resources.h +++ b/remoting/base/resources.h @@ -9,11 +9,15 @@ namespace remoting { -// Loads chromoting resources. Returns false in case of a failure. |pref_locale| +// Loads (or reloads) Chromoting resources for the given locale. |pref_locale| // is passed to l10n_util::GetApplicationLocale(), so the default system locale -// is used if |pref_locale| is empty. +// is used if |pref_locale| is empty. Returns |true| if the shared resource +// bundle has been initialized. bool LoadResources(const std::string& pref_locale); +// Unloads Chromoting resources. +void UnloadResources(); + } // namespace remoting #endif // REMOTING_HOST_BASE_RESOURCES_H_ diff --git a/remoting/base/resources_linux.cc b/remoting/base/resources_linux.cc new file mode 100644 index 0000000..af530e8 --- /dev/null +++ b/remoting/base/resources_linux.cc @@ -0,0 +1,44 @@ +// Copyright 2013 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. + +#include "remoting/base/resources.h" + +#include <dlfcn.h> + +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_paths.h" + +namespace remoting { + +namespace { +const char kLocaleResourcesDirName[] = "remoting_locales"; +} // namespace + +bool LoadResources(const std::string& pref_locale) { + if (ui::ResourceBundle::HasSharedInstance()) { + ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale); + } else { + // Retrive the path to the module containing this function. + Dl_info info; + CHECK(dladdr(reinterpret_cast<void*>(&LoadResources), &info) != 0); + + // Point DIR_LOCALES to 'remoting_locales'. + base::FilePath path = base::FilePath(info.dli_fname).DirName(); + PathService::Override(ui::DIR_LOCALES, + path.AppendASCII(kLocaleResourcesDirName)); + + ui::ResourceBundle::InitSharedInstanceLocaleOnly(pref_locale, NULL); + } + + return true; +} + +void UnloadResources() { + ui::ResourceBundle::CleanupSharedInstance(); +} + +} // namespace remoting diff --git a/remoting/base/resources_mac.mm b/remoting/base/resources_mac.mm new file mode 100644 index 0000000..d1ce4af --- /dev/null +++ b/remoting/base/resources_mac.mm @@ -0,0 +1,43 @@ +// Copyright 2013 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. + +#import <Cocoa/Cocoa.h> + +#include "remoting/base/resources.h" +#include "base/mac/bundle_locations.h" +#include "ui/base/l10n/l10n_util_mac.h" +#include "ui/base/resource/resource_bundle.h" + +// A dummy class used to locate the host plugin's bundle. +@interface NSBundleLocator : NSObject +@end + +@implementation NSBundleLocator +@end + +namespace remoting { + +bool LoadResources(const std::string& pref_locale) { + if (ui::ResourceBundle::HasSharedInstance()) { + ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale); + } else { + // Use the plugin's bundle instead of the hosting app bundle. + base::mac::SetOverrideFrameworkBundle( + [NSBundle bundleForClass:[NSBundleLocator class]]); + + // Override the locale with the value from Cocoa. + if (pref_locale.empty()) + l10n_util::OverrideLocaleWithCocoaLocale(); + + ui::ResourceBundle::InitSharedInstanceLocaleOnly(pref_locale, NULL); + } + + return true; +} + +void UnloadResources() { + ui::ResourceBundle::CleanupSharedInstance(); +} + +} // namespace remoting diff --git a/remoting/base/resources_unittest.cc b/remoting/base/resources_unittest.cc index 6d69cee..b02a12b 100644 --- a/remoting/base/resources_unittest.cc +++ b/remoting/base/resources_unittest.cc @@ -4,52 +4,46 @@ #include "remoting/base/resources.h" -#include "remoting/base/common_resources.h" #include "remoting/base/string_resources.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" #include "testing/gtest/include/gtest/gtest.h" namespace remoting { -// TODO(sergeyu): Resources loading doesn't work yet on OSX. Fix it and enable -// the test. -#if !defined(OS_MACOSX) -#define MAYBE_ProductName ProductName -#define MAYBE_ProductLogo ProductLogo -#else // !defined(OS_MACOSX) -#define MAYBE_ProductName DISABLED_ProductName -#define MAYBE_ProductLogo DISABLED_ProductLogo -#endif // defined(OS_MACOSX) - class ResourcesTest : public testing::Test { protected: + ResourcesTest(): resources_available_(false) { + } + virtual void SetUp() OVERRIDE { - ASSERT_TRUE(LoadResources("en-US")); + resources_available_ = LoadResources("en-US"); } virtual void TearDown() OVERRIDE { - ui::ResourceBundle::CleanupSharedInstance(); + UnloadResources(); } + + bool resources_available_; }; -TEST_F(ResourcesTest, MAYBE_ProductName) { +TEST_F(ResourcesTest, ProductName) { #if defined(GOOGLE_CHROME_BUILD) std::string expected_product_name = "Chrome Remote Desktop"; #else // defined(GOOGLE_CHROME_BUILD) std::string expected_product_name = "Chromoting"; #endif // !defined(GOOGLE_CHROME_BUILD) - EXPECT_EQ(expected_product_name, - l10n_util::GetStringUTF8(IDR_PRODUCT_NAME)); -} -TEST_F(ResourcesTest, MAYBE_ProductLogo) { - gfx::Image logo16 = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_PRODUCT_LOGO_16); - EXPECT_FALSE(logo16.IsEmpty()); - gfx::Image logo32 = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_PRODUCT_LOGO_32); - EXPECT_FALSE(logo32.IsEmpty()); + // Chrome-style i18n is not used on Windows. +#if defined(OS_WIN) + EXPECT_FALSE(resources_available_); +#else + EXPECT_TRUE(resources_available_); +#endif + + if (resources_available_) { + EXPECT_EQ(expected_product_name, + l10n_util::GetStringUTF8(IDR_PRODUCT_NAME)); + } } } // namespace remoting diff --git a/remoting/base/resources_win.cc b/remoting/base/resources_win.cc new file mode 100644 index 0000000..e4d9efa --- /dev/null +++ b/remoting/base/resources_win.cc @@ -0,0 +1,17 @@ +// Copyright 2013 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. + +#include "remoting/base/resources.h" + +namespace remoting { + +bool LoadResources(const std::string& pref_locale) { + // Do nothing since .pak files are not used on Windows. + return false; +} + +void UnloadResources() { +} + +} // namespace remoting |