Follow

Website Localizer Translate JS Usage

Installation:

Once the widget has been enabled via the “Website Localizer” tab in the Translate.com site, add these script tags to your website, and replace “my_key” with your website’s key:

 

<script src="//wt-js.translate.com/translate.js" type="text/javascript"></script>

<script type="text/javascript">TranslateJS.init({"key": "my_key"});</script>

List of exported functions:

  • translate: called by the selected language of the widget, with the language code as the first argument.
  • init: called once on initial page load. Required argument is a javascript object with at least a “key” entry defined.
  • build_widget: can be called any time after the destroy_widget function is called. This function re-builds the widget and adds any associated elements to the DOM.
  • destroy_widget: can be called at any time after the initial init function is called. This function performs a clean removal of the widget and associated elements from the DOM.

Example usage:

  • translate: TranslateJS.translate(‘en’);
  • init: TranslateJS.init({ ‘key’: ‘my_key_goes_here’});
  • build_widget: TranslateJS.build_widget();
  • destroy_widget: TranslateJS.destroy_widget();

Comments