简体   繁体   中英

How i can get the word who user type for a special word in non-english language in any language even c# , javascript

Assume that a Non-English user types Namaste Duniya. I need to show नमस्ते दुनिया in Hindi Language. if i have नमस्ते दुनिया stored in a variable then how i can get the word that was typed by the user through keyboard and to show them in unicode. Like in this example namaste Duniya was typed for showing them नमस्ते दुनिया.

So my question is can I convert the chars to match the word they (users) typed in the keyboard? How i can do this in c# or any other language like javascript?

This one seems to handle your texts

http://pinyin.info/tools/converter/chars2uninumbers.html

नमस्ते दुनिया became नमस्ते दुनिया नमस्ते दुनिया

The code used is quite simple:

  var iString = "नमस्ते दुनिया", oString ="";
  for (var i=0; i<iString.length; i++) {
    oString += (iString.charCodeAt(i)<=127)? iString.charAt(i) : '&#' + iString.charCodeAt(i) + ';': 
  }

UPDATE:

If I understand the new text of the question, then something like

var translateLatin2Hindi = { 
"Namaste Duniya":"नमस्ते दुनिया",
,
,

"Duniya Namaste":"दुनिया नमस्ते"
}

var translateHindi2Latin = {}
for (var o in translateLatin2Hindi) {
  translateHindi2Latin[translateLatin2Hindi[o]]=o;
}

which then can be used as

function getHindi(latinString) {
  var val = translateLatin2Hindi[latinString];
  return (val)?val:"Not found";
}    
function getLatin(hindiString) {
  var val = translateHindi2Latin[hindiString];
  return (val)?val:"Not found";
}

The original question was

like Hello wolrd in Hindi it's was नमस्ते दुनिया and user type in keyboard for type it is

namaste Duniya

how i can get them namaste Duniya when i have a text नमस्ते दुनिया

so I guess the question is either about transliteration of Hindi, or about mapping output (Unicode) characters to key sequences on the keyboard.

(just a hint for those fluent in Hindi keyboard mappings)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM