Introspection and Dynamic String Constants

Is it possible to get information about Dynamic String Constants with Introspection? Thanks.

Don’t think so
http://documentation.xojo.com/index.php/Introspection

What is it you’d want to know ?

I intended to use Introspection to search a Dynamic String Constant which name matches with a database field value, and use it to make easiest the localization of my web apps. Now I resolve it with Selects, but in some cases is tedious.

Am I correct that the database holds the name of a constant that you then need to find & get the localized version of ?

Yes Norman, It’s correct.

Yeah that’s not going to work out very well since you cannot look up the constants by name

Instead maybe try (I think this will do what you are trying to do)

  1. create a singleton instance of a class in your app called Localizer - it HAS to be an instance that exists to use introspection - and you really only need this one

  2. Localizer has METHODS and these are the names you save in the DB - not the names of constants - so you can look the methods up at run time using introspection

  3. those methods take a language code ( from Session.LanguageCode ) and simply grab the specific language version of the dynamic constant using the syntax I mentioned in a post I cannot locate now

Bascially any time you want to get a specific version of a dynamic constant you can write

value = <constant name>( language code )

so with 1,2, and 3 you can write a method that gets you the dynamic constant that you CAN look up using introspection

@Carlos Arzuaga - Could you tell me what you are trying to accomplish? I’m curious what is missing from the built-in system?

Norman: Thanks, I’m going to explore that solution.

Greg: I wish do something like this in WE:


Sub FillLocalizedWebPopUpMenu(records As RecordSet, byRef MyPopUpMenu As WebPopupMenu)

'Fills a PopupMenu with the localized value of Dynamic String Constants 
'which names matches with a database field value

'recordset example:
'
'     id           name           xojo_k_localization
' __________________________________________________
'      1           Spain          kSpain
'      2           France         kFrance
'      3           USA            kUsa
'      4           Germany        kGermany
'      5           Canada         kCanada
'      6           Brazil         kBrazil
' ........................

'Dynamic String Constant example:
'
'Const kSpain As String ="Spain" (dynamic)
'
'   Platform       Language       Value
'_______________________________________
'   Any            Spanish        Espaa
'   Any            English        Spain
'   Any            French         Espagne
'   Any            German         Spanien

For i As Integer=0 To records.RecordCount-1

     'myLocalizer is the class instance that contains the Dynamic String Contants
     'DynamicConstantInfo and GetDynamicConstants are invented methods that don't exist in Xojo Framework

     Dim myDynamicContants() As Introspection.DynamicConstantInfo=Introspection.GetType(myLocalizer).GetDynamicConstants
          
     For Each c As Introspection.DynamicConstantInfo In myDynamicContants
          If c.Name=records.IdxField('xojo_k_localization").Value Then
               MyPopUpMenu.AddRow(c.Value)
               Exit For
          End If
     Next
          
     records.MoveNext
Next
     
records.Close

End Sub

The way we do this is to create a dynamic constant with a base value of:

English / Spanish / German / Italian

And then insert the translated versions (i’m using google translate for this example, but you get the idea):

Spanish: Ingls / Espaol / Alemn / Italiano German: Englisch / Spanisch / Deutsch / Italienisch Italian: Inglese / spagnolo / tedesco / italiano

then you do something like this:

Dim Languages() as String = Split(kLanguageNames,"/") for i as integer = 0 to UBound(Languages) MyPopupMenu.AddRow Trim(Languages(i)) Next i