|
@@ -116,6 +116,7 @@ var PDFViewerApplication = {
|
|
|
toolbar: null,
|
|
|
secondaryToolbar: null,
|
|
|
eventBus: null,
|
|
|
+ l10n: null,
|
|
|
pageRotation: 0,
|
|
|
isInitialViewSet: false,
|
|
|
viewerPrefs: {
|
|
@@ -140,11 +141,14 @@ var PDFViewerApplication = {
|
|
|
configure(_pdf.PDFJS);
|
|
|
this.appConfig = appConfig;
|
|
|
return this._readPreferences().then(function () {
|
|
|
+ return _this._initializeL10n();
|
|
|
+ }).then(function () {
|
|
|
return _this._initializeViewerComponents();
|
|
|
}).then(function () {
|
|
|
_this.bindEvents();
|
|
|
_this.bindWindowEvents();
|
|
|
- _ui_utils.localized.then(function () {
|
|
|
+ var appContainer = appConfig.appContainer || document.documentElement;
|
|
|
+ _this.l10n.translate(appContainer).then(function () {
|
|
|
_this.eventBus.dispatch('localized');
|
|
|
});
|
|
|
if (_this.isViewerEmbedded && !_pdf.PDFJS.isExternalLinkTargetSet()) {
|
|
@@ -208,6 +212,19 @@ var PDFViewerApplication = {
|
|
|
viewerPrefs['enablePrintAutoRotate'] = value;
|
|
|
})]).catch(function (reason) {});
|
|
|
},
|
|
|
+ _initializeL10n: function _initializeL10n() {
|
|
|
+ if (this.viewerPrefs['pdfBugEnabled']) {
|
|
|
+ var hash = document.location.hash.substring(1);
|
|
|
+ var hashParams = (0, _ui_utils.parseQueryString)(hash);
|
|
|
+ if ('locale' in hashParams) {
|
|
|
+ _pdf.PDFJS.locale = hashParams['locale'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.l10n = this.externalServices.createL10n();
|
|
|
+ return this.l10n.getDirection().then(function (dir) {
|
|
|
+ document.getElementsByTagName('html')[0].dir = dir;
|
|
|
+ });
|
|
|
+ },
|
|
|
_initializeViewerComponents: function _initializeViewerComponents() {
|
|
|
var _this2 = this;
|
|
|
|
|
@@ -233,6 +250,7 @@ var PDFViewerApplication = {
|
|
|
linkService: pdfLinkService,
|
|
|
downloadManager: downloadManager,
|
|
|
renderer: _this2.viewerPrefs['renderer'],
|
|
|
+ l10n: _this2.l10n,
|
|
|
enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
|
|
|
renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
|
|
|
enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
|
|
@@ -243,7 +261,8 @@ var PDFViewerApplication = {
|
|
|
_this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
|
|
|
container: thumbnailContainer,
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
- linkService: pdfLinkService
|
|
|
+ linkService: pdfLinkService,
|
|
|
+ l10n: _this2.l10n
|
|
|
});
|
|
|
pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
|
|
|
_this2.pdfHistory = new _pdf_history.PDFHistory({
|
|
@@ -272,14 +291,14 @@ var PDFViewerApplication = {
|
|
|
var findBarConfig = Object.create(appConfig.findBar);
|
|
|
findBarConfig.findController = _this2.findController;
|
|
|
findBarConfig.eventBus = eventBus;
|
|
|
- _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig);
|
|
|
- _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager);
|
|
|
+ _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
|
|
|
+ _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
|
|
|
_this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
|
|
|
container: container,
|
|
|
eventBus: eventBus,
|
|
|
preferences: _this2.preferences
|
|
|
});
|
|
|
- _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus);
|
|
|
+ _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
|
|
|
_this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
|
|
|
if (_this2.supportsFullscreen) {
|
|
|
_this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
|
|
@@ -290,7 +309,7 @@ var PDFViewerApplication = {
|
|
|
contextMenuItems: appConfig.fullscreen
|
|
|
});
|
|
|
}
|
|
|
- _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager);
|
|
|
+ _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
|
|
|
_this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
|
|
|
container: appConfig.sidebar.outlineView,
|
|
|
eventBus: eventBus,
|
|
@@ -306,7 +325,7 @@ var PDFViewerApplication = {
|
|
|
sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
|
|
|
sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
|
|
|
sidebarConfig.eventBus = eventBus;
|
|
|
- _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig);
|
|
|
+ _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
|
|
|
_this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
|
|
|
resolve(undefined);
|
|
|
});
|
|
@@ -479,16 +498,20 @@ var PDFViewerApplication = {
|
|
|
_this3.load(pdfDocument, scale);
|
|
|
}, function (exception) {
|
|
|
var message = exception && exception.message;
|
|
|
- var loadingErrorMessage = _ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
|
|
|
+ var loadingErrorMessage = void 0;
|
|
|
if (exception instanceof _pdf.InvalidPDFException) {
|
|
|
- loadingErrorMessage = _ui_utils.mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
|
|
|
+ loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
|
|
|
} else if (exception instanceof _pdf.MissingPDFException) {
|
|
|
- loadingErrorMessage = _ui_utils.mozL10n.get('missing_file_error', null, 'Missing PDF file.');
|
|
|
+ loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
|
|
|
} else if (exception instanceof _pdf.UnexpectedResponseException) {
|
|
|
- loadingErrorMessage = _ui_utils.mozL10n.get('unexpected_response_error', null, 'Unexpected server response.');
|
|
|
+ loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
|
|
|
+ } else {
|
|
|
+ loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
|
|
|
}
|
|
|
- _this3.error(loadingErrorMessage, { message: message });
|
|
|
- throw new Error(loadingErrorMessage);
|
|
|
+ return loadingErrorMessage.then(function (msg) {
|
|
|
+ _this3.error(msg, { message: message });
|
|
|
+ throw new Error(msg);
|
|
|
+ });
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -517,20 +540,20 @@ var PDFViewerApplication = {
|
|
|
},
|
|
|
fallback: function pdfViewFallback(featureId) {},
|
|
|
error: function pdfViewError(message, moreInfo) {
|
|
|
- var moreInfoText = _ui_utils.mozL10n.get('error_version_info', {
|
|
|
+ var moreInfoText = [this.l10n.get('error_version_info', {
|
|
|
version: _pdf.version || '?',
|
|
|
build: _pdf.build || '?'
|
|
|
- }, 'PDF.js v{{version}} (build: {{build}})') + '\n';
|
|
|
+ }, 'PDF.js v{{version}} (build: {{build}})')];
|
|
|
if (moreInfo) {
|
|
|
- moreInfoText += _ui_utils.mozL10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}');
|
|
|
+ moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
|
|
|
if (moreInfo.stack) {
|
|
|
- moreInfoText += '\n' + _ui_utils.mozL10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}');
|
|
|
+ moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
|
|
|
} else {
|
|
|
if (moreInfo.filename) {
|
|
|
- moreInfoText += '\n' + _ui_utils.mozL10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}');
|
|
|
+ moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
|
|
|
}
|
|
|
if (moreInfo.lineNumber) {
|
|
|
- moreInfoText += '\n' + _ui_utils.mozL10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}');
|
|
|
+ moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -562,7 +585,9 @@ var PDFViewerApplication = {
|
|
|
closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
|
|
moreInfoButton.removeAttribute('hidden');
|
|
|
lessInfoButton.setAttribute('hidden', 'true');
|
|
|
- errorMoreInfo.value = moreInfoText;
|
|
|
+ Promise.all(moreInfoText).then(function (parts) {
|
|
|
+ errorMoreInfo.value = parts.join('\n');
|
|
|
+ });
|
|
|
},
|
|
|
progress: function pdfViewProgress(level) {
|
|
|
var _this4 = this;
|
|
@@ -799,22 +824,26 @@ var PDFViewerApplication = {
|
|
|
this.pdfRenderingQueue.renderHighestPriority();
|
|
|
},
|
|
|
beforePrint: function pdfViewSetupBeforePrint() {
|
|
|
+ var _this6 = this;
|
|
|
+
|
|
|
if (this.printService) {
|
|
|
return;
|
|
|
}
|
|
|
if (!this.supportsPrinting) {
|
|
|
- var printMessage = _ui_utils.mozL10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by this browser.');
|
|
|
- this.error(printMessage);
|
|
|
+ this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
|
|
|
+ _this6.error(printMessage);
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
if (!this.pdfViewer.pageViewsReady) {
|
|
|
- var notReadyMessage = _ui_utils.mozL10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.');
|
|
|
- window.alert(notReadyMessage);
|
|
|
+ this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
|
|
|
+ window.alert(notReadyMessage);
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
var pagesOverview = this.pdfViewer.getPagesOverview();
|
|
|
var printContainer = this.appConfig.printContainer;
|
|
|
- var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer);
|
|
|
+ var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
|
|
|
this.printService = printService;
|
|
|
this.forceRendering();
|
|
|
printService.layout();
|
|
@@ -925,9 +954,9 @@ var validateFileURL;
|
|
|
}
|
|
|
} catch (e) {
|
|
|
var message = e && e.message;
|
|
|
- var loadingErrorMessage = _ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
|
|
|
- var moreInfo = { message: message };
|
|
|
- PDFViewerApplication.error(loadingErrorMessage, moreInfo);
|
|
|
+ PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
|
|
|
+ PDFViewerApplication.error(loadingErrorMessage, { message: message });
|
|
|
+ });
|
|
|
throw e;
|
|
|
}
|
|
|
};
|
|
@@ -1004,9 +1033,6 @@ function webViewerInitialized() {
|
|
|
if ('ignorecurrentpositiononzoom' in hashParams) {
|
|
|
_pdf.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
|
|
|
}
|
|
|
- if ('locale' in hashParams) {
|
|
|
- _pdf.PDFJS.locale = hashParams['locale'];
|
|
|
- }
|
|
|
if ('textlayer' in hashParams) {
|
|
|
switch (hashParams['textlayer']) {
|
|
|
case 'off':
|
|
@@ -1027,7 +1053,6 @@ function webViewerInitialized() {
|
|
|
waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
|
|
|
}
|
|
|
}
|
|
|
- _ui_utils.mozL10n.setLanguage(_pdf.PDFJS.locale);
|
|
|
if (!PDFViewerApplication.supportsPrinting) {
|
|
|
appConfig.toolbar.print.classList.add('hidden');
|
|
|
appConfig.secondaryToolbar.printButton.classList.add('hidden');
|
|
@@ -1050,7 +1075,9 @@ function webViewerInitialized() {
|
|
|
Promise.all(waitForBeforeOpening).then(function () {
|
|
|
webViewerOpenFileViaURL(file);
|
|
|
}).catch(function (reason) {
|
|
|
- PDFViewerApplication.error(_ui_utils.mozL10n.get('loading_error', null, 'An error occurred while opening.'), reason);
|
|
|
+ PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
|
|
|
+ PDFViewerApplication.error(msg, reason);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
var webViewerOpenFileViaURL;
|
|
@@ -1067,7 +1094,9 @@ var webViewerOpenFileViaURL;
|
|
|
xhr.responseType = 'arraybuffer';
|
|
|
xhr.send();
|
|
|
} catch (e) {
|
|
|
- PDFViewerApplication.error(_ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.'), e);
|
|
|
+ PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
|
|
|
+ PDFViewerApplication.error(msg, e);
|
|
|
+ });
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -1094,7 +1123,9 @@ function webViewerPageRendered(e) {
|
|
|
Stats.add(pageNumber, pageView.stats);
|
|
|
}
|
|
|
if (pageView.error) {
|
|
|
- PDFViewerApplication.error(_ui_utils.mozL10n.get('rendering_error', null, 'An error occurred while rendering the page.'), pageView.error);
|
|
|
+ PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
|
|
|
+ PDFViewerApplication.error(msg, pageView.error);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
function webViewerTextLayerRendered(e) {}
|
|
@@ -1575,9 +1606,6 @@ function webViewerKeyDown(evt) {
|
|
|
evt.preventDefault();
|
|
|
}
|
|
|
}
|
|
|
-_ui_utils.localized.then(function webViewerLocalized() {
|
|
|
- document.getElementsByTagName('html')[0].dir = _ui_utils.mozL10n.getDirection();
|
|
|
-});
|
|
|
var PDFPrintServiceFactory = {
|
|
|
instance: {
|
|
|
supportsPrinting: false,
|