Convert solution to multi language
What's the best practice for converting very large windows solution to multi-language .
There are hundreds of windows a lots of l开发者_如何学JAVAabels, combo etc.
We are using devxpress components (not layout) .
Localization is always a huge amount of work, especially if you need to localize already created application.
As for static labels of forms, there is an elegant solution which allows you to make 75% of work easily and quickly. Just move labels to resources, not touching your existing English labels. Then, depending on your current thread's Culture, change labels on the form reading them from localized resources.
For instance, french resource for YourForm class:
YourForm.fr-CA.resx:
"name" -> "value"
labelCaption\ --> "Légende"
labelInputLabel\ --> "Champ de saisie"
"Name" is the name of your control object of the form, "value" is a label of the control.
1). Make a base class for all your forms, for instance LocalizationBaseForm 2). Handle OnLoad() event in this class and read the resource. Depends on currently selected culture you will read corresponding localized resource. Canadian French will be located in /fr-Ca/ directory, Spanish in /es-Es/ etc.
ResourceManager manager = new ResourceManager(your_ form_type);
ResourceSet set = manager.GetResourceSet(manager, ...);
3). Iterate through the list of labels and change labels on the form according the list on the resource.
//*pseudocode:*
foreach (DictionaryEntry entry in set)
{
SetControlLabel(entry.Key, entry.Value)
}
SetControlLabel(...) method looks a control with the given name and change it caption with the given new cation.
You can make more complicated things, like localizing columns in grids, making values in resource more complex, for instance:
"name" -> "value" gridTable(ColumnKey1)\ --> "Сolonne Une" gridTable(ColumnKey2)\ --> "Сolonne Deux"
The same thing with trees, toolbars etc. You can even generate resource automatically, it's all up to you.
That approach won't resolve all your problems, but it will help you if you need to localize your already existing application quickly. You still need to localize string parsers, dates etc.
Good luck!
if u want to use DB for localize then a can give advise:
Create 4 tables 1.ProjectKeyWords(KW_ID, LNGID, Value); 2.Pages (PageID, PageName); 3.Labels (LabelID, LabelName, KW_ID); 4.Application_Labels(PageID, LabelID); 5.Langs (ID, NAME);
sample: ProjectKeyWords 1, 1, FirstName (In English) 2, 1, LastName (In English) 1, 2, Имя(In Russian) 2, 2, Фамилия(In Russian) 1, 1, Adı(In Azerbaijan) 2, 1, Soyadı(In Azerbaijan) Pages --> 1, Form1 2, Form2
Labels --> 1, lblFirstName ,1 1, lblLastName ,2
Application_Labels --> 1,1 1,2 2,1 2,2
Langs --> 1, Eng 2, Rus 3, Az
And in Form_Load() event u can Create SQLQuery as "
SELECT L.LabelName, PKW.Value
FROM Labels L, Pages P, Application_Labels A_L, ProjectKeyWords PKW
WHERE P.NAME=
AND PKW.LNG_ID=
AND A_L.PageID=P.ID
AND A_L.LabelID=L.LabelID
"
create iteration and find All controls with L.LabelName with FindControl method and set PKW.Value to this label Text Property
Try using ResourceManager class
ondotnet.com tutorial
精彩评论