question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically changing language of pdf viewer

See original GitHub issue

I wanted to configure chunk size on pdf.js so instead of opening pdfs with the link i’m opening them when the iframe of the viewer is initialized with the open function from viewer.js: open: function open(file, args) {... $(element)[0].contentWindow.PDFViewerApplication.open(viewerUrl(), { rangeChunkSize: chunkSize() });

This works fine, but the problem is that i don’t know how to set the local language dynamically. I managed to do it with the function setLanguage ($(element)[0].contentWindow.document.webL10n.setLanguage("sl-SI");), but this changes only 1 part (see the picture) image

Is there a better way to do it ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ZeviLiaocommented, Jul 27, 2021

viewer.html link add locale query parameter , pdf/web/viewer.html?locale=${langCode}&file= then in viewer.js add two lines in class GenericL10n constructor class GenericL10n { constructor(lang) { const urlParams = new URLSearchParams(window.location.search); lang = urlParams.get(‘locale’); this._lang = lang;

it works for me.

0reactions
EugenMayercommented, Oct 18, 2022

You should rather patch it this way, change the initialization in _initializeL10n

  async _initializeL10n() {
    // HACK START
    const urlParams = new URLSearchParams(window.location.search);
    let urlParamLocale = urlParams.get('locale');
	// HACK END

    this.l10n = this.externalServices.createL10n({
       // HACK START
      locale: urlParamLocale || _app_options.AppOptions.get("locale")
	  // HACK END
    });
    const dir = await this.l10n.getDirection();
    document.getElementsByTagName("html")[0].dir = dir;
  },

or as a patch

--- viewer.js	2022-10-18 12:59:43.380000000 +0200
+++ viewer.js.patched	2022-10-18 13:20:17.595672298 +0200
@@ -1899,9 +1899,13 @@
   },

   async _initializeL10n() {
+    const urlParams = new URLSearchParams(window.location.search);
+    let urlParamlocale = urlParams.get('locale');
+
     this.l10n = this.externalServices.createL10n({
-      locale: _app_options.AppOptions.get("locale")
+      locale: urlParamlocale || _app_options.AppOptions.get("locale")
     });
+
     const dir = await this.l10n.getDirection();
     document.getElementsByTagName("html")[0].dir = dir;
   },
@@ -18623,4 +18627,4 @@

 /******/ })()
 ;
-//# sourceMappingURL=viewer.js.map
\ No newline at end of file
+//# sourceMappingURL=viewer.js.map
Read more comments on GitHub >

github_iconTop Results From Across the Web

Localization: Change Languages in JavaScript PDF Viewer
Localization: Updating Languages in Our JavaScript PDF Viewer · Chinese Simplified / Chinese Traditional (zh-Hans/zh-Hant) · Croatian (hr) · Czech (cs) · Danish...
Read more >
Static and Dynamic Viewers | Transit Training
In the PDF viewer/Word preview a static viewer can be combined with a dynamic preview: Source language: If a PDF file of the...
Read more >
How to dynamically change the "src" or "data" for a PDF Object ...
I'm hoping the instance of Adobe Acrobat Reader will stay on the screen, but the new document will load into it. Here is...
Read more >
Create dynamic PDF documents in Adobe InDesign
Create interactive PDF documents with buttons, movies and sound clips, hyperlinks, bookmarks, and page transitions in InDesign.
Read more >
Dynamically displaying PDF in a region - Oracle Communities
The goal is to have a region on the same page, which displays the currently selected pdf using the browsers PDF viewer (this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found