• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Bilingual support in Java

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We are supporting a bilingual application(English and Arabic). User can change some setting in a system tray so that he can enter data from keyboard in either of the language.
I want to restrict/validate user from entering English characters in Arabic field or vice versa.
Is there a way I can know what characters are getting inputed from keyboard? Are they English or Arabic? So that I can validate the input.

Kindly provide some suggestions.

Cheers
Ashwin
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
English text would for the most part use ASCII or ISO-8859-1, so the characters entered would have values between 0 and 255. I'm not familair with how you enter Arabic text, but in a Java string it would have higher values (because of the Unicode encoding) - that's how you can tell them apart.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is there a way I can know what characters are getting inputed from keyboard? Are they English or Arabic?


You are going to struggle to find a fool proof way of doing this. For example is this text English or Arabic: "78978789789" ? My point is you can guess based on the Unicode value of the String, but this will fail when encounter characters shared between English and Arabic.

I'm not sure why you need to stop English being entered when the application expects Arabic and viceversa. Can you explain why this is a problem?
 
Ash Kondhalkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf and Paul,

Thank you for your replies. Our customer's requirement is,user should only enter arabic in Arabic textfield and vice versa. So we need to do this.

Actually after going through JDK, I have found out the way! JDK provides a class "Character.UnicodeBlock", which provides constants for different langauges e.g ARABIC, BASIC_LATIN etc and also a method as "of". This method returns the unicode block of a character passed to it. So using this constant and a method I am in position to restrict user from entering non arabic characters in Arabi textfield!

Regards
Ashwin
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic