NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: sylvain on September 24, 2010, 05:57:13 AM

Title: Translation
Post by: sylvain on September 24, 2010, 05:57:13 AM
Hi,
I would like to translate prompts, comments, headers, buttons,... depending of the language of my user (store in a session variable). I see that there is a translate mathode in the web handler but can someone just explain to me shortly what is the process to do that ?

Thanks

Sylvain

Title: Re: Translation
Post by: Bruce on September 25, 2010, 03:57:01 AM
Hi Sylvain,

1.) A string comes into the method.
2.) you can access the session queue at that point using self.GetSessionValue.
3) you return the translated string (using whatever translation tool you like.)

for example
  case self.GSV('language')
  of English
    ! translate call goes here
  End

Cheers
Bruce

Title: Re: Translation
Post by: sylvain on September 25, 2010, 04:55:33 AM
Hi Bruce,

Thanks

Sylvain
Title: Re: Translation
Post by: Alberto on September 26, 2010, 03:24:32 AM
Inside Translate embed:


    Returnvalue = p_string
    !Trace('Translate From: '&p_string)

    if p_string<>'' and left(p_string,8)<>'uploads\' and p_string<>'??:??' and p_web.gsv('notranslate')<>1 and p_web.translateoff = 0

       if right(clip(p_string),1)=':'
          p_string=left(p_string,len(clip(p_string))-1)
          dp#=true
       else
          dp#=false
       end

       !Access:Translate.open()
       !Access:Translate.UseFile()
       TRA:TranslateFrom = p_string
       get(Translate,TRA:XFROM)
       if error()
          !Trace('Dont found: '&p_string)
          if loc:Add=1 !getini('translation','add',1,'.\TRANSLAT.INI')=1
             !Trace('Adding: '&p_string)
             clear(tra:record)
             TRA:TranslateFrom = p_string
             !Trace('Adding Translate From: '&TRA:TranslateFrom)
             TRA:ProcedureName = GlobalErrors.GetProcedureName()
             !Trace('Adding ProcedureNAme: '&TRA:ProcedureName)
             if Access:Translate.TryInsert()
                Trace(error())
             end
             !Trace('Added: '&p_string)
          end
          ReturnValue = ''
       else
          !Trace('Found: '&p_string)
          if loc:Repair=1 !getini('translation','repair',0,'.\TRANSLAT.INI')=1
             TRA:TranslateFrom = p_string
             TRA:ProcedureName = GlobalErrors.GetProcedureName()
             PUT(Translate)
          END
          ReturnValue = choose(p_web.gsv('LOGIN_lngCol')+1, TRA:TranslateTo_00, TRA:TranslateTo_01, TRA:TranslateTo_02, TRA:TranslateTo_03, TRA:TranslateTo_04, TRA:TranslateTo_05, TRA:TranslateTo_06, TRA:TranslateTo_07, TRA:TranslateTo_08, TRA:TranslateTo_09, TRA:TranslateTo_10, TRA:TranslateTo_11, TRA:TranslateTo_12, TRA:TranslateTo_13, TRA:TranslateTo_14, TRA:TranslateTo_15, TRA:TranslateTo_16, TRA:TranslateTo_17, TRA:TranslateTo_18, TRA:TranslateTo_19, TRA:TranslateTo_20)
          !Trace('Translate To: '&getini('languages',p_web.GetSessionValue('LOGIN_lng'),0,'.\TRANSLAT.INI')+1&' '&ReturnValue)
       end
       !Access:Translate.Close()

       if ReturnValue = ''
          ReturnValue = p_string
       end
       if dp#=true
          ReturnValue = clip(Returnvalue)&':'
       end

    end

    ReturnValue = parent.Translate(ReturnValue,p_AllowHtml)
    Return clip(ReturnValue)

Hope this helps
Title: Re: Translation
Post by: Rene Simons on September 27, 2010, 10:00:41 PM
Hi Bernardo,

Nice piece of code.
A questions though:
Why did you comment the access:Translate.xxx commands out.
Is this because the translation file is allways open?

Rene
.
Title: Re: Translation
Post by: Alberto on September 28, 2010, 02:01:06 AM
Yes, at the ProccessLink embed, before the parent call I open all files I need for the thread...

!Open files I need for all the tread
   Access:Translate.Open()
   Access:Translate.UseFile()
   Access:Sql.Open()
   Access:Sql.UseFile()
   Access:Languages.Open()
   Access:Languages.UseFile()

Then I dont need to open the file for each call to the Translate method.

Regards
Alberto