Localization for Database Column Names

I want to use the column names from a database table to be displayed as a header of a ListBox. This works fine with the following statement:

MyListBox.HeaderAt(i) = rs.ColumnAt(i).Name

How can I translate the column name based on the localization constants? (e.g. database column name = “kCountry”, localized strings for kCountry are: in French : Pays, in Dutch : Stad…)

you could add the key word names in a database table too.

order, EN, Order
order, DE, Bestellung

if the user login you could add his languge to a dictionary and call the lookup method.

=Dictionary.Lookup(key, defaultValue)

MyListBox.HeaderAt(i)=TranslateDictionary.Lookup(rs.ColumnAt(i).Name, rs.ColumnAt(i).Name)

https://documentation.xojo.com/api/language/dictionary.html

https://documentation.xojo.com/topics/localizing_your_apps/index.html

Indeed, this can solve the problem. But is there any way to use the localization strings already defined in the app?
Scherm­afbeelding 2024-10-11 om 17.34.40

Maybe change that to:

If rs.ColumnAt(i).Name = "kCountry" Then
  MyListBox.HeaderAt(i) = kCountry
End If

or use Select Case.

As rs.ColumnAt(i).Name is a String and you need to assign the constant.

Note: not tested, just an idea.

Another idea:
I use a TABLE / Record to store the Header. I use only one set (French), but it is very easy to add records / and it is up to you to define the wy to display the correct language from there.

@AlbertoD Thank you, this solves the problem based on the localization constants available in the app.
@MarkusR @Emile_Schwarz For large applications it may be more interesting to create a separate table and read this table into a dictionary when the application is started. Thank you for the ideas.

2 Likes