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

Unified Diff: ui/webui/resources/PRESUBMIT.py

Issue 2451283005: Add presubmit explaining embedding translations in shared UI code (Closed)
Patch Set: remove rietveld dep Created 4 years, 2 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/PRESUBMIT.py
diff --git a/ui/webui/resources/PRESUBMIT.py b/ui/webui/resources/PRESUBMIT.py
index 1a7cbb3932116d1aa95ab1e852a4a3d7a0e581a5..521ad5e6effce837372b926dba56439f9aab855b 100644
--- a/ui/webui/resources/PRESUBMIT.py
+++ b/ui/webui/resources/PRESUBMIT.py
@@ -27,3 +27,44 @@ def PostUploadHook(cl, change, output_api):
rietveld_obj.update_description(cl.issue, new_description)
return [output_api.PresubmitNotifyResult(
'Automatically added optional Closure bots to run on CQ.')]
+
+
+def CheckChangeOnUpload(input_api, output_api):
+ return _CheckForTranslations(input_api, output_api)
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ return _CheckForTranslations(input_api, output_api)
+
+
+def _CheckForTranslations(input_api, output_api):
+ shared_keywords = ['i18n(']
+ html_keywords = shared_keywords + ['$118n{']
+ js_keywords = shared_keywords + ['I18nBehavior', 'loadTimeData.']
+
+ errors = []
+
+ for f in input_api.AffectedFiles():
+ local_path = f.LocalPath()
+
+ keywords = None
+ if local_path.endswith('.js'):
+ keywords = js_keywords
+ elif local_path.endswith('.html'):
+ keywords = html_keywords
+
+ if not keywords:
+ continue
+
+ for lnum, line in f.ChangedContents():
+ if any(line for keyword in keywords if keyword in line):
+ errors.append("%s:%d\n%s" % (f.LocalPath(), lnum, line))
+
+ if not errors:
+ return []
+
+ return [output_api.PresubmitError("\n".join(errors) + """
+
+Don't embed translations directly in shared UI code. Instead, inject your
+translation from the place using the shared code. For an example: see
+<cr-dialog>#closeText (http://bit.ly/2eLEsqh).""")]
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698