add app.setLocale() (#11469)

* infrastructure for setLocale via klang

* add documentation for setLocale

* add test for setLocale

* fix spec

* add spec and update docs

* fix carriage feeds on windows

* SetLocale() sets LC_ALL on Linux

* in SetLocale() on Linux, use g_setenv()

* fix tyop: '#ifdef OSX_POSIX'

* make the linter happy

* improvements from review
This commit is contained in:
shelley vohr 2018-02-08 09:26:37 -05:00 committed by Charles Kerr
parent e3f1d90854
commit ca34978e73
9 changed files with 92 additions and 16 deletions

View file

@ -42,17 +42,22 @@ bool SubprocessNeedsResourceBundle(const std::string& process_type) {
} // namespace
void InitializeResourceBundle(const std::string& locale) {
// Load locales.
ui::ResourceBundle::InitSharedInstanceWithLocale(
locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
void LoadResourceBundle(const std::string& locale) {
const bool initialized = ui::ResourceBundle::HasSharedInstance();
if (initialized)
ui::ResourceBundle::CleanupSharedInstance();
// Load other resource files.
ui::ResourceBundle::InitSharedInstanceWithLocale(
locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
bundle.ReloadLocaleResources(locale);
// Load other resource files.
#if defined(OS_MACOSX)
LoadCommonResources();
#else
base::FilePath pak_dir;
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
PathService::Get(base::DIR_MODULE, &pak_dir);
bundle.AddDataPackFromPath(
pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")),
@ -104,7 +109,7 @@ void MainDelegate::PreSandboxStartup() {
// browser process as a command line flag.
if (SubprocessNeedsResourceBundle(process_type)) {
std::string locale = cmd.GetSwitchValueASCII(switches::kLang);
InitializeResourceBundle(locale);
LoadResourceBundle(locale);
}
}