| # Copyright 2016 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. |
| |
| def PostUploadHook(cl, change, output_api): |
| return output_api.EnsureCQIncludeTrybotsAreAdded( |
| cl, |
| [ |
| 'master.tryserver.chromium.linux:closure_compilation', |
| ], |
| 'Automatically added optional Closure bots to run on CQ.') |
| |
| |
| def CheckChangeOnUpload(input_api, output_api): |
| return _CommonChecks(input_api, output_api) |
| |
| |
| def CheckChangeOnCommit(input_api, output_api): |
| return _CommonChecks(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() |
| if local_path.endswith('i18n_behavior.js'): |
| continue |
| |
| 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).""")] |
| |
| |
| def _CommonChecks(input_api, output_api): |
| results = [] |
| results += _CheckForTranslations(input_api, output_api) |
| results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api, |
| check_js=True) |
| return results |