Solved

Localization but  Database method for  WinForm

Posted on 2007-11-21
19
1,051 Views
Last Modified: 2016-07-30
I used this code; http://msdn2.microsoft.com/en-us/library/aa905797.aspx#exaspnet20rpm_t

 I converted that to VB.Net, tweaked it a little bit for my ASP.Net app and it works great.

Is there a database localization method similar to that for windows form? I've been googling and I've mostly found RESX method:  http://www.ondotnet.com/pub/a/dotnet/2003/08/25/globalization_pt1.html

*** I have a localization table like that first link and just need to read the text from that table...

any ideas would be great....
0
Comment
Question by:Camillia
  • 12
  • 6
19 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 20333694
I have an idea to implement on this matter but didn't had the time to implement it...

It should work with one db table and a component that would work as an extender provider.
http://msdn2.microsoft.com/en-us/library/d6c1xa43(vs.80).aspx

DATABASE:
The datamodel for this is very simple, just a table with a code column (unique & varchar) and several columns (string) one for each language supported. name the columns the language code like ''en-EN"


EXTENDER PROVIDER:
If you read the article above you know that Extender Providers add properties and functionality to the controls you have on the form.
You can/have specify which controls you want to interact with.

This Extender Provider will have to add a property to the handled controls that will represent a code (string). This code will identify the row on the db table. Lets name this property "LocalMsgCode".

So, thinking simple, lets focus on label controls.
what the extender must do is pick each control LocalMsgCode property value, get the application localization code and request the string row/column value on the db table that matches the query.
The you just have to set the label text property with the result.

If the db doesn't have a column for the requested localization you should have a property on the extender that specifies the default local.

You can even use this model for all kind of interaction with the user like messageboxes for example... request the string by its code and it will retrieve the message.

The code should be string so you can group messages with prefixes... but you can go a little further and implement a Id -> PId recursive relation within the table to create groups and show them on a tree control.

I really don't have the time know to implement this but isn't hard at all... 1 day should do it all.

Cheers,
Alex
0
 
LVL 7

Author Comment

by:Camillia
ID: 20334306
let me read it. Thanks for responding. That MS article for asp.net works great. Hope I can get this one working for windows. Will post back.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20334500
This is an architecture I designed to be able to implement multi-language on every single string I need to display to the user... being that on controls, messages, exceptions, whatever...

A simple implementations would be simply using the Language property of the form and translate the controls.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20334715
let me read it and wrap my head around it.

Thanks
Kamila
0
 
LVL 7

Author Comment

by:Camillia
ID: 20336547
It sounds similar to the asp.net method. I do have the table with unique ids. ASP.Net uses GetObject like this:
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsLocalization.aspx

>> what the extender must do is pick each control LocalMsgCode property value,...

Yeah, that ASP.Net link has all this coded for ASP.Net.

Let me read the provider link and see where that would get me..
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20336582
Yeah, maybe you can implement a way using the same database.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20339866
ok, i read that article, googled for more examples to get a better understanding and this is a good example:
http://www.emoreau.com/Entries/Articles/2004/10/Extender-providers.aspx

This is what i dont understand: how does the extender help in localization??
So, I have a Form with 2 labels. I have the table with 2 unique rows. I create the extender. Now what? where does going to the database and getting the value for each label fits in all this??
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20340130
The extender does that...
One extender can interact with every single control on your form.

Currently I'm using an extender to apply security just like I've described for localization.
I specify the security code for the action the control executes (if any) and the extender will enable or disable it.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20340508
i'm probably beating this to death. I'll download the code and try it.

>>One extender can interact with every single control on your form.
    but for each label, i need to call the database to get the corect value for that specific label..right? So, the extender is a property for all the labels on a form..i need to bind the value to an extender property for each label?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20340625
Wait... your getting the Extender functionality all wrong...
I believe you need to make a small test with it, a simple one, just to get the hang of it.

"the extender is a property for all the labels on a form"
The Extender isn't a property, the extender is a Component (not a control, it shows on designer like an ImageList on the bottom).
The extender add properties and functionalities to controls and it can interact with them.
From the Extender component you can:
1. "loop" through all the controls you want
2. get the value they have on the Code property (added by the extender), do nothing if no value
3. get the string from the database based on the code
4. Set the control text

Once the Extender is applied to the form it will do this for every control type you specified as supported.


This may seem a bit complex said like this but it isn't.
It's not the easiest thing but once you get the hang of it it's pretty straight forward.

Do some standalone testing.

Cheers!
Alex
0
 
LVL 7

Author Comment

by:Camillia
ID: 20343148
I stepped thru that sample code. I think i know what you're doing. That code basically does what you're describing. I will need to tweak it to go to the database and get the "text" for the label..Your step 3 above

Thanks for sticking for this. I will keep the question open few more days just in case. will post back.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20354512
I played around with that sample code. Then I changed the sample code to C# (i'm trying this in C#). I added a class library, added that code to a class. Named it cExtenderProvider. I added a reference to it in my project.

Now, how can I drag and drop this to the form?? I looked at the Toobar, under Components, i dont see it there. I tried to drag and drop the class..of course it didnt work. I dragged a ToolTip and that worked fine..

how can I do this??
0
 
LVL 7

Author Comment

by:Camillia
ID: 20354628
I closed VS and opened it. Now I see it in the toolbar but it has : There are no usable controls in this group.Drag an iten onto this text to add it to the toolbox.

What to drag??
0
 
LVL 7

Author Comment

by:Camillia
ID: 20354670
dont know what i did but now i see the class name under the Component tab :
cExtenderProvider
   pointer
   ExtenderProvider

But both items are greyed out. I can rename ExtenderProvider but cant drag and drop.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20354761
I think i fixed it. I had created the component using a "class". I deleted it. Added a "component" item.

Now I can see it in the toolbar and it's not greyed out.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20354825
Sorry I didn't replied...
Sometimes VS have some troubles adding the controls to the toolbox.
The best option is having the controls on a separated project, somehow I never had that kind of problems when my controls were on a different project than the on I was going to use them.

No great answer for you on this one, sorry...

Cheers... 2AM... time to bed... :)
0
 
LVL 7

Author Comment

by:Camillia
ID: 20354846
Got it fixed. Thanks for sticking with this. Will keep this thread open for few more days just in case.

Kamila
0
 
LVL 7

Author Closing Comment

by:Camillia
ID: 31411244
Thanks for your help. Works great.
0
 

Expert Comment

by:Cool Current
ID: 41736051
One issue though is that extender provider wont work for datagridview column headers and a few other controls
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now