Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In my project I have a collection with the texts to translate the controls.

This collection is filled when the program starts, with a number that identifies the text, and a default text.

 

To be easier for me, I need to do is in each form:

- define all control.tag (label, checkbox, or something similar) with a numeric value

- define all control.text with the default text

 

Create a sub called Translate (or something else) with something like this:

 

Dim a as integer, b as string

 

For each x in me.Controls

a = cint(x.tag)

b = cstr(x.text)

if (a > 0) then

a.text = trans(a, b)

end if

Next

 

where trans is the function that will return the translated text.

 

I tried to do this, exactly, and i saw that me.controls was not catching all the control, in the form. No label, no checkboxes, nothing!!

 

Does anyone has a suggestion, please???

  • Moderators
Posted

If a control is in another container such as a Panel you need to iterate Panel.controls.

 

As a side note: why aren't you using a resource file for all your language strings, this is done with a couple of lines of code and requires little effort. There is no need to loop controls or use IF conditions to see which language is being used. It is really simple and would apply the selected language to the entire application and is scalable.

Visit...Bassic Software
Posted
If a control is in another container such as a Panel you need to iterate Panel.controls.
How can I do this??

 

 

 

As a side note: why aren't you using a resource file for all your language strings, this is done with a couple of lines of code and requires little effort. There is no need to loop controls or use IF conditions to see which language is being used. It is really simple and would apply the selected language to the entire application and is scalable.
I can't do this, because the database structure is already defined, and already has a table wich contains all messages in all languages.

If I could change this, maybe it would be easier, but this is a small part o a huge project, and I must continue with what was already decided. Thanks anyway, for the suggestion. I'll consider in the future.

 

Thanks!!

  • Leaders
Posted

exactly. try something like this:

 

Sub ApplyLocalization(Collection As ControlCollection)
   For Each Item As Control In Collection
       'Localization Code
       If Item.Controls.Count > 0 Then ApplyLocalization(Item.Controls)
   Next
End Sub

 

A recursive sub like this will automatically take care of all the controls contained within other controls. To start the whole thing up, you would just use the line ApplyLocalization(Me.Controls).

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...