Here is a list of some things that you should consider for Internationalization of Applications.
1. CurrentUICulture and CurrentCulture.
Is is better if you don’t change CurrentUICulture form the the Operating System
2. Windows Forms Layout
Forms must be set Localizable property to true.
This will allow you to define different layouts for your forms depending on the current culture.
3. Strongly Typed Resources.
Instead of something like MessageBox.Show(“Invalid code”) use something like:
MessageBox.Show(resourceManager.GetString(“InvalidCode”)) or even better if you strongly type it:
MessageBox.Show(Form1Resources.InvalidCode);
4. Localize Exceptions messages.
If you include messages in your exceptions that will be shown somehow
on the user interface it is better if your localize those strings also.
If exceptions messages are only for developers then you might not need this.
5.Relate Internationalization sensitive values to the Culture Info
For example
a) Extension methods something like:
CurrentCulture.GetPostalCode();
static class CultureInforExtensions
{
public static string GetPostalCode(this CultureInfo cultureInfo)
{
return new PostalCode(cultureInfo.Name).ToString();
}
}
and then use it like:
maskedTextBox1.Mask = CultureInfo.CurrentCulture.GetPostalCode()
b) Customized CultureInfo it can be helpful for
- Change inappropiate Culture Information
- Supplementary Cultures
- New Combinations of Existing Languages and Regios (for example: Spanish (United States))
6. Right To Left
In some languages Right to Left is important and is an important aspect to consider.
In your forms you have to set the RightToLeftLayout to true and RightToLeft to Yes.
However some controls do not have rtl layoout when RightToLeft=yes: Panel, GroupBos, TabPages and SplitContainerPanels.
You need to rearrange the items in these controls to flow from RightToLeft manually.
This is an example of rearranging the layout of the controls programmatically at runtime, without changing the Form at design-time:
int NumberOfControls = ParentPanel.Controls.Count;
for ( int i=0; i<NumberOfControls;i++)
{
ParentPanel.Controls[i].Left = ParentPanel.Width -
(ParentPanel.Controls[i].Left + ParentPanel.Controls[i].Width);
}
This code iterates into all the controls in the ParentPanel and changes their location to be rtl oriented.
Other problematic controls are: MainMenu, ToolBar, StatusBar MenuStrip, ToolStrip, StatusStrip and ContextMenuString
Other advises:
When you develop multi-lingual application you are bound to change your Forms direction to rtl programmatically at runtime.
There are several techniques to detect the OS language and display your application with the appropriate language and rtl settings, here are some ideas:
The old technique, you would need to detect your UIculture and change the RightToLeft value accordingly.
public static bool CultureInfoIsRightToLeft()
{
string cultureInfoLanguage = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
return
cultureInfoLanguage == "ar" ||
cultureInfoLanguage == "div" ||
cultureInfoLanguage == "fa" ||
cultureInfoLanguage == "syr" ||
cultureInfoLanguage == " ur " ;
}
In Visual Studio 2005, you have a new property TextInfo.IsRightToLeft that indicates the direction of each culture. This is a simple code snippet to detect the culture direction.
private static bool CultureInfoIsRightToLeft()
{
return System.Globalization.CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
}
GDI+
In case you implement your own drawing, you need to specify how your digits would appear in your DrawString. This is achieved using the StringFormat.SetDigitSubstitution. For more info to this method please refer to the documentation . Below is a code snippet that shows how to display digits using the different enums.
private void IndicDigits_Paint( object sender, PaintEventArgs e)
{
StringFormat StrFormat = new StringFormat ();
int AraLCID = new System.Globalization. CultureInfo ( "ar-eg" ).LCID;
StrFormat.SetDigitSubstitution(AraLCID, StringDigitSubstitute .National);
e.Graphics.DrawString( "Digit Substitution National 0,1,2,3,4,5,6,7,8,9" , this .Font, newSolidBrush ( this .ForeColor), new PointF (10, 10), StrFormat);
StrFormat.SetDigitSubstitution(AraLCID, StringDigitSubstitute .Traditional);
e.Graphics.DrawString( "Digit Substitution Traditional 0,1,2,3,4,5,6,7,8,9" , this .Font, newSolidBrush ( this .ForeColor), new PointF (10, 30), StrFormat);
StrFormat.SetDigitSubstitution(AraLCID, StringDigitSubstitute .None);
e.Graphics.DrawString( "Digit Substitution None 0,1,2,3,4,5,6,7,8,9" , this .Font, newSolidBrush ( this .ForeColor), new PointF (10, 50), StrFormat);
StrFormat.SetDigitSubstitution(AraLCID, StringDigitSubstitute .User);
e.Graphics.DrawString( "Digit Substitution User 0,1,2,3,4,5,6,7,8,9" , this .Font, newSolidBrush ( this .ForeColor), new PointF (10, 70), StrFormat);
}