|
|
|
APPLICATION LOCALIZATION |
|
Introduction
When writing an application for multiple locales you could write completely different sets
of source code for each locale. That wouldn't be a very efficient approach however, with
much overlap between each application. More sensibly you would write one set of source
code and build into the solution the ability to customize the application for different
locales.
The purpose of this document is to provide help to a developer on how to build an
application that is ‘Localization Enabled’.
Definitions & Acronyms
| HTML |
Hypertext Mark-up Language |
| IE |
Internet Explorer |
| LAD |
Localized Application Development |
| NN |
Netscape Navigator |
| OS |
Operating System |
| SQL |
Structured Query Language |
| WEFT |
Web Embedding Font Tool |
| XML |
Extended Mark-up Language |
Objective
Globalizing an application means that the user interface and functionality in application
makes sense to users all over the world.
Localization is the process of customizing your application for a given culture or locale.
Scope
This document provides information about how to make Desktop applications and Web
applications ‘Localization Enabled’ with databases like Oracle, SQL Server and Access.
For building the architecture for an application to be localized there are several
alternatives.
Use the so called "built-in" features of the .NET framework.
Create an XML-based solution (as discussed below).
Guidelines
Front End
This section will describe how to go about the front end programming for localized
applications.
The following types of application will be discussed.
i> Desktop Applications
ii> Web Applications
There are certain areas that are common to both of the above. The following section
covers that.
Basic Environment Requirement (Hardware and Software)
Development:-
OS: Win XP, Win 2000, Win 2003
Deployment:-
O.S.: Win XP, Win 2000, Win 2003
Specific Environment Requirements
o The OS should have fonts installed for the requisite locale scripts.
o Keyboard settings need to be enables for respective locale scripts for data
entry purpose.
Further information on the above points can be found at the following sites:
http://www.bhashaindia.com
http://www.bhashaindia.com/Developers/indianlang/indicscript/oslevel.aspx
Desktop Applications
5.1.3.1. Points to Remember
5.1.3.1.1. Storing Data for Control Captions (Label, Button)
Description:
All captions for controls in the application should appear in localized
languages. For this purpose we need to create different XML files for different
languages, which will contain captions of different controls of that application in
different languages. It is recommended that custom controls be built which
before displaying the caption senses the current locale in scope and retrieves
the caption from the appropriate XML file for the language. Example1
5.1.3.1.2. Storing Data for Dynamic Messages
Description:
Any message in an application should appear in localized language. For this
purpose we need to create different XML files for different languages, which
will contain all the messages of the application in different languages.
Application will pick up the appropriate XML file for that language and show the
message in that language.
Development Guidelines for Localized Applications Controlled Copy
Page 6 of 14
5.1.3.1.3. Handling Font Size for Various Control Captions
Description:
Since the width and height of letters and the number of characters of a
particular word in different languages are different, the resultant width and
height of controls may differ while displaying text for different languages if it is
not handled explicitly. To prevent this, custom controls should be made which
programmatically adjusts the size of the font so that the text (retrieved from the
XML file) fits into the control when displayed. Example2
5.1.3.1.4. Consideration for Currency and Date
Description:
Since the currency and date formats are different in different locales / cultures,
it should be considered at the time of building a localized application. For this
purpose an XML file should be created which will contain the appropriate Date
and Currency formats. At the time of form loading if there is any control that
shows Currency and Date type values, they should use the respective display
formats available in the language specific XML file.
5.1.3.1.5. Handling Language Change Scenarios
Description:
As the user can change the language setting of the application at any position
when the application is running, we have to change the captions of the controls
of the forms already opened. For this purpose, our recommendation is to use
the concept of Factory Pattern, which will help us to keep track of the forms
that are in the open state. When the user changes the language settings,
application can easily reload the controls captions of the open forms.
5.1.4. Web Applications
5.1.4.1. Points to be Remember
5.1.4.1.1. Handling Control Captions (Label and Button)
Description:
All captions in an application should appear in localized languages. For this
purpose we need to create different XML files for different languages, which
will contain all the caption of different controls of that application in different
languages. It is recommended that custom controls be built which before
displaying the caption senses the current locale in scope and retrieves the
caption from the appropriate XML file for the language. Example4
Development Guidelines for Localized Applications Controlled Copy
Page 7 of 14
5.1.4.1.2. Handling Dynamic Messages (Client Side)
Description:
Any dynamic message in a web application should appear in localized
language. For this purpose we need to create different XML files for the
supporting locales, which will contain all the messages in the application in
different locales. This should be handled with JavaScript at the client end. Each
web page while opening should load an xml file containing messages for the
language in scope from the server. Alert messages can be shown from this xml
file when needed. This can be implemented using XMLDOM.
5.1.4.1.3. Handling Font Size for Various Control Captions
Description:
Since the width and height of letters and the number of characters of a
particular word in different languages are different, the width and height of
controls in different language settings may be different. This may affect the
layout of the page. To prevent this, customized controls should be made which
at the time of rendering adjusts the size of the font depending on the size of the
string to be displayed.
Note: For this purpose, developer must have to mention the width and height of
the control in .HTML file. Example5
5.1.4.1.4. Embedded Font Types
Description:
Since the font that is required to achieve localization may not be installed in a
client machine, the required font has to be embedded within that web page.
This is achieved by using a tool called WEFT (Web Embedding Font Tool) from
Microsoft Corp which generates an EOT file for the font to be embedded and is
included in the page. Such EOT files are only supported by Internet Explorer,
not by Netscape Navigator. For Netscape, there is another tool called
“TrueDoc” which generates a PFR file for the embedded font and is included
within the page. PFR files are supported by both Internet Explorer and
Netscape Navigator.
5.1.4.1.5. Consideration for Currency and Date
Description:
Since the currency and date formats are different in different locales / cultures,
it should be considered at the time of making an application localized. For that
purpose an XML file should be create which will contain the appropriate Date
and Currency formats for different locales. At the time of page loading if there
is any control, that shows Currency and Date type values, they should use the
respective format for display available in the language specific XML file.
Development Guidelines for Localized Applications Controlled Copy
Page 8 of 14
5.1.5. Suggestions
For making localization technology-independent we suggest using XML files
based approach (as discussed above) rather than using .NET-specific .RESX
files. With .RESX-based approach a compilation is must for every change in
captions, which is not a desired approach.
Apart from XML files, databases can also be used for the purpose of storing
captions for different locales.
Development Guidelines for Localized Applications Controlled Copy
Page 9 of 14
5.2. Database
5.2.1. Access Database
5.2.1.1. Storing Data in Database
Description:
One can store data for localization to Access database in usual manner. No
special considerations are needed.
5.2.1.2. Fetching Data from Database
Description:
One can fetch data from Access database in usual manner. No special
considerations are needed.
Example3
5.2.1.3. Database Design Considerations
Description:
Since Access database has full Unicode support, there is no need to do
anything different for saving data of different languages in this database.
5.2.2. SQL Server 2000
5.2.2.1. Storing Data in Database
Description:
To insert / update values in multilingual enabled columns, the value needs to
be prefixed by ‘N’, e.g., INSERT INTO <TABLE> (COL1, COL2) VALUES
(<COL1_VALUE>, N<COL2_VALUE>), assuming that column “COL2” will
have multilingual texts.
5.2.2.2. Fetching Data from Database
Description:
One can fetch data from SQL Server 2000 database in usual manner. No
special considerations are needed.
5.2.2.3. Database Design Considerations
Description:
To make a column accept multilingual text the column is to be of Unicode data
type i.e. NCHAR or NVARCHAR.
Development Guidelines for Localized Applications Controlled Copy
Page 10 of 14
5.2.3. Oracle 9i
5.2.3.1. Storing Data in Database
Description:
One can store data for localization to Oracle 9i database in usual manner. No
special considerations are needed.
5.2.3.1. Fetching Data from Database
Description:
One can fetch data from Oracle 9i database in usual manner. No special
considerations are needed.
5.2.3.3. Database Design Considerations
Description:
There are generally two ways of making Oracle 9i accept multilingual text data.
They are as follows:
To make a new Unicode database by changing the National Character
Set to UTF-8.
To make a column in a table within an existing database of NCHAR or
NVARCHAR data type.
5.2.4. Suggestions
In case of using Oracle 9i as back end, one has to consider a few things before
deciding which approach needs to be taken to make the application accept
Unicode data.
One should go for full Unicode database when:
• Lots of Unicode data have to be saved in the database.
• A new application with a new database is being developed.
One should go for Unicode supported columns when:
• Very few Unicode data have to be saved in the database (say,
only an individual’s personal information)
• Unicode support is being implemented incrementally.
• An existing database is being used.
Development Guidelines for Localized Applications Controlled Copy
Page 11 of 14
6. Summary
To be able to handle language change scenario:
1 Put all Display Controls Text, Date, Currency and all Messages
for different locales in different XML files – one set per language.
2 Build necessary Customized Display Controls.
3 Embed all required Fonts within the application.
4 Make special considerations during database design.
5 Pay special attention while saving / updating data in SQL Server
database.
7. References
Reference for further reading:
http://msdn.microsoft.com/library/default.asp?url=/library/enus/
vbcon/html/vbwlkwalkthroughlocalizingwindowsforms.asp
Development Guidelines for Localized Applications Controlled Copy
Page 12 of 14
Appendix: Sample Codes
1. Examples
Example1
‘Following piece of code show how captions can be assigned dynamically
from an xml file
Dim xml As New XmlDocument
Dim btnName As New Hashtable
xml.Load(“XML file name”)
For Each n As XmlNode In xml.SelectSingleNode(“Root Tag name”)
If n.NodeType <> XmlNodeType.Comment Then
btnName(n.Attributes(“Attribute name”).Value) = n.InnerText
End If
Next
....
....
....
“Control Name”.Text = btnName(“Attribute Value”)
Example2
‘Following piece of code is for controlling font size so that the text
fits into the control.
Private Sub checkFontSize(ByVal myGraphics As Graphics)
Dim s As SizeF
Dim intFontSize As Integer
s = myGraphics.MeasureString(Me.Text, Me.Font)
intFontSize = Me.Font.Size
If s.Height > Me.Height - 6 Or s.Width > Me.Width - 6 Then
Me.Font = New System.Drawing.Font(Me.Font.Name,
intFontSize - 1, Me.Font.Style, GraphicsUnit.Point, CType(0,
Byte))
s = myGraphics.MeasureString(Me.Text, Me.Font)
checkFontSize(myGraphics)
End If
End Sub
Development Guidelines for Localized Applications Controlled Copy
Page 13 of 14
Example3
Private sub Show_Data()
Dim strUnicodeName As String
Dim strSql As String = "select name from bank where AccountNo=812"
strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=vbnet1.mdb;"
objCon = New OleDb.OleDbConnection(strConString)
objCon.ConnectionString = strConString
objCon.Open()
objCommand = New OleDb.OleDbCommand
objCommand.Connection = objCon
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSql
Dim drd As OleDb.OleDbDataReader
drd = objCommand.ExecuteReader
drd.Read()
txtDName.Text = drd(0)
End Sub
Example4
<script type="text/javascript">
var xmldom;
xmldom = new ActiveXObject("Microsoft.XMLDOM");
xmldom.async = false;
xmldom.load("SupportedLanguages.xml");
</script>
Development Guidelines for Localized Applications Controlled Copy
Page 14 of 14
Example5
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
MyBase.Text = {Retrieve text from XML file }
checkFontSize(MyBase.Text)
MyBase.Render(writer)
End Sub
Private Sub checkFontSize(ByVal strText As String)
Dim bmpImage As New Bitmap(1, 1)
Dim MyGraphics As Graphics = Graphics.FromImage(bmpImage)
Dim fontSize As SizeF
Dim shrFontSize As Short = 24
Do
If Me.Font.Bold = True Then
fontSize = MyGraphics.MeasureString(strText, New
Font("Verdana", shrFontSize,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point))
Else
fontSize = MyGraphics.MeasureString(strText, New
Font("Verdana", shrFontSize,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point))
End If
If fontSize.Width > Me.Width.Value or
FontSize.Height>me.Height.Value Then
shrFontSize -= 1
Me.Font.Size = FontUnit.Point(shrFontSize)
Else
Exit Do
End If
Loop
End Sub |
|
|