Methods

View the JS SDK public methods.

isReady

Check is LangShop ready

        
/**
 * @return {boolean}
 */
LangShopSDK.isReady();

// true
        
    

getLanguages

Returns array of languages instances

        
/**
 * @returns {Language[]}
 */
LangShopSDK.getLanguages();

// [ { "code": "en", "title": "English", "icon": null }, { "code": "fr", "title": "French", "icon": null } ]
        
    

getCurrentLanguage

Returns current page language

        
/**
 * @returns {Language}
 */
LangShopSDK.getCurrentLanguage();

// { "code": "fr", "title": "French", "icon": null }
        
    

getCurrencies

Returns array of currencies instances

        
/**
 * @returns {Currency[]}
 */
LangShopSDK.getCurrencies();

// [ { "code": "usd", "title": "US Dollar", "icon": null, "formatWithCurrency": "${{amount}} USD", "formatWithoutCurrency": "${{amount}}", "rate": 1 }, { "code": "eur", "title": "Euro", "icon": null, "formatWithCurrency": "€{{amount}} EUR", "formatWithoutCurrency": "€{{amount}}", "rate": 0.8868 } ]
        
    

getCurrentCurrency

Returns current page currency

        
/**
 * @returns {Currency}
 */
LangShopSDK.getCurrentCurrency();

// { "code": "eur", "title": "Euro", "icon": null, "formatWithCurrency": "€{{amount}} EUR", "formatWithoutCurrency": "€{{amount}}", "rate": 0.8868 }
        
    

switchLanguage

Switch to another language by alphabetic code

        
/**
 * @param {string} code
 */
LangShopSDK.switchLanguage("fr");
        
    

switchCurrency

Switch to another currency by alphabetic code

        
/**
 * @param {string} code
 */
LangShopSDK.switchCurrency("eur");
        
    

convertAmount

Convert number from default currency to current

        
/**
 * @param {number} cents
 * @returns {number}
 */
LangShopSDK.convertAmount(100);

// 88.68
        
    

getMoneyFormat

Returns current currency money format or default

        
/**
 * @returns {string}
 */
LangShopSDK.getMoneyFormat();

// €{{amount}} EUR
        
    

formatMoney

Converts cents to money representation of the current currency

        
/**
 * @param {number} cents
 * @returns {string}
 */
LangShopSDK.formatMoney(100);

// €0.88 EUR
        
    

createLanguagesSwitcher

Create new languages switcher

        
/**
 * @param {HTMLElement} target
 * @param {Object} switcher
 * @returns {Switcher}
 */
LangShopSDK.createLanguagesSwitcher(document.body, {

    /**
     * Switcher type: "dropdown", "inline", "select".
     * @type {string}
     */
    "type": "inline",

    /**
     * Switcher icons type: "rounded", "circle", "square", "rectangle".
     * @type {string}
     */
    "icons": "circle",

    /**
     * Switcher position: "relative", "bottom-right", "bottom-left", "top-right", "top-left".
     * @type {string}
     */
    "position": "bottom-right",

    /**
     * Switcher display mode: "all", "titles", "icons".
     * @type {string}
     */
    "display": "all",

    /**
     * Offsets from the corner for non-relative switcher positions, e.g.: "10px", "5%"
     * @type {string}
     */
    "offset": "10px",

    /**
     * Display languages alphabetic codes in uppercase instead of languages titles.
     * @type {boolean}
     */
    "shortTitles": false,

    /**
     * Use predesigned switcher styles.
     * @type {boolean}
     */
    "defaultStyles": true
});
        
    

createCurrenciesSwitcher

Create new currencies switcher

        
/**
 * @param {HTMLElement} target
 * @param {Object} switcher
 * @returns {Switcher}
 */
LangShopSDK.createCurrenciesSwitcher(document.body, {

    /**
     * Switcher type: "dropdown", "inline", "select".
     * @type {string}
     */
    "type": "dropdown",

    /**
     * Switcher icons type: "rounded", "circle", "square", "rectangle".
     * @type {string}
     */
    "icons": "rounded",

    /**
     * Switcher position: "relative", "bottom-right", "bottom-left", "top-right", "top-left".
     * @type {string}
     */
    "position": "relative",

    /**
     * Switcher display mode: "all", "titles", "icons".
     * @type {string}
     */
    "display": "titles",

    /**
     * Offsets from the corner for non-relative switcher positions, e.g.: "10px", "5%"
     * @type {string}
     */
    "offset": "0px",

    /**
     * Display currencies alphabetic codes in uppercase instead of currencies titles.
     * @type {boolean}
     */
    "shortTitles": true,

    /**
     * Use predesigned switcher styles.
     * @type {boolean}
     */
    "defaultStyles": true
});
        
    

on

Subscribe to event by it name

        
function onLangShopReady() {
    ...
}

/**
 * @param {string} event
 * @param {function} callback
 */
LangShopSDK.on("ready", onLangShopReady);
        
    

off

Remove subscription on event by it name

        
function onLangShopReady() {
    ...
}

/**
 * @param {string} event
 * @param {function} callback
 */
LangShopSDK.off("ready", onLangShopReady);
        
    

Start your 3-day free trial today!

Try LangShop free for 3 days by entering your domain of Shopify store.