Skip to content

Localization

Nicolas Kruchten edited this page Jun 22, 2016 · 6 revisions

What does "localization" mean? Localization is the process of customizing the display of information for a particular context: translating labels to a particular language and tweaking the display of numbers to fit a particular convention (national, currency, scientific etc).

By default, PivotTable.js renders a UI with English-language string constants, and all of the default number-formatting follows US conventions (i.e. , as the thousands separator, . as the decimal separator). Like almost everything else with this library, however, this is overrideable.

The object found at $.pivotUtilities.locales contains locale-specific aggregators, renderers and locale-strings. By default the only entry is in this array is under the key en. The locale parameter to pivotUI() (see Parameters) controls which locale is used, and the default value is en. The net effect of this is that the default aggregators, renderers and locale-strings are in the en locale, although they remain overridable.

To localize PivotTable.js, you need to first add an entry to $.pivotUtilities.locales (i.e. by loading an additional 'language pack' Javascript file which does this) and then call pivotUI() with the locale parameter set accordingly. An example of a French 'language pack' is provided with PivotTable.js as pivot.fr.coffee or compiled to pivot.fr.js and there is an example of the French localization in action in the examples section. To write your own 'language pack' you will find the documentation on Aggregators useful, specifically the section on 'aggregator templates' which allow you to customize the output formatting.

The older, more flexible, more involved way to localize is to pass in your own values to the renderers, aggregators and localeStrings parameters on every call to pivotUI().