Commit fafc48fb authored by Robert Lyon's avatar Robert Lyon Committed by Son Nguyen
Browse files

Allow the pdf viewer to display menu items in user's lang (Bug 1423435)



Change-Id: Ibc87e7ae48f7ed8362779977b82d4269fd0c50df
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 11503817
......@@ -6236,7 +6236,7 @@ function webViewerInitialized() {
document.getElementById('fileInput').value = null;
}
var locale = PDFJS.locale || navigator.language;
var locale = params.lang || PDFJS.locale || navigator.language;
if (PDFViewerApplication.preferencePdfBugEnabled) {
// Special debugging flags in the hash section of the URL.
......
......@@ -30,6 +30,7 @@ class PluginBlocktypePdf extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $USER;
require_once(get_config('docroot') . 'lib/view.php');
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
......@@ -55,8 +56,21 @@ class PluginBlocktypePdf extends PluginBlocktype {
$urlbase = profile_url($viewauthor) . '/';
}
}
$result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&view=' . $instance->get('view')
// Send the current language to the pdf viewer
$language = current_language();
$language = str_replace('_', '-', substr($language, 0, ((substr_count($language, '_') > 0) ? 5 : 2)));
if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
// In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this
$language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2));
if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
// In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese)
$language = substr($language, 0, 2);
if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
$language = 'en-GB';
}
}
}
$result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view')
. '" width="100%" height="500" frameborder="0"></iframe>';
require_once(get_config('docroot') . 'artefact/comment/lib.php');
......
......@@ -18,7 +18,6 @@
document.body.className = 'js';
document.body.style.display = 'block';
document.getElementById('nojsdownload').style.display = 'none';
document.getElementById('outerContainer').className = 'loadingInProgress';
}
</script>
......@@ -31,9 +30,9 @@
</head>
<body class="no-js">
<body class="no-js loadingInProgress" tabindex="1">
<div id="nojsdownload" class="no-js"><a href="{$url|safe}&download=1">{$title}</a></div>
<div id="outerContainer" class="loadingInProgress js">
<div id="outerContainer">
<div id="sidebarContainer">
<div id="toolbarSidebar">
......@@ -204,14 +203,14 @@
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Fit Page</option>
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Full Width</option>
<option id="customScaleOption" title="" value="custom"></option>
<option title="" value="0.5">50%</option>
<option title="" value="0.75">75%</option>
<option title="" value="1">100%</option>
<option title="" value="1.25">125%</option>
<option title="" value="1.5">150%</option>
<option title="" value="2">200%</option>
<option title="" value="3">300%</option>
<option title="" value="4">400%</option>
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
</select>
</span>
</div>
......
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