0

I'm building an Urdu language website which, let's say, is similar to a blogging website. I want to enforce users to make posts in no language other than Urdu.

One solution I have in my mind is to manually capture each key pressed in Javascript and display its alternate in Urdu in the textbox. Something like this:

'A'-> 'ا' , 'B' -> 'ب'

I dont find it an efficient solution at all and would like to know if there is some sort of plug-in that I could use that sets the input language of a textbox? Or even if I must write a code of my own, do you have a solution other than one above?

4 Answers4

1

I found what I was looking for. For other people who might work on Urdu language in future, following are great Urdu editors available online.

https://www.branah.com/urduphonetic

http://www.lipikaar.com/online-editor/urdu-typing

They seem to be easily integrate-able with my website. Great stuff, really. Saved me from reinventing the wheel.

0

No, it cannot be done using HTML, CSS or JavaScript... Use google input tools to do it http://www.google.co.in/inputtools/

molecule
  • 1,027
  • 1
  • 14
  • 27
  • I'm aware of google input tools. I installed them yesterday but how do I integrate it with my website? –  Sep 30 '15 at 14:31
0

Check out this link:

https://css-tricks.com/snippets/javascript/javascript-keycodes/

Basically, you need to capture they keycode value on each keypress.

This link describes further how to intercept and change an entered value:

Changing the keypress

Community
  • 1
  • 1
khalid13
  • 2,767
  • 2
  • 30
  • 48
  • That's already a solution that I have in my mind. But I was hoping there was a better way to do it. –  Sep 30 '15 at 14:33
0

to me it is possible using regex : with the help of the wikipedia page of the urdu alphabet you can get the unicode range of Urdu language which are : [\u0600-\u06FF] , [\u0750-\u077F] , [\uFB50-\uFDFF] , [\uFE70-\uFEFF]

You can try something like that : bind a jquery event when a key is pressed, get the key string, test if it is Urdu, add the char if it is, do nothing if it isn't:

$('#yourTextArea').bind('keydown',function(evt){
    evt.stopPropagation(); // stop propagating the key pressed
    var TextAreaVal = $('#yourTextArea').val()
    var urduRegex = /[\u0600-\u06FF]|[\u0750-\u077F]|[\uFB50-\uFDFF]|[\uFE70-\uFEFF]/;
    CharToTest = String.fromCharCode(evt.keyCode); // get the char related to the key pressed
    if(urduRegex.test(CharToTest)) // if urdu
    {$('#yourTextArea').val(TextAreaVal + ChartoTest )} // add char to the textarea
    else
    {return;} // do nothing
}

[NOT TESTED] though I am sure you can work something around that...

romainm
  • 281
  • 8
  • 16
  • And I'll appreciate if others didn't delete their answers. I'd like to keep my options open. –  Sep 30 '15 at 14:55
  • 1
    @TahreemIqbal The problem with this solution is that if you move your cursor to the middle of a sentence and attempt to insert something, it will still be appended to the end of the sentence. Additionally, it only stops a user from using non-Urdu characters. It doesn't actually convert roman characters to Urdu characters, so you would have to require your users to have an Urdu keyboard program installed. – khalid13 Sep 30 '15 at 16:21
  • @khalid13, if it is the problem, you can add an onchange event to the text zone to check if the new value are allowed. + the initial statement is _I want to enforce users to make posts in no language other than Urdu_ . – romainm Sep 30 '15 at 16:37
  • @khalid13 that's a valid argument. And not only that, there's also a problem of capturing multiple keydowns for a character. Like if small 'a' represents 'ا' and capital A represents 'آ' then I'll also have to capture shift+a keys and this will only go more complicated from there. –  Sep 30 '15 at 16:53
  • I could provide the setup for the software that enables Urdu language on the website and tell users to first install it before making posts. But that's not user friendly. I can't believe there is no plug in that solves this problem. –  Sep 30 '15 at 16:55
  • yes you are right, so you should then go for the `onchange` event that target the text area, then get the whole value and check if it validate the regex, if not put back the old value the text area – romainm Sep 30 '15 at 16:56