Commit c42c3e8f authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer: Leverage $i18n{} C++ replacements in more places.

Bug: 1091516
Change-Id: Ibcbb1dce1ca16b293f3f8998413632c29ed34042
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2236674
Auto-Submit: dpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776842}
parent b6288872
...@@ -67,7 +67,10 @@ js_library("viewer-page-selector") { ...@@ -67,7 +67,10 @@ js_library("viewer-page-selector") {
} }
js_library("viewer-password-screen") { js_library("viewer-password-screen") {
deps = [ "//ui/webui/resources/cr_elements/cr_input:cr_input.m" ] deps = [
"//ui/webui/resources/cr_elements/cr_input:cr_input.m",
"//ui/webui/resources/js:load_time_data.m",
]
} }
js_library("viewer-pdf-toolbar") { js_library("viewer-pdf-toolbar") {
......
<style include="cr-hidden-style"></style> <style include="cr-hidden-style"></style>
<cr-dialog id="dialog" no-cancel> <cr-dialog id="dialog" no-cancel>
<div slot="title">[[strings.errorDialogTitle]]</div> <div slot="title">$i18n{errorDialogTitle}</div>
<div slot="body">[[strings.pageLoadFailed]]</div> <div slot="body">$i18n{pageLoadFailed}</div>
<div slot="button-container" hidden$="[[!reloadFn]]"> <div slot="button-container" hidden$="[[!reloadFn]]">
<cr-button class="action-button" on-click="reload"> <cr-button class="action-button" on-click="reload">
[[strings.pageReload]] $i18n{pageReload}
</cr-button> </cr-button>
</div> </div>
</cr-dialog> </cr-dialog>
...@@ -15,8 +15,6 @@ Polymer({ ...@@ -15,8 +15,6 @@ Polymer({
properties: { properties: {
reloadFn: Function, reloadFn: Function,
strings: Object,
}, },
show() { show() {
......
<style include="cr-hidden-style"></style> <style include="cr-hidden-style"></style>
<cr-dialog id="dialog" no-cancel> <cr-dialog id="dialog" no-cancel>
<div slot="title">[[strings.annotationFormWarningTitle]]</div> <div slot="title">$i18n{annotationFormWarningTitle}</div>
<div slot="body">[[strings.annotationFormWarningDetail]]</div> <div slot="body">$i18n{annotationFormWarningDetail}</div>
<div slot="button-container"> <div slot="button-container">
<cr-button class="cancel-button" on-click="onCancel"> <cr-button class="cancel-button" on-click="onCancel">
[[strings.annotationFormWarningKeepEditing]] $i18n{annotationFormWarningKeepEditing}
</cr-button> </cr-button>
<cr-button class="action-button" on-click="onAction"> <cr-button class="action-button" on-click="onAction">
[[strings.annotationFormWarningDiscard]] $i18n{annotationFormWarningDiscard}
</cr-button> </cr-button>
</div> </div>
</cr-dialog> </cr-dialog>
...@@ -14,10 +14,6 @@ Polymer({ ...@@ -14,10 +14,6 @@ Polymer({
_template: html`{__html_template__}`, _template: html`{__html_template__}`,
properties: {
strings: Object,
},
/** @private {PromiseResolver} */ /** @private {PromiseResolver} */
resolver_: null, resolver_: null,
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</style> </style>
<cr-input id="pageselector" value="[[pageNo]]" on-mouseup="select" <cr-input id="pageselector" value="[[pageNo]]" on-mouseup="select"
on-value-changed="onInputValueChange_" on-change="pageNoCommitted" on-value-changed="onInputValueChange_" on-change="pageNoCommitted"
aria-label$="[[strings.labelPageNumber]]"> aria-label$="$i18n{labelPageNumber}">
</cr-input> </cr-input>
/ /
<span id="pagelength">[[docLength]]</span> <span id="pagelength">[[docLength]]</span>
...@@ -26,8 +26,6 @@ Polymer({ ...@@ -26,8 +26,6 @@ Polymer({
type: Number, type: Number,
value: 1, value: 1,
}, },
strings: Object,
}, },
/** @return {!CrInputElement} */ /** @return {!CrInputElement} */
......
...@@ -4,20 +4,19 @@ ...@@ -4,20 +4,19 @@
} }
</style> </style>
<cr-dialog id="dialog" no-cancel> <cr-dialog id="dialog" no-cancel>
<div slot="title">[[strings.passwordDialogTitle]]</div> <div slot="title">$i18n{passwordDialogTitle}</div>
<div slot="body"> <div slot="body">
<div id="message">[[strings.passwordPrompt]]</div> <div id="message">$i18n{passwordPrompt}</div>
<cr-input id="password" <cr-input id="password"
type="password" type="password"
error-message="[[getErrorMessage_(strings.passwordInvalid, error-message="[[getErrorMessage_(invalid)]]"
invalid)]]"
invalid="[[invalid]]" invalid="[[invalid]]"
autofocus> autofocus>
</cr-input> </cr-input>
</div> </div>
<div slot="button-container"> <div slot="button-container">
<cr-button id="submit" class="action-button" on-click="submit"> <cr-button id="submit" class="action-button" on-click="submit">
[[strings.passwordSubmit]] $i18n{passwordSubmit}
</cr-button> </cr-button>
</div> </div>
</cr-dialog> </cr-dialog>
...@@ -8,6 +8,7 @@ import 'chrome://resources/cr_elements/cr_input/cr_input.m.js'; ...@@ -8,6 +8,7 @@ import 'chrome://resources/cr_elements/cr_input/cr_input.m.js';
import 'chrome://resources/cr_elements/shared_style_css.m.js'; import 'chrome://resources/cr_elements/shared_style_css.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js'; import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Polymer({ Polymer({
...@@ -17,8 +18,6 @@ Polymer({ ...@@ -17,8 +18,6 @@ Polymer({
properties: { properties: {
invalid: Boolean, invalid: Boolean,
strings: Object,
}, },
get active() { get active() {
...@@ -57,10 +56,9 @@ Polymer({ ...@@ -57,10 +56,9 @@ Polymer({
* Returns |message| if input is invalid, otherwise empty string. * Returns |message| if input is invalid, otherwise empty string.
* This avoids setting the error message (which announces to screen readers) * This avoids setting the error message (which announces to screen readers)
* when there is no error. * when there is no error.
* @param {string} message
* @return {string} * @return {string}
*/ */
getErrorMessage_(message) { getErrorMessage_() {
return this.invalid ? message : ''; return this.invalid ? loadTimeData.getString('passwordInvalid') : '';
} }
}); });
...@@ -170,8 +170,7 @@ ...@@ -170,8 +170,7 @@
<div id="pageselector-container"> <div id="pageselector-container">
<viewer-page-selector id="pageselector" class="invisible" <viewer-page-selector id="pageselector" class="invisible"
doc-length="[[docLength]]" page-no="[[pageNo]]" doc-length="[[docLength]]" page-no="[[pageNo]]">
strings="[[strings]]">
</viewer-page-selector> </viewer-page-selector>
</div> </div>
......
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
on-pointerdown="blurOnPointerDown"> on-pointerdown="blurOnPointerDown">
</template> </template>
<cr-icon-button id="expand" iron-icon="cr:expand-more" tabindex="3" <cr-icon-button id="expand" iron-icon="cr:expand-more" tabindex="3"
on-click="toggleExpanded_" aria-label$="[[strings.annotationExpand]]" on-click="toggleExpanded_" aria-label$="$i18n{annotationExpand}"
title$="[[strings.annotationExpand]]"></cr-icon-button> title$="$i18n{annotationExpand}"></cr-icon-button>
</div> </div>
<div id="separator"></div> <div id="separator"></div>
<div id="sizes" on-change="sizeChanged_"> <div id="sizes" on-change="sizeChanged_">
......
...@@ -788,13 +788,6 @@ export class PDFViewer { ...@@ -788,13 +788,6 @@ export class PDFViewer {
// Display the zoom toolbar after the UI text direction is set, to ensure it // Display the zoom toolbar after the UI text direction is set, to ensure it
// appears on the correct side of the PDF viewer. // appears on the correct side of the PDF viewer.
$('zoom-toolbar').hidden = false; $('zoom-toolbar').hidden = false;
if (this.passwordScreen_) {
$('password-screen').strings = strings;
}
$('error-screen').strings = strings;
if ($('form-warning')) {
$('form-warning').strings = strings;
}
} }
/** /**
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "chrome/browser/printing/background_printing_manager.h" #include "chrome/browser/printing/background_printing_manager.h"
#include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/print_preview_data_service.h" #include "chrome/browser/printing/print_preview_data_service.h"
...@@ -360,6 +361,12 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) { ...@@ -360,6 +361,12 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION, shortcut_text)); IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION, shortcut_text));
#endif #endif
// Register strings for the PDF viewer, so that $i18n{} replacements work.
base::Value pdf_strings(base::Value::Type::DICTIONARY);
pdf_extension_util::AddStrings(&pdf_strings);
pdf_extension_util::AddAdditionalData(&pdf_strings);
source->AddLocalizedStrings(base::Value::AsDictionaryValue(pdf_strings));
} }
void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) { void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) {
......
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