Add Google Translation Links
Below are explanations for two functions included in the script, along with tips on using the code.
function smo_write_google_tanslate_links ( outputtype, targettype, target, mediadirectory, langarray )
smo_write_google_translate_links is the core function. This will output HTML code that will show images, text links or both that link to the Google translation tool to translate the current page. (The function is dependent on other functions included in the script.) The attributes are explained below:
- outputtype (string) : You should enter one of the following strings: 'text' to display text links; 'image' to display image links; 'both' to display both.
- targettype (string/mixed) : You must enter the target type for the output. Enter 'id' if you want to fill an element with the translation links; enter 'write' to write the links to the location in the document where the function is called; pass an empty string to return the HTML contents for use in other functions.
- target (string) : target is only used if targettype is set to 'id'. Pass the ID of the element you want to put the links in; the contents of the element will be replaced with the links.
- mediadirectory (string) : when using image links, you must pass the directory where you keep the images for this function. A list of images you must create is listed below. If no value is passed, the code assumes that the images are housed in the document's current directory.
- langarray (array) : not yet in use. This value will allow you to designate which languages to use and what order to place them when implemented.
The images you must create include:
Example code below:
This function is utilized by smo_write_google_tanslate_links(). What this function does is actually send the browser to the Google tranlation site for the current page, using the language passed. The passed language must be one of the following values:
To make a button to translate a page into German, you could add an onclick handler to call smo_goto_google_translate('german'). Note that the values must be lowercase.
As with all of my code, please make sure that your usage of these scripts abides by my Terms & Conditions.