Disabling loading of translation.json for performance improvement

69 views
Skip to first unread message

sbi

unread,
Aug 27, 2018, 4:36:00 AM8/27/18
to PDFTron WebViewer
Hello,

just a quick question: Is it possible to prevent the WebViewer from loading the translation.json during intitialization?
This would improve our performance a little bit and save a server roundtrip on mobile devices.

We are overwriting the translations in our config file anyways so loading the file is unnecessary for us. Can we disable/change this behaviour (preferrably by changing our config and without editing the original webviewer files)?

Thanks in advance!

Justin Jung

unread,
Aug 28, 2018, 3:06:56 PM8/28/18
to PDFTron WebViewer
Hello,

Unfortunately, it cannot be disabled unless you edit ControlUtil.js directly.
In ControlUtils.initialize function, you can comment out the following block:

window.ControlUtils.i18nInit(function() {
  if (!window.CanvasRenderingContext2D) {
    notSupportedCallback();
  }
});



Justin Jung
Software Developer
PDFTron Systems Inc.

sbi

unread,
Sep 17, 2018, 5:49:58 AM9/17/18
to PDFTron WebViewer
Hi Justin,

thanks for the quick response and the provided hotfix. It seems to work pretty well.

Will the new ui provide an easier way to do this. We would like to prevent editing WebViewer sources as much as possible, as it hinders upgradeability.

Thanks, Sascha

Justin Jung

unread,
Sep 17, 2018, 5:16:06 PM9/17/18
to PDFTron WebViewer
Hello Sascha,

Unfortunately, our new UI also uses i18n to support internationalization. Basically any UI components are expecting to get the strings from json file, so it wouldn't be possible to change that behaviour other than creating your own version of the UI. I would recommend to keep your custom code in a version control so that when there's an update you can simply diff them.

Justin Jung
Software Developer
PDFTron Systems Inc.
-------------------------------------------------------------------------------------------------------
scireum GmbH, Eisenbahnstraße 24, 73630 Remshalden

Am schnellsten erreichen Sie uns per Chat über MEMOIO: Support Channel  

MEMOIO ist eine B2B Messaging Lösung. Weitere Informationen finden Sie unter: https://www.scireum.de/memoio



Fax: +49 (0) 7151 90316-19
Internet: https://www.scireum.de
 
Geschäftsführer: Michael Haufler, Andreas Haufler
Amtsgericht Stuttgart, HRB 732171

unsere Datenschutzerklärung hier: https://www.scireum.de/scireum/datenschutz

--
You received this message because you are subscribed to the Google Groups "PDFTron WebViewer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfnet-webview...@googlegroups.com.
To post to this group, send email to pdfnet-w...@googlegroups.com.
Visit this group at https://groups.google.com/group/pdfnet-webviewer.
For more options, visit https://groups.google.com/d/optout.

sbi

unread,
Sep 18, 2018, 2:55:15 AM9/18/18
to PDFTron WebViewer
Hello Justin,

we think a way to disable the i18next initialization via a flag would be optimal as we now initialize i18next with our own parameters (passing the translations json directly).

If thats not possible, will a similar "hotfix" via commenting out some code work in the new UI too

Justin Jung

unread,
Sep 18, 2018, 6:59:28 PM9/18/18
to PDFTron WebViewer
Hi Sascha,

Yes, it will be possible to change the source to stop the initialization.
Would you be able to describe more about your use case?
How are you hooking into the existing WebViewer translation keys?

Justin Jung
Software Developer
PDFTron Systems Inc.

sbi

unread,
Sep 19, 2018, 11:12:37 AM9/19/18
to PDFTron WebViewer
Hi Justin,

the reason we want to prevent the loading of the translation json files is that we already load all the translations for our frontend elsewhere (including the webviewer translations) in the correct language and pass these to the viewer.
So the translations would be an unnecessary round trip for the browser and double the maintenance for us.

Thats the code we are using in our config file to initialize the translation engine ourself and pass our translated texts:

i18n.init({
resStore: {universal: {translation: Config.translation}},
defaultValueFromContent: false,
lng: "universal",
fallbackLng: false,
useCookie: false,
useDataAttrOptions: true
}, function () {
$(document).trigger('i18nready');
});

Justin Jung

unread,
Sep 19, 2018, 5:39:04 PM9/19/18
to PDFTron WebViewer
Hi Sascha,

Thanks for the clarification. In our new viewer v1 release, we will see if we can provide a better API for this use case.
Until then, it would be inevitable to change the source code if you want to disable it.

sbi

unread,
Sep 20, 2018, 4:59:46 AM9/20/18
to PDFTron WebViewer
Hi Justin,

a proper API for this would be awesome! In the meantime we change the source code to use our own i18next initialization.

Thanks!

sbi

unread,
Oct 18, 2018, 8:55:06 AM10/18/18
to PDFTron WebViewer
What is the way to do this now WebViewer 4.0 is released?

Justin Jung

unread,
Oct 18, 2018, 9:36:57 PM10/18/18
to PDFTron WebViewer
Hi Sascha,

You can add disableI18n: true to your WebViewer constructor.

Justin Jung
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages