Asp.net
All Language Tanslate in Textbox --Type in Indian languages
Just Put following Code in you
.ASPX PAGE and run you get Above Output
.aspx code:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="test.aspx.cs"
Inherits="test"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
<script type="text/javascript">
// Load
the Google Transliteration API
google.load("elements",
"1", {
packages: "transliteration"
});
var
transliterationControl;
function
onLoad() {
var
options = {
sourceLanguage: 'en',
destinationLanguage: ['ar', 'hi', 'kn', 'ml', 'ta', 'te'],
transliterationEnabled: true,
shortcutKey: 'ctrl+g'
};
//
Create an instance on TransliterationControl with the required
//
options.
transliterationControl =
new
google.elements.transliteration.TransliterationControl(options);
//
Enable transliteration in the textfields with the given ids.
var
ids = ["transl2"];
transliterationControl.makeTransliteratable(ids);
//
Add the STATE_CHANGED event handler to correcly maintain the state
// of
the checkbox.
transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED,
transliterateStateChangeHandler);
//
Add the SERVER_UNREACHABLE event handler to display an error message
// if
unable to reach the server.
transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE,
serverUnreachableHandler);
//
Add the SERVER_REACHABLE event handler to remove the error message
//
once the server becomes reachable.
transliterationControl.addEventListener(
google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE,
serverReachableHandler);
//
Set the checkbox to the correct state.
document.getElementById('checkboxId').checked =
transliterationControl.isTransliterationEnabled();
//
Populate the language dropdown
var
destinationLanguage =
transliterationControl.getLanguagePair().destinationLanguage;
var
languageSelect = document.getElementById('languageDropDown');
var
supportedDestinationLanguages =
google.elements.transliteration.getDestinationLanguages(
google.elements.transliteration.LanguageCode.ENGLISH);
for
(var lang in
supportedDestinationLanguages) {
var
opt = document.createElement('option');
opt.text = lang;
opt.value =
supportedDestinationLanguages[lang];
if
(destinationLanguage == opt.value) {
opt.selected = true;
}
try
{
languageSelect.add(opt, null);
} catch
(ex) {
languageSelect.add(opt);
}
}
}
// Handler for STATE_CHANGED event which makes sure
checkbox status
//
reflects the transliteration enabled or disabled status.
function
transliterateStateChangeHandler(e) {
document.getElementById('checkboxId').checked = e.transliterationEnabled;
}
//
Handler for checkbox's click event.
Calls toggleTransliteration to toggle
// the
transliteration state.
function
checkboxClickHandler() {
transliterationControl.toggleTransliteration();
}
//
Handler for dropdown option change event.
Calls setLanguagePair to
// set
the new language.
function
languageChangeHandler() {
var
dropdown = document.getElementById('languageDropDown');
transliterationControl.setLanguagePair(
google.elements.transliteration.LanguageCode.ENGLISH,
dropdown.options[dropdown.selectedIndex].value);
}
//
SERVER_UNREACHABLE event handler which displays the error message.
function
serverUnreachableHandler(e) {
document.getElementById("errorDiv").innerHTML =
"Transliteration
Server unreachable";
}
//
SERVER_UNREACHABLE event handler which clears the error message.
function
serverReachableHandler(e) {
document.getElementById("errorDiv").innerHTML = "";
}
google.setOnLoadCallback(onLoad);
function
CharCountML(str) {
spnCharacterCountML.innerHTML =
str.length;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="pnlMiltiLimgualTextBoxUC" runat="server">
<center>Type in
Indian languages (Press Ctrl+g to toggle between English and Hindi)</center>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div id='translControl'>
<input type="checkbox" id="checkboxId" onclick="javascript:checkboxClickHandler()"></input>
Type in
<select id="languageDropDown" onchange="javascript:languageChangeHandler()"></select>
</div>
</td>
</tr>
<tr>
<td>
<textarea id="transl2" style="width:500px;" rows="3" cols="100" onkeyup="CharCountML(this.value)"></textarea>
<br />
<b>Character
Count : <span
id="spnCharacterCountML"></span></b>
</td>
</tr>
<tr>
<td>
<div id="errorDiv"></div>
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>
No comments:
Post a Comment