Commit e68377c6 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Public side of English fallback CL

Change-Id: Ic6254af767545e783605a6f0cbe853601fcec236
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405750Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806265}
parent 4579d553
......@@ -32,6 +32,7 @@ namespace {
// Wraps the strings in JS so they can be accessed by the code. The strings are
// placed on the window object so they can always be accessed.
const char kStringWrapper[] =
"window.KALEIDOSCOPE_STRINGS_FALLBACK = new Map(Object.entries(%s));"
"window.KALEIDOSCOPE_STRINGS = new Map(Object.entries(%s));";
bool OnShouldHandleRequest(const std::string& path) {
......@@ -182,22 +183,26 @@ int GetResourceForLocale(const std::string& locale) {
#endif // BUILDFLAG(ENABLE_KALEIDOSCOPE)
void OnStringsRequest(const std::string& path,
content::WebUIDataSource::GotDataCallback callback) {
DCHECK(OnShouldHandleRequest(path));
std::string GetStringsForLocale(const std::string& locale) {
std::string str;
#if BUILDFLAG(ENABLE_KALEIDOSCOPE)
auto locale = base::ToLowerASCII(base::i18n::GetConfiguredLocale());
str = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
GetResourceForLocale(locale));
#else
#endif
return str;
}
#endif // BUILDFLAG(ENABLE_KALEIDOSCOPE)
void OnStringsRequest(const std::string& path,
content::WebUIDataSource::GotDataCallback callback) {
DCHECK(OnShouldHandleRequest(path));
auto str_lang = GetStringsForLocale(
base::ToLowerASCII(base::i18n::GetConfiguredLocale()));
auto str_lang_en = GetStringsForLocale("en");
base::RefCountedString* ref_contents = new base::RefCountedString();
ref_contents->data() = base::StringPrintf(kStringWrapper, str.c_str());
ref_contents->data() =
base::StringPrintf(kStringWrapper, str_lang_en.c_str(), str_lang.c_str());
std::move(callback).Run(ref_contents);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment