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 english
English
chinese_simplified
简体中文
chinese_traditional
繁體中文
japanese
日本語
korean
한국어
afrikaans
afrikaans
albanian
albanian
amharic
amharic
arabic
بالعربية
armenian
Արմենյան
azerbaijani
azerbaijani
bengali
বেঙ্গালী
bosnian
bosnian
bulgarian
български
burmese
ဗာရမ်
catalan
català
croatian
hrvatski
czech
český
danish
dansk
deutsch
Deutsch
dutch
nederlands
estonian
eesti keel
filipino
Pilipino
finnish
suomi
french
Français
gujarati
ગુજરાતી
greek
ελληνικά
haitian_creole
Kreyòl ayisyen
hebrew
היברית
hungarian
magyar
hindi
हिन्दी
icelandic
Ísland
indonesian
Indonesia
inuktitut
ᐃᓄᒃᑎᑐᑦ
irish
Íris
italian
italiano
kannada
ಕನ್ನಡ್
khmer
ខ្មែរ
kurdish
Kurdî
lao
ກະຣຸນາ
latvian
latviešu
lithuanian
Lietuva
malagasy
Malagasy
malay
Malay
malayalam
മലമാലം
marathi
मराठी
maltese
Malti
maori
Maori
nepali
नेपाली
norwegian
Norge
oriya
ଓଡିଆ
pashto
پښتو
persian
Persian
polish
Polski
portuguese
português
punjabi
ਪੰਜਾਬੀ
russian
Русский язык
romanian
Română
samoan
lifiava
spanish
Español
slovak
Slovenská
slovene
slovenščina
swahili
Kiswahili
swedish
Svenska
tamil
தாமில்
telugu
తెలుగు
thai
คนไทย
tongan
汤加语
turkish
Türkçe
ukrainian
Українська
urdu
اوردو
vietnamese
Tiếng Việt
Demo:
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'); }