JavaScript customizations

Each localized page has access to JavaScript global object window.glopalYou can use it to determine if code is running on original or localized page:

if (window.glopal !== undefined) {
    /* Remove newsletter popup on localized pages */
    $.fancybox && $.fancybox.close(true)


Inside property you can find useful data about language and currency and localized page:

    "countryCode": "PL",
    "languageTag": "pl-PL",
    "currencyCode": "PLN",
    "currencySymbol": "zł"

You can use them for dynamic customizations:

if (window.glopal !== undefined) {
  /* load additional font for greek language */
  (function() {
   a if (!'el-')) {
    const n = document.createElement('style');
    n.textContent = "@font-face {font-family:Interstate; src:local(serif);}";

Content localization

Glopal will automatically localize all visible content and links, even if it is updated dynamically after the initial page load.

Even that in general you don't need customizations to get localization of your website, in some specific cases it may be useful to have additional control. For example there could be analytics code that is not visible or elements of the UI that should be sorted where translating dynamic content before it is rendered can be useful. Glopal is exposign public API that can be used in site JavaScript code in such scenarios.

If localizing visible elements, it is required to apply gp-noloc attributes on already localized content to avoid double-localization.

Method window.glopal.localizeUrl() can be used to get localized links for the current site.

// localizeUrl(url: string): string

// On FR localized site, result:


Method window.glopal.localize() can be used to get translations inside your code:

// type LocalizeArgs = string[] | { [key: string]: string };
// localize<T extends LocalizeArgs>(args: T): Promise<T>

]).then(data => console.log(data)); // ["Poniedziałek", "Wtorek", "Środa"]

  "monday": "Monday",
  "tuesday": "Tuesday",
  "wednesday": "Wednesday"
}).then(data => console.log(data)); // {"monday": "Poniedziałek", "tuesday": "Wtorek", "wednesday": "Środa"}

Last updated