Javascript API
With Bablic Javascript API you can control your web page localization on run-time.
widget.get, widget.update, widget.hide, widget.show, widget.expand, widget.collapse, widget.element, widget.switch
languages.get, languages.update, languages.hide, languages.show, languages.flag
element, element.restore, element.translate, element.exclude, element.include,
element.watch, element.pre, element.post
selector, selector.exclude, selector.include,
selector.pre, selector.post
getLocale, getLink, redirectTo, __, __n, exclude, include, markup, processElement, on
widget.get()
Gets the widget configurations
widget.update(config)
Sets the widget configuration and renders the widget. Use this method to change widget position/color/type/size.
widget.hide()
Hides the widget
widget.show()
Shows the widget
widget.expand()
Opens the widget to show all languages.
widget.collapse()
Close the widget to show only single language.
widget.element()
Returns the DOM Element that contains the widget.
widget.switch()
Turns the given element into a language switch (for websites with only 1 language). The element will display the language of the language, and will switch to that language on click
languages.get(languageCode /*Optional*/)
Returns language configuration. If no languageCode is given, returns an array of all language configurations
languages.update(config)
Updates the language config. If needed, renders widget or switches page language.
languages.hide(languageCode)
Hides the given language from widget. Prevent Bablic from showing that language, and switch to original if this language is the current language of the page.
languages.show(languageCode)
Restores a language, if it was hidden
languages.flag(languageCode,flagSize)
Returns the flag image url of the given language and the given size.
size is an integer between 1 and 6, with the following values:
1=16px, 2=24px, 3=32px, 4=48px, 5=64px, 6=128px
element(elementsOrSelector)
Wrap element or selector that are currently loaded in the DOM
element(elementsOrSelector).restore()
Restore the given elements, or element query selector, to the original language. You can pass a single DOM element, a list of elements, or a single CSS Query Selector as string. The matched elements will be reverted to the original language unless element.translate is called on them.
element(elementsOrSelector).translate()
Undo element.restore
element(elementsOrSelector).exclude()
Excludes this element from translation all together (Same as bablic.exclude())
element(elementsOrSelector).include()
Undo element.exclude
element(elementsOrSelector).markup(markupKey,markupValue)
Adds Bablic markup to an element
element(elementsOrSelector).watch(eventHandler)
Fire the eventHandler every time Bablic has changed the given element
element(elementsOrSelector).pre()
Fire an event just before this element is going to be processed for translation
removeHighlight(this);
}).post(function() {
showHighlight(this);
}).done();
element(elementsOrSelector).post()
Fire an event just after this element was processed for translation
removeHighlight(this);
}).post(function() {
showHighlight(this);
}).done();
selector(cssSelector)
Wrap a selector accross all document. The elements matching this selector might not be loaded in the DOM yet
selector(cssSelector).exclude()
Excludes this selector from translation all together (Same as bablic.exclude())
selector(cssSelector).include()
Undo selector.exclude
selector(cssSelector).markup(markupKey,markupValue)
Adds Bablic markup to all elements matching
selector(cssSelector).pre()
Fire an event just before a matching element is going to be processed for translation
removeHighlight(this);
}).post(function() {
showHighlight(this);
}).done();
selector(cssSelector).post()
Fire an event just after a matching element was processed for translation
removeHighlight(this);
}).post(function() {
showHighlight(this);
}).done();
getLocale()
Returns the current locale code ('en','ch','es_ar'...)
getLink(languageCode)
Returns the URI of the current web page with the given locale
redirectTo(languageCode,options)
Switches the page language to the given language code. Use options.forceRedirect to make sure page is refreshed.
__(textToTranslate,..)
Returns the localized text. Supports format templates
__n(single_text, plural_text, count, ..)
Returns the localized string according the the right plural state.
exclude(querySelector | Element | HTMLCollection )
Excludes the elements from translation
include(querySelector | Element | HTMLCollection )
Includes the elements for translation, even if parents were excluded.
markup(markupKey,querySelector | Element | HTMLCollection,value)
Applies markup for given elements
processElement(Element)
Bablic will process the given element syncronicly
on(eventName,handlerFunc)
Listen to Bablic event. To read more check out Javascript Events