Fallback locale string for JS code; simplify locale embedding for the extension
This commit is contained in:
parent
2d81ca1586
commit
89156cec89
7
external/webL10n/l10n.js
vendored
7
external/webL10n/l10n.js
vendored
@ -21,7 +21,8 @@
|
|||||||
/*
|
/*
|
||||||
Additional modifications for PDF.js project:
|
Additional modifications for PDF.js project:
|
||||||
- Loading resources from <script type='application/l10n'>;
|
- Loading resources from <script type='application/l10n'>;
|
||||||
- Disabling language assignment on page loading.
|
- Disabling language initialization on page loading;
|
||||||
|
- Add fallback argument to the translateString.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -221,8 +222,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// translate a string
|
// translate a string
|
||||||
function translateString(key, args) {
|
function translateString(key, args, fallback) {
|
||||||
var data = getL10nData(key);
|
var data = getL10nData(key);
|
||||||
|
if (!data && fallback)
|
||||||
|
data = {textContent: fallback};
|
||||||
if (!data)
|
if (!data)
|
||||||
return '{{' + key + '}}';
|
return '{{' + key + '}}';
|
||||||
return substArguments(data.textContent, args);
|
return substArguments(data.textContent, args);
|
||||||
|
2
make.js
2
make.js
@ -327,7 +327,7 @@ target.firefox = function() {
|
|||||||
// Modify the viewer so it does all the extension-only stuff.
|
// Modify the viewer so it does all the extension-only stuff.
|
||||||
cd(FIREFOX_BUILD_CONTENT_DIR + '/web');
|
cd(FIREFOX_BUILD_CONTENT_DIR + '/web');
|
||||||
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUNDLE.*\n/, cat(ROOT_DIR + BUILD_TARGET), 'viewer-snippet-firefox-extension.html');
|
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUNDLE.*\n/, cat(ROOT_DIR + BUILD_TARGET), 'viewer-snippet-firefox-extension.html');
|
||||||
sed('-i', /PDFJSSCRIPT_LOCALE_DATA/, JSON.stringify({text: LOCALE_CONTENT}), 'viewer-snippet-firefox-extension.html');
|
sed('-i', /.*PDFJSSCRIPT_LOCALE_DATA.*\n/, LOCALE_CONTENT, 'viewer-snippet-firefox-extension.html');
|
||||||
sed('-i', /.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html');
|
sed('-i', /.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html');
|
||||||
sed('-i', /.*PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
|
sed('-i', /.*PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
|
||||||
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');
|
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
<!-- This snippet is used in firefox extension, see Makefile -->
|
<!-- This snippet is used in firefox extension, see Makefile -->
|
||||||
<base href="resource://pdf.js/web/" />
|
<base href="resource://pdf.js/web/" />
|
||||||
<script type="text/javascript">
|
<script type="application/l10n">
|
||||||
(function() {
|
<!-- PDFJSSCRIPT_LOCALE_DATA -->
|
||||||
// doning script creation here since resource:// urls won't work
|
|
||||||
// for content loading.
|
|
||||||
var localeData = PDFJSSCRIPT_LOCALE_DATA;
|
|
||||||
var script = document.createElement('script');
|
|
||||||
script.type = 'application/l10n';
|
|
||||||
script.text = localeData.text;
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(script);
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="l10n.js"></script>
|
<script type="text/javascript" src="l10n.js"></script>
|
||||||
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
|
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">
|
||||||
|
@ -349,11 +349,13 @@ var PDFView = {
|
|||||||
},
|
},
|
||||||
function getDocumentError(message, exception) {
|
function getDocumentError(message, exception) {
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingIndicator = document.getElementById('loading');
|
||||||
loadingIndicator.textContent = mozL10n.get('loading_error_indicator');
|
loadingIndicator.textContent = mozL10n.get('loading_error_indicator',
|
||||||
|
null, 'Error');
|
||||||
var moreInfo = {
|
var moreInfo = {
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
self.error(mozL10n.get('loading_error'), moreInfo);
|
self.error(mozL10n.get('loading_error', null,
|
||||||
|
'An error occurred while loading the PDF.'), moreInfo);
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
},
|
},
|
||||||
function getDocumentProgress(progressData) {
|
function getDocumentProgress(progressData) {
|
||||||
@ -461,22 +463,27 @@ var PDFView = {
|
|||||||
moreInfoButton.removeAttribute('hidden');
|
moreInfoButton.removeAttribute('hidden');
|
||||||
lessInfoButton.setAttribute('hidden', 'true');
|
lessInfoButton.setAttribute('hidden', 'true');
|
||||||
errorMoreInfo.value =
|
errorMoreInfo.value =
|
||||||
mozL10n.get('error_build', {build: PDFJS.build}) + '\n';
|
mozL10n.get('error_build', {build: PDFJS.build},
|
||||||
|
'PDF.JS Build: {{build}}') + '\n';
|
||||||
|
|
||||||
if (moreInfo) {
|
if (moreInfo) {
|
||||||
errorMoreInfo.value +=
|
errorMoreInfo.value +=
|
||||||
mozL10n.get('error_message', {message: moreInfo.message});
|
mozL10n.get('error_message', {message: moreInfo.message},
|
||||||
|
'Message: {{message}}');
|
||||||
if (moreInfo.stack) {
|
if (moreInfo.stack) {
|
||||||
errorMoreInfo.value += '\n' +
|
errorMoreInfo.value += '\n' +
|
||||||
mozL10n.get('error_stack', {stack: moreInfo.stack});
|
mozL10n.get('error_stack', {stack: moreInfo.stack},
|
||||||
|
'Stack: {{stack}}');
|
||||||
} else {
|
} else {
|
||||||
if (moreInfo.filename) {
|
if (moreInfo.filename) {
|
||||||
errorMoreInfo.value += '\n' +
|
errorMoreInfo.value += '\n' +
|
||||||
mozL10n.get('error_file', {file: moreInfo.filename});
|
mozL10n.get('error_file', {file: moreInfo.filename},
|
||||||
|
'File: {{file}}');
|
||||||
}
|
}
|
||||||
if (moreInfo.lineNumber) {
|
if (moreInfo.lineNumber) {
|
||||||
errorMoreInfo.value += '\n' +
|
errorMoreInfo.value += '\n' +
|
||||||
mozL10n.get('error_line', {line: moreInfo.lineNumber});
|
mozL10n.get('error_line', {line: moreInfo.lineNumber},
|
||||||
|
'Line: {{line}}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -486,7 +493,8 @@ var PDFView = {
|
|||||||
progress: function pdfViewProgress(level) {
|
progress: function pdfViewProgress(level) {
|
||||||
var percent = Math.round(level * 100);
|
var percent = Math.round(level * 100);
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingIndicator = document.getElementById('loading');
|
||||||
loadingIndicator.textContent = mozL10n.get('loading', {percent: percent});
|
loadingIndicator.textContent = mozL10n.get('loading', {percent: percent},
|
||||||
|
'Loading... {{percent}}%');
|
||||||
|
|
||||||
PDFView.loadingBar.percent = percent;
|
PDFView.loadingBar.percent = percent;
|
||||||
},
|
},
|
||||||
@ -523,7 +531,7 @@ var PDFView = {
|
|||||||
var id = pdfDocument.fingerprint;
|
var id = pdfDocument.fingerprint;
|
||||||
var storedHash = null;
|
var storedHash = null;
|
||||||
document.getElementById('numPages').textContent =
|
document.getElementById('numPages').textContent =
|
||||||
mozL10n.get('page_of', {pageCount: pagesCount});
|
mozL10n.get('page_of', {pageCount: pagesCount}, 'of {{pageCount}}');
|
||||||
document.getElementById('pageNumber').max = pagesCount;
|
document.getElementById('pageNumber').max = pagesCount;
|
||||||
PDFView.documentFingerprint = id;
|
PDFView.documentFingerprint = id;
|
||||||
var store = PDFView.store = new Settings(id);
|
var store = PDFView.store = new Settings(id);
|
||||||
@ -837,7 +845,8 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|||||||
var rect = viewport.convertToViewportRectangle(item.rect);
|
var rect = viewport.convertToViewportRectangle(item.rect);
|
||||||
rect = PDFJS.Util.normalizeRect(rect);
|
rect = PDFJS.Util.normalizeRect(rect);
|
||||||
image.src = kImageDirectory + 'annotation-' + type.toLowerCase() + '.svg';
|
image.src = kImageDirectory + 'annotation-' + type.toLowerCase() + '.svg';
|
||||||
image.alt = mozL10n.get('text_annotation_type', {type: type});
|
image.alt = mozL10n.get('text_annotation_type', {type: type},
|
||||||
|
'[{{type}} Annotation]');
|
||||||
var content = document.createElement('div');
|
var content = document.createElement('div');
|
||||||
content.setAttribute('hidden', true);
|
content.setAttribute('hidden', true);
|
||||||
var title = document.createElement('h1');
|
var title = document.createElement('h1');
|
||||||
@ -1018,8 +1027,10 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|||||||
delete self.loadingIconDiv;
|
delete self.loadingIconDiv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error)
|
if (error) {
|
||||||
PDFView.error(mozL10n.get('rendering_error'), error);
|
PDFView.error(mozL10n.get('rendering_error', null,
|
||||||
|
'An error occurred while rendering the page.'), error);
|
||||||
|
}
|
||||||
|
|
||||||
self.stats = pdfPage.stats;
|
self.stats = pdfPage.stats;
|
||||||
self.updateStats();
|
self.updateStats();
|
||||||
@ -1163,7 +1174,8 @@ var DocumentOutlineView = function documentOutlineView(outline) {
|
|||||||
if (!outline) {
|
if (!outline) {
|
||||||
var noOutline = document.createElement('div');
|
var noOutline = document.createElement('div');
|
||||||
noOutline.classList.add('noOutline');
|
noOutline.classList.add('noOutline');
|
||||||
noOutline.textContent = mozL10n.get('no_outline');
|
noOutline.textContent = mozL10n.get('no_outline', null,
|
||||||
|
'No Outline Available');
|
||||||
outlineView.appendChild(noOutline);
|
outlineView.appendChild(noOutline);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user