Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Unified Diff: ui/base/template_expressions.cc

Issue 2607843002: [MD settings] i18n template replacements in shared HTML resources (Closed)
Patch Set: added TemplateReplacementsSetBool Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/template_expressions.h ('k') | ui/base/webui/jstemplate_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/template_expressions.cc
diff --git a/ui/base/template_expressions.cc b/ui/base/template_expressions.cc
index 10aaf4fecf5a4e44040c427de461ba5704336fbf..1fcee4ef55cb5432f5ccad3eb1df9c94004350ca 100644
--- a/ui/base/template_expressions.cc
+++ b/ui/base/template_expressions.cc
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "base/logging.h"
+#include "base/values.h"
#include "net/base/escape.h"
namespace {
@@ -18,6 +19,31 @@ const char kKeyClose = '}';
namespace ui {
+void TemplateReplacementsFromDictionaryValue(
+ const base::DictionaryValue& dictionary,
+ TemplateReplacements* replacements) {
+ for (base::DictionaryValue::Iterator it(dictionary); !it.IsAtEnd();
+ it.Advance()) {
+ if (it.value().IsType(base::Value::Type::STRING)) {
+ std::string str_value;
+ if (it.value().GetAsString(&str_value))
+ (*replacements)[it.key()] = str_value;
+ } else if (it.value().IsType(base::Value::Type::BOOLEAN)) {
+ bool bool_value;
+ if (it.value().GetAsBoolean(&bool_value))
+ TemplateReplacementsSetBool(it.key(), bool_value, replacements);
+ }
+ }
+}
+
+void TemplateReplacementsSetBool(const std::string& name,
+ bool value,
+ TemplateReplacements* replacements) {
+ // These are HTML Boolean attributes which are represented by their name
+ // if truthy and by complete absence (empty string) if falsy.
Dan Beam 2017/01/03 20:03:15 this comment is confusing. hidden="" hides stuff,
dschuyler 2017/01/03 20:36:56 Correct, so in this case: <div $i18n{guestMode}>.
+ (*replacements)[name] = value ? name : "";
+}
+
std::string ReplaceTemplateExpressions(
base::StringPiece source,
const TemplateReplacements& replacements) {
« no previous file with comments | « ui/base/template_expressions.h ('k') | ui/base/webui/jstemplate_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698