|
Multi-lingual Support in C |
|
|
|
Computer is now in use in almost all parts of the world so much work is in progress to give support to languages other than English. Many major languages of the world like Arabic, Hindi and Chinese are not written in Roman Script, so special features are provided for dealing with these languages. This article will tell how to implement multilingual application using C#. Our Example Script will be Arabic. But it can be generalized to any major language of the world.
C# stores character in the form of Unicode Characters. Unicode is a 16 bit encoding scheme of characters and has characters of all major languages of the world like Arabic, Urdu, Hindi, Chinese, Korean, Hebrew etc. Every character has a unicode code point, e.g. Arabic Character Aleph has codepoint 1575. To display different languages and script, one has to install support for the script. Windows 2000 has support for displaying many scripts.
Script is the writing style of language .For example, English and many western languages are written in Roman Script. Arabic, Farsi, Urdu are written in Arabic Script. Hindi, Bengali, Tamil are written in Indic Script. Every script has its own features. Arabic Script is written from right to left and characters changes their shape according to the context.
To install support for Arabic or any other Script. Open Control Panel --> Regional Options --> Language Setting for the System and check your desired Script(Arabic in our case). After checking Arabic click on OK and Arabic Script support is installed on our computer and you can have input locale in Arabic, Farsi and Urdu.
For input, keyboard for Arabic, Farsi and Other languages can be installed from Control Panel ---> Keyboard --> Input Locale --> Add.
So it is the configuration for displaying multilingual text. Now we will start C# IDE and explore its features. Throughout the article we will only concentrate on the code written for multilingual features.
The code for form creation, adding controls to form and event handling will be generated by the IDE and will not be discussed.
FIRST EXAMPLE OF MESSAGE BOX
Create a Windows Application. Place a button in the centre of form. Set the name and text properties of the button to btnMessage( ) and "Show Message" respectively. For displaying Message Box, add following code to the Click event of btnMessage( ). protected void btnMessage_Click (object sender, System.EventArgs e) {
MessageBox.Show("English Text Example","English Title");
} On Pressing F5, Form will be displayed and on clicking Show Message. Message Box will be displayed.
Now for displaying Arabic text, type message and title using Arabic characters. The Message is " Urdu Text Example" and "Urdu Title" in Urdu Language.
The message box displayed by clicking Show Message Button will be
The Message box
displays Urdu Text(in Arabic Script). But it has some problems. Arabic
Script is written from Right to Left(The rightmost character is first
character of string, and leftmost is the last character of string). So
the text must be right aligned. In the above example both Title and
Message are left aligned. Also the Title must be at right and the Close
Button should be at left in a RightToLeft Scheme. This can be done by
using style attributes as third parameter of MessageBox.Show method.
Style Attributes are used to change the visual style and options of
Message Box. For Example, for displaying a Cancel button with OK button,
MessageBox.Show ( "Message", "Title", MessageBox.OKCancel ) ; For RightToLeft
MessageBox,
In above examples, we use Windows 2000 support to insert Arabic (Urdu) characters to the code. But if the development environment does not have support for writing multilingual characters, then this work can be done by code. The character datatype of C# stores characters as Unicode character. So we can declare variables of character and string type and assign characters and words of different languages to these variables. In the next example, we will display word "Urdu" in Arabic Script in a textbox without using Arabic Keyboard of Windows 2000.
protected void button1_Click (object sender, System.EventArgs e) {
char aleph ; char ra; char dal; char wao; string word; aleph = '\u0627'; ra = '\u0631'; dal = '\u062F'; wao = '\u0648'; word = aleph.ToString() + ra.ToString()+dal.ToString()+ wao.ToString(); textBox1.Text = word;
}
During execution of the application, when we click on the button, word "urdu" in Arabic Script will be displayed in the textbox.
The word "urdu"
in Arabic script consists of four characters:
The only problem with
above code is that it is aligned to the right. All controls have a
property
The Combo Box displays
three words in Arabic Script but it does not have all Right to Left
Features. In a Right To Left Control, all the words must be right
aligned. Also the Dropdown Arrow must be at left of the control.
Similarly if a control has vertical scrollbar then it must be at left of
the control. This can be done by setting
If |