PrizmDoc Viewer v13.21 Release - Updated
Developer Guide / Viewer / Configure the Viewer / Configuration Options / Localize the Viewer
In This Topic
    Localize the Viewer
    In This Topic

    Introduction

    The Viewer has a language localization feature which allows you to customize labels and text using a language JavaScript object. The language object is passed as a parameter in the Viewer plugin configuration options:

    Example

    var pluginOptions = {
        documentID: viewingSessionId,
        language: languageItems,
        template: htmlTemplates
    }
    
    

    Using the Language Parameters

    In viewer.js the language parameters are used in various places. The following example shows a message with the printRangeError language parameter:

    Example

    viewer.notify({message: viewer.language.printRangeError});
    
    

    When the HTML templates are loaded, using the Underscore.js Template utility function, the language object is used as template data:

    Example

    element.html(_.template(options.template.viewer, options.language))
    
    

    The language parameters are then referenced as variables in the templates:

    Example

    <!-- This is using the "rotate" parameter from language.json -->
    <button data-pcc-rotate class="pcc-icon pcc-icon-rotate"
         title="<%= rotate %>"></button>
    
    

    For more information on template syntax see the Underscore.js Template documentation at http://underscorejs.org/#template.

    Common Pitfalls

    When editing the language.json file or the templates there may be some errors for which the cause may not be immediately obvious. Here are some common console errors and their possible causes:

    Uncaught TypeError

    • Cannot read property languageElements of undefined - This error is thrown when viewer.js cannot find the language object. Verify that the language.json file is being read and parsed correctly.

    Uncaught ReferenceError

    • x is not defined - This error could be thrown if you have referenced a variable in the HTML templates that is not defined as data when loading the template. Check to see that this variable exists in either the language.json file or as a template data property used when loading a template.