-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (28 loc) · 1.01 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$(document).ready(function () {
$('#englishInput').on('keypress', function (e) {
const key = e.keyCode || e.which;
if (key === 13) {
$('#englishInput').val($('#hindiOutput').text());
$('#hindiOutput').text('');
$('.select-option').hide();
} else {
$('.select-option').show();
}
const englishText = $('#englishInput').val();
$.ajax({
url: `https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=hi&dt=t&q=${encodeURI(englishText)}`,
success: function (result) {
if (result[0] !== undefined && result[0] !== null) {
const hindiText = result[0][0][0];
$('#hindiOutput').text(hindiText);
} else {
$('#hindiOutput').text('');
}
}
});
});
$(document).on('click', '.select-option', function () {
$('#englishInput').val($('#hindiOutput').text());
$('#hindiOutput').text('');
});
});