Comment puis-je changer dynamiquement la langue dans Google transliterate API à partir de JavaScript
Je ne peux changer la langue qu'une seule fois(première fois après le chargement de la page). Si je sélectionne une autre langue après la première sélection, la langue ne change pas. Voici mon code
<select id="selectedLanguageId" onchange="changeLanguage(this.value)">
<option value="ENGLISH" selected="selected" >English</option>
<option value="HINDI">Hindi</option>
<option value="TAMIL">Tamil</option>
<option value="MALAYALALM">Malayalam
function changeLanguage(val) {
var data = val;
$("#stdTextArea").html("");
var options = {
sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage: [google.elements.transliteration.LanguageCode[data]],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
var control = new google.elements.transliteration.TransliterationControl(options);
control.makeTransliteratable(['stdTextArea']);
}
0
1 answers
Cela peut vous aider!
<script type="text/javascript">
// Load the Google Transliterate API
google.load("elements", "1", {
packages: "transliteration"
});
function changelanguage(lan) {
if (lan == 'Arabic') {alert (" لا تنس أن تضغط G+ctrl قبل البدء بكتابة اللغة العربية");}
switch (lan){
case "Hindi":
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.HINDI],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
break;
case "Arabic":
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.ARABIC],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
break;
case "Malayalam":
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.MALAYALAM],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
break;
default:
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.ENGLISH],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
}
// Create an instance on TransliterationControl with the required
// options.
var control =
new google.elements.transliteration.TransliterationControl(options);
// Enable transliteration in the textbox with id
// 'transliterateTextarea'.
control.makeTransliteratable(['stdTextArea']);
}
</script>
0
Author: Benjith Kizhisseri, 2018-05-09 04:14:51