Javascript functions
All functions you can call in your Javascript code
Last updated
All functions you can call in your Javascript code
Last updated
The JS library exposes functions that you can use anywhere in your code. (just make sure the library is already loaded when calling one of these functions)
payload(Object):
words(Array)
t(Integer): word type, see
w(String): string to translate
languageTo(String): translation destination language code
callback(Function)
None
code(String): the ISO 639-1 2-letter code of
None
This function checks the visitors preferred languages, and finds the best match among the languages you support on Weglot. It's the function used internally when you use the autoSwitch
function
term(String): Any term written in the current language of the page.
callback(Function): A function that will be called whenever the search term in the original language is available. Takes one String argument
code(String): the ISO 639-1 2-letter code of a language you're supporting on your website
code is either originalLanguage or one of the destinationLanguages
You can subscribe your own code to Weglot-specific events. When these events occur, the callback function you have defined will be called.
This is called right after a language has changed on the page
The callback function will be called with two optional arguments:
newLanguage (String): the 2-letter code of the language the page changed to
previousLanguage (String): the 2-letter code of the previous language of the page
Example:
This event is only available with our Javascript integration, not with subdomain or subdirectory integration.
This is called right after the call to Weglot.initialize(options) has been successful, but before the switchers are created and the page is translated
The callback function will be called with no argument.
This is called right after the switchers have been created.
The callback function will be called with one optional argument: initialLanguage
Example:
With Weglot.off
, you can unsubscribe the events you subscribed to with Weglot.on
eventName(String): mandatory field, the name of the event you want to unsubscribe from
callbackFunction(Function): optional field, if you'd like to target a specific function
Called to initialize Weglot. See