recently i was trying to make profilsmart translatable. in other words all program texts on forms, classes, messageboxes, reports etc. must be in the language that the user prefers. i have to admit that this is a very very boring procedure. if you ever have tried something like that you understand what i mean. even i have downloaded steven's intl toolkit i preferred to do the job manually.
at first, program forms have all the captions in greek. i was lucky enough to have used only sublclassed labels. so i created a message_id property in my base label class. after that i created a table langtext (rec_id integer, gr_text , en_text, fr_text ...) in order to keep there every string of the program. my thought was to have a table with the messages and in each control a message_id number that corresponds to the appropriate record. the translation will take place "on the fly" in the setcaption method after label's init event.

moving the label captions from controls into langtext table one by one very soon i realised that this procedure will take months! so i decided to spend a couple of hours to create this routine:

*======================================================================

*| purpose...... sets the correct message_id to all labels of the class/form

*| author....... vaggelakos

*| created...... august 18, 2006

*| about........

*| mod list.....

*======================================================================

local lcclassname, lcprop, lnmsgline, lncaptionline, lncaptionstart, lncountoffiles, lncounter

local array laproplines[1]

lcclassname = "form1.scx"

store 0 to lnmsgline, lncaptionline, lncaptionstart, lncountoffiles

if not used("langtext")

      use langtext in 0

endif

if not used(justfname(lcclassname))

      use (lcclassname) in 0

endif

select (lcclassname)

go top

scan

      if alltrim(baseclass)="label"

            lcprop = properties

            lncaptionstart = at("caption",lcprop)

            store 0 to lnmsgline, lncaptionline

            if lncaptionstart > 0 then

                  *we have a caption

                  lncountoflines = getwordcount(properties,chr(10))

                  dimension laproplines[lncountoflines]

                  laproplines[1] = getwordnum(properties,1,chr(13))

                  if substr(laproplines[1],1,7) = "caption"

                        lncaptionline = 1

                  endif

                  for lncounter = 2 to lncountoflines

                        laproplines[lncounter] = chr(13) + getwordnum(properties,lncounter,chr(13))

                        if substr(laproplines[lncounter],1,7) = "caption"

                              lncaptionline = lncounter

                        endif

                        if substr(laproplines[lncounter],3,7) = "caption"

                              lncaptionline = lncounter

                        endif

                        if substr(laproplines[lncounter],3,10) = "message_id"

                              lnmsgline = lncounter

                        endif

                  endfor

                  if lncaptionline > 0 then

                        lcstring = substr(laproplines[lncaptionline],at("=",laproplines[lncaptionline])+1)

                        lcstring2find = getwordnum(&lcstring,1,["])

                        select langtext

                        locate for alltrim(gr_text) == alltrim(lcstring2find)

                        if found()

                              lnmessage_id = record_id

                        else

                              append blank

                              replace record_id with recno()

                              replace gr_text with lcstring2find

                              lnmessage_id = record_id

                        endif

                        if lnmsgline > 0 then

                              lcstring = substr(laproplines[lnmsgline],at("=",laproplines[lnmsgline])+1)

                              laproplines[lnmsgline] = substr(laproplines[lnmsgline],1,at("=",laproplines[lnmsgline]))+ " " + alltrim(str(lnmessage_id))

                              ***update properties field

                              lcprop = ""

                              for lncounter = 1 to lncountoflines

                                    lcprop = lcprop +laproplines[lncounter]

                              endfor

                              select (lcclassname)

                              replace properties with lcprop

                        else

                              lcnewline = chr(13)+chr(10) + "message_id = "+ alltrim(str(lnmessage_id))

                              ***update properties field

                              lcprop = ""

                              for lncounter = 1 to lncountoflines - 1

                                    lcprop = lcprop +laproplines[lncounter]

                              endfor

                              lcprop = lcprop + lcnewline

                              lcprop = lcprop + laproplines[lncountoflines]

                              select (lcclassname)

                              replace properties with lcprop

                        endif

                  endif

            endif

      endif

      select (lcclassname)

endscan

wait window "done!"

close databases


that's it! what i wanted all the texts from every control are transferred into langtext table in seconds! keep in mind that the routine checks if the text string is already in the table and updates the message_id property correctly.

after that it was a matter of minutes to create a wrapper method that finds all the forms (and all the classes) of the project and calls this routine for every form or class.

all of my visual controls are now translatable!
thanks to the nature of the visual foxpro source files this routine saved me months of work!

important: since this procedure dives into your form/class file keep a backup copy before you run it!

vfp can do anything you can imagine!

ta leme 

Leave a Reply

Your email address will not be published. Required fields are marked *