Translate-Go Documentation
1. Getting started with Translate-Go.#
- Add to the footer of index.html
<script src="https://public.cmche.com/js/translate.mini.js"></script>
<script>
translate.language.setLocale('english'); // set the default language
translate.service.use('client.edge'); // set the translation service
translate.selectLanguageTag.show = false; // hide the language selection menu
translate.listener.start(); // listen for dynamic content changes
window.onload = function () { // vue.js or other frameworks need to be placed in the onload event
translate.execute(); // execute the translation
}
</script>
- Add to the menu.html
<div class="menu">
<a href="javascript:window.translate.changeLanguage('english');">English</a>
<a href="javascript:window.translate.changeLanguage('chinese_simplified');">中文</a>
<a href="javascript:window.translate.changeLanguage('japanese');">しろうと</a>
</div>
2. Configuration parameters Translate-Go.#
-
translate.language.setLocal: Set the default language, the default is ’english'.values views englishEnglishchinese_simplified简体中文chinese_traditional繁體中文japanese日本語korean한국어afrikaansafrikaansalbanianalbanianamharicamharicarabicبالعربيةarmenianԱրմենյանazerbaijaniazerbaijanibengaliবেঙ্গালীbosnianbosnianbulgarianбългарскиburmeseဗာရမ်catalancatalàcroatianhrvatskiczechčeskýdanishdanskdeutschDeutschdutchnederlandsestonianeesti keelfilipinoPilipinofinnishsuomifrenchFrançaisgujaratiગુજરાતીgreekελληνικάhaitian_creoleKreyòl ayisyenhebrewהיבריתhungarianmagyarhindiहिन्दीicelandicÍslandindonesianIndonesiainuktitutᐃᓄᒃᑎᑐᑦirishÍrisitalianitalianokannadaಕನ್ನಡ್khmerខ្មែរkurdishKurdîlaoກະຣຸນາlatvianlatviešulithuanianLietuvamalagasyMalagasymalayMalaymalayalamമലമാലംmarathiमराठीmalteseMaltimaoriMaorinepaliनेपालीnorwegianNorgeoriyaଓଡିଆpashtoپښتوpersianPersianpolishPolskiportugueseportuguêspunjabiਪੰਜਾਬੀrussianРусский языкromanianRomânăsamoanlifiavaspanishEspañolslovakSlovenskásloveneslovenščinaswahiliKiswahiliswedishSvenskatamilதாமில்teluguతెలుగుthaiคนไทยtongan汤加语turkishTürkçeukrainianУкраїнськаurduاوردوvietnameseTiếng ViệtDemo:
translate.language.setLocale('english'); -
translate.service.use: Set the translation service, the default is ‘client.edge’.- use the ‘client.edge’: Microsoft Edge browser translation service.
use the ’engine.google’: Google translation service.- use the ’translate.service’: use the server api translation service.
Demo:
translate.service.use('client.edge'); -
translate.selectLanguageTag.show: Show the language selection menu, the default is true.- true: show the language selection menu.
- false: hide the language selection menu.
Demo:
translate.selectLanguageTag.show = false; -
translate.listener.start(): Listen for dynamic content changes, the default is true. -
translate.execute(): Execute the translation, the default is true.Demo:
// if you use to javascript translate.execute(); // if you use to Vue.js React.js or other frameworks window.onload = function () { translate.execute(); } -
translate.selectionTranslate.start(): Start the selection translation, the default is true. -
translate.language.setUrlParamControl(): Use the url parameters to control the languageDemo:
// use the url parameters to control the language translate.language.setUrlParamControl(); /* example: * https://www.example.com/index.html?language=english // english * https://www.example.com/index.html?language=chinese_simplified // chinese_simplified * https://www.example.com/index.html?language=japanese // japanese */ -
translate.language.translateLanguagesRange: Set the range of languages to be translated, the default is all languages.Demo:
// only translate chinese_simplified, and japanese translate.language.translateLanguagesRange = ['chinese_simplified', 'japanese']; -
translate.ignore.id.push(#id): Don’t translate the element with the specified id.Demo:
// don't translate the element with the id of 'nav' translate.ignore.id.push('nav'); -
translate.ignore.class.push(.class): Don’t translate the element with the specified class.Demo:
// don't translate the element with the class of 'tab-header' translate.ignore.class.push('tab-header'); -
translate.ignore.tag.push(tag): Don’t translate the element with the specified tag.Demo:
// don't translate the element with the tag of 'span' translate.ignore.tag.push('span'); -
translate.setDocuments(array): Only translate the specified elements,if not set, all elements will be translated.Demo:
let docs = []; docs.push(document.getElementById('nav')); docs.push(document.getElementById('tab-body')); docs.push(document.getElementById('tab-footer')); translate.setDocuments(docs); -
translate.listener.renderTaskFinish=function(): Callback function after the translation is completed.Demo:
translate.listener.renderTaskFinish = function () { console.log('The translation is complete'); }