Fallback locale string for JS code; simplify locale embedding for the extension

This commit is contained in:
Yury Delendik 2012-05-04 08:37:08 -05:00
parent 2d81ca1586
commit 89156cec89
4 changed files with 33 additions and 26 deletions

View File

@ -21,7 +21,8 @@
/*
Additional modifications for PDF.js project:
- 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';
@ -221,8 +222,10 @@
}
// translate a string
function translateString(key, args) {
function translateString(key, args, fallback) {
var data = getL10nData(key);
if (!data && fallback)
data = {textContent: fallback};
if (!data)
return '{{' + key + '}}';
return substArguments(data.textContent, args);

View File

@ -327,7 +327,7 @@ target.firefox = function() {
// Modify the viewer so it does all the extension-only stuff.
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_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_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');

View File

@ -1,15 +1,7 @@
<!-- This snippet is used in firefox extension, see Makefile -->
<base href="resource://pdf.js/web/" />
<script type="text/javascript">
(function() {
// 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 type="application/l10n">
<!-- PDFJSSCRIPT_LOCALE_DATA -->
</script>
<script type="text/javascript" src="l10n.js"></script>
<script type="text/javascript" id="PDFJS_SCRIPT_TAG">

View File

@ -349,11 +349,13 @@ var PDFView = {
},
function getDocumentError(message, exception) {
var loadingIndicator = document.getElementById('loading');
loadingIndicator.textContent = mozL10n.get('loading_error_indicator');
loadingIndicator.textContent = mozL10n.get('loading_error_indicator',
null, 'Error');
var moreInfo = {
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;
},
function getDocumentProgress(progressData) {
@ -461,22 +463,27 @@ var PDFView = {
moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true');
errorMoreInfo.value =
mozL10n.get('error_build', {build: PDFJS.build}) + '\n';
mozL10n.get('error_build', {build: PDFJS.build},
'PDF.JS Build: {{build}}') + '\n';
if (moreInfo) {
errorMoreInfo.value +=
mozL10n.get('error_message', {message: moreInfo.message});
mozL10n.get('error_message', {message: moreInfo.message},
'Message: {{message}}');
if (moreInfo.stack) {
errorMoreInfo.value += '\n' +
mozL10n.get('error_stack', {stack: moreInfo.stack});
mozL10n.get('error_stack', {stack: moreInfo.stack},
'Stack: {{stack}}');
} else {
if (moreInfo.filename) {
errorMoreInfo.value += '\n' +
mozL10n.get('error_file', {file: moreInfo.filename});
mozL10n.get('error_file', {file: moreInfo.filename},
'File: {{file}}');
}
if (moreInfo.lineNumber) {
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) {
var percent = Math.round(level * 100);
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;
},
@ -523,7 +531,7 @@ var PDFView = {
var id = pdfDocument.fingerprint;
var storedHash = null;
document.getElementById('numPages').textContent =
mozL10n.get('page_of', {pageCount: pagesCount});
mozL10n.get('page_of', {pageCount: pagesCount}, 'of {{pageCount}}');
document.getElementById('pageNumber').max = pagesCount;
PDFView.documentFingerprint = 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);
rect = PDFJS.Util.normalizeRect(rect);
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');
content.setAttribute('hidden', true);
var title = document.createElement('h1');
@ -1018,8 +1027,10 @@ var PageView = function pageView(container, pdfPage, id, scale,
delete self.loadingIconDiv;
}
if (error)
PDFView.error(mozL10n.get('rendering_error'), error);
if (error) {
PDFView.error(mozL10n.get('rendering_error', null,
'An error occurred while rendering the page.'), error);
}
self.stats = pdfPage.stats;
self.updateStats();
@ -1163,7 +1174,8 @@ var DocumentOutlineView = function documentOutlineView(outline) {
if (!outline) {
var noOutline = document.createElement('div');
noOutline.classList.add('noOutline');
noOutline.textContent = mozL10n.get('no_outline');
noOutline.textContent = mozL10n.get('no_outline', null,
'No Outline Available');
outlineView.appendChild(noOutline);
return;
}