Creating Language Switcher

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Creating Language Switcher

Postby Otto » Tue Jul 20, 2021 9:11 am

Hello friends,
This is how I change language in our landing page.
Best regards,
Otto



Image

Image

Image

Image


Reading from DBF-file
Image


Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: Creating Language Switcher

Postby Ruth » Mon Jul 26, 2021 8:26 am

Dear team,

instead of
location.href='https://winhotel.space/lp/demo/landingpage1.prg?sprache=en'
I would need the landingpage1.prg part as a variable, because I would like the switcher to work on landinpage1.prg, landingpage2,prg, landingpage3.prg and so on....

how could this be done?

thank you very much and kind regards
Ruth
User avatar
Ruth
 
Posts: 156
Joined: Fri Dec 07, 2007 1:26 pm

Re: Creating Language Switcher

Postby Otto » Mon Jul 26, 2021 10:25 am

Dear Ruth,
add these lines to the main function

Code: Select all  Expand view
local cEnv := ""
  local cPrgWithPath := ""
  local cProgram := ""

  // https://github.com/FiveTechSoft/mod_har ... od-Harbour
   cEnv := HB_GETENV( 'PRGPATH' )                        //  Obtains a system environmental setting
   cPrgWithPath :=  AP_FileName()                        // returns the filename.prg provided to Apache by the client inclusive path  
   cProgram := '"'+STRTRAN( cPrgWithPath, cEnv + "/" )+'"'  
 

pass cProgram to the HTML section
Code: Select all  Expand view

 TEMPLATE PARAMS hIni, hHash_DBF, cRecords,  cApp, cImgPath, cProgram  
 

and change the displaylanguage function like this.

Code: Select all  Expand view

 function displayLang(cLang) {
      cprg = <?prg return  cProgram  ?>;
   
      if (cLang=='en') {
         
         location.href= cprg + '?sprache=en'
      } else if (cLang=='it') {
         
         location.href= cprg + '?sprache=it'
      } else {
         
         location.href= cprg  
      }

}

 


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: Creating Language Switcher

Postby Ruth » Mon Jul 26, 2021 1:21 pm

...thanks a lot.
this i perfect. Maybe you could explain to me what a "system environmental setting" and the "filename.prg" are?

HB_GETENV( 'PRGPATH' ) // Obtains a system environmental setting
AP_FileName() // returns the filename.prg provided to Apache by the client inclusive path

Kind regards and thanks again :-)
User avatar
Ruth
 
Posts: 156
Joined: Fri Dec 07, 2007 1:26 pm

Re: Creating Language Switcher

Postby Otto » Mon Jul 26, 2021 3:11 pm

Dear Ruth,
Best regards,
Otto

Code: Select all  Expand view


function Main()
  local cEnv := ""
  local cPrgWithPath := ""
  local cProgram := ""

    cEnv := HB_GETENV( 'PRGPATH' )            //  Obtains a system environmental setting
    ? cEnv                    
    cPrgWithPath :=  AP_FileName()            // returns the filename.prg provided to Apache by the client inclusive path
   
    ? cPrgWithPath

    ? "STRTRAN()    search for and replace"  

    cProgram := STRTRAN( cPrgWithPath, cEnv + "/" )      
   
    ? cProgram
 
return nil

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: Creating Language Switcher

Postby Ruth » Mon Jul 26, 2021 3:22 pm

thank you very much .... i got this now. sorry...i was looking for a filename.prg and could not find it...maybe by now you see that i am very new to all of this :-)

another question please:
why do you use cImgFile and cImgPath? And why is there no
Code: Select all  Expand view
if file( cImgfile )
for landingpage2 and landingpage3?

thanks again and kind regards

Code: Select all  Expand view

 if lower(cApp) = "landingpage1.prg"
      cImgfile :=  hb_GetEnv( "PRGPATH" )  + "/img/logo1.svg"  
      cImgfile := STRTRAN( cImgfile,"/","\")

      if file( cImgfile )
         cImgPath := "
./img/logo1.svg"
      endif      

      clandingpageFile := "
landingpage1"

   elseif lower(cApp) = "
landingpage2.prg"
      clandingpageFile := "
landingpage2"

   elseif lower(cApp) = "
landingpage3.prg"
      clandingpageFile := "
landingpage3"
     
   endif      
User avatar
Ruth
 
Posts: 156
Joined: Fri Dec 07, 2007 1:26 pm

Re: Creating Language Switcher

Postby Ruth » Mon Jul 26, 2021 3:46 pm

i post the whole code here...maybe somebody is interested.
Code: Select all  Expand view
REQUEST DBFCDX
REQUEST DBFFPT


static hIni  := {=>}
static hHash_DBF, cRecords

static clandingpageFile := "landingpage1"

function main
  LOCAL cStatus := ""
  LOCAL nRecords
  LOCAL cApp :=  AP_FileName()
  local cExt := ""
  local n := 0
  local cImgPath := "./img/bergland_quadratisch.png"
  local cImgfile := ""
  local cPage := ""
  local cTMPPage := ""
  local cProgram := ""
  // https://github.com/FiveTechSoft/mod_har ... od-Harbour
   cEnv := HB_GETENV( 'PRGPATH' )                        //  Obtains a system environmental setting
   cPrgWithPath :=  AP_FileName()                        // returns the filename.prg provided to Apache by the client inclusive path  
   cProgram := '"'+STRTRAN( cPrgWithPath, cEnv + "/" )+'"'  


  cPage := controller( AP_Args() )

  //? cFileNoPath( cApp )
  //INI()  
 
  READINI()

  n    := hb_RAt( ".", cApp )
  cExt := left( cApp, n-1)
 
  //? "ohne cExt " + cExt
  cExt := UPPER( substr( cApp, n + 1) )
  //? "cExt " + cExt

  cApp := STRTRAN(cApp,"/","\")
  cApp := cFileNoPath( cApp )


   if lower(cApp) = "
landingpage1.prg"
      cImgfile :=  hb_GetEnv( "
PRGPATH" )  + "/img/logo1.svg"  
      cImgfile := STRTRAN( cImgfile,"
/","\")

      if file( cImgfile )
         cImgPath := "
./img/logo1.svg"
      endif      

      clandingpageFile := "
landingpage1"

   elseif lower(cApp) = "
landingpage2.prg"
      clandingpageFile := "
landingpage2"

   elseif lower(cApp) = "
landingpage3.prg"
      clandingpageFile := "
landingpage3"
     
   endif      

 
 

aRelationship_DBF := {}
cTMPPage := hb_GetEnv( "
PRGPATH" ) + "\data\" + clandingpageFile + ".dbf"
logging( "
-->Datenbank einlesen: " + cTMPPage  + "Filter" + cPage )

hHash_DBF := {=>}  

cStatus="
ready"

nRecords := 0  


use ( cTMPPage ) new ALIAS landingpage
logging( "
close: " + cTMPPage   )
Close
use ( cTMPPage ) new ALIAS landingpage

index on field->ID  TAG TmpB5Nr TO TEMP5 TEMPORARY
do while .not. eof()
  if field->ready = .T.
   if field->LANGUAGE  = cPage
      nRecords += 1
      AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->ID ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_ID" ] = ALLTRIM( field->ID )  
     
     elseif VALTYPE( field->ID ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_ID" ] = dtoc( field->ID )  
     
      elseif VALTYPE( field->ID ) = "
C"  .or. VALTYPE( field->ID ) = "M"
         if LEN( ALLTRIM( field->ID ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_ID" ] = ALLTRIM( field->ID )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_ID" ] = ALLTRIM( CONVERTUMLAUTE (  field->ID  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_ID" ] = ALLTRIM( field->ID )
      endif



        AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

        if VALTYPE( field->TEXT ) = "
N"
           hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT" ] = ALLTRIM( field->TEXT)  
       
        elseif VALTYPE( field->TEXT ) = "
D"
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_TEXT" ] = dtoc( field->TEXT )  
         
       
         elseif VALTYPE( field->TEXT ) = "
C"  .or. VALTYPE( field->TEXT ) = "M"
           
            if LEN( ALLTRIM( field->TEXT ) ) = 0
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT" ] = ALLTRIM( field->TEXT )
            else
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT" ] = ALLTRIM( CONVERTUMLAUTE (  field->TEXT  ) )
            endif
         else  
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT" ] = ALLTRIM( field->TEXT )
           endif


           

        AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

        if VALTYPE( field->PICTURE ) = "
N"
           hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_PICTURE" ] = ALLTRIM( field->PICTURE)  
       
        elseif VALTYPE( field->PICTURE ) = "
D"
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_PICTURE" ] = dtoc( field->PICTURE )  
         
       
         elseif VALTYPE( field->PICTURE ) = "
C"  .or. VALTYPE( field->PICTURE ) = "M"
           
            if LEN( ALLTRIM( field->PICTURE ) ) = 0
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_PICTURE" ] = ALLTRIM( field->PICTURE )
            else
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_PICTURE" ] = ALLTRIM( CONVERTUMLAUTE (  field->PICTURE  ) )
            endif
         else  
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_PICTURE" ] = ALLTRIM( field->PICTURE )
       
       
           endif





   AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->CAPTION ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_CAPTION" ] = ALLTRIM( field->CAPTION )  
     
     elseif VALTYPE( field->CAPTION ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_CAPTION" ] = dtoc( field->CAPTION )  
     
     
      elseif VALTYPE( field->CAPTION ) = "
C"  .or. VALTYPE( field->CAPTION ) = "M"
         
         if LEN( ALLTRIM( field->CAPTION ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_CAPTION" ] = ALLTRIM( field->CAPTION )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_CAPTION" ] = ALLTRIM( CONVERTUMLAUTE (  field->CAPTION  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_CAPTION" ] = ALLTRIM( field->CAPTION )
     
     
        endif
     AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->TITLE ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TITLE" ] = ALLTRIM( field->TITLE )  
     
     elseif VALTYPE( field->TITLE ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_TITLE" ] = dtoc( field->TITLE )  
     
     
      elseif VALTYPE( field->TITLE ) = "
C"  .or. VALTYPE( field->TITLE ) = "M"
         
         if LEN( ALLTRIM( field->TITLE ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TITLE" ] = ALLTRIM( field->TITLE )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TITLE" ] = ALLTRIM( CONVERTUMLAUTE (  field->TITLE  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TITLE" ] = ALLTRIM( field->TITLE )
     
     
        endif
 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->AWESOME ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_AWESOME" ] = ALLTRIM( field->AWESOME )  
     
     elseif VALTYPE( field->AWESOME ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_AWESOME" ] = dtoc( field->AWESOME )  
     
     
      elseif VALTYPE( field->AWESOME ) = "
C"  .or. VALTYPE( field->AWESOME ) = "M"
         
         if LEN( ALLTRIM( field->AWESOME ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_AWESOME" ] = ALLTRIM( field->AWESOME )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_AWESOME" ] = ALLTRIM( CONVERTUMLAUTE (  field->AWESOME  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_AWESOME" ] = ALLTRIM( field->AWESOME )
     
     
        endif
 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->FUNC ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FUNC" ] = ALLTRIM( field->FUNC )  
     
     elseif VALTYPE( field->FUNC ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_FUNC" ] = dtoc( field->FUNC )  
     
     
      elseif VALTYPE( field->FUNC ) = "
C"  .or. VALTYPE( field->FUNC ) = "M"
         
         if LEN( ALLTRIM( field->FUNC ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FUNC" ] = ALLTRIM( field->FUNC )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FUNC" ] = ALLTRIM( CONVERTUMLAUTE (  field->FUNC  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FUNC" ] = ALLTRIM( field->FUNC )
     
     
        endif
 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->STATUS ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_STATUS" ] = ALLTRIM( field->STATUS )  
     
     elseif VALTYPE( field->STATUS ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_STATUS" ] = dtoc( field->STATUS )  
     
     
      elseif VALTYPE( field->STATUS ) = "
C"  .or. VALTYPE( field->STATUS ) = "M"
         
         if LEN( ALLTRIM( field->STATUS ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_STATUS" ] = ALLTRIM( field->STATUS )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_STATUS" ] = ALLTRIM( CONVERTUMLAUTE (  field->STATUS  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_STATUS" ] = ALLTRIM( field->STATUS )
     
     
        endif
 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->COLOR ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_COLOR" ] = ALLTRIM( field->COLOR )  
     
     elseif VALTYPE( field->COLOR ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_COLOR" ] = dtoc( field->COLOR )  
     
     
      elseif VALTYPE( field->COLOR ) = "
C"  .or. VALTYPE( field->COLOR ) = "M"
         
         if LEN( ALLTRIM( field->COLOR ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_COLOR" ] = ALLTRIM( field->COLOR )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_COLOR" ] = ALLTRIM( CONVERTUMLAUTE (  field->COLOR  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_COLOR" ] = ALLTRIM( field->COLOR )
     
     
        endif


        AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

        if VALTYPE( field->TEXT_COLOR ) = "
N"
           hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT_COLOR" ] = ALLTRIM( field->TEXT_COLOR )  
       
        elseif VALTYPE( field->TEXT_COLOR ) = "
D"
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_TEXT_COLOR" ] = dtoc( field->TEXT_COLOR )  
         
       
         elseif VALTYPE( field->TEXT_COLOR ) = "
C"  .or. VALTYPE( field->TEXT_COLOR ) = "M"
           
            if LEN( ALLTRIM( field->TEXT_COLOR ) ) = 0
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT_COLOR" ] = ALLTRIM( field->TEXT_COLOR )
            else
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT_COLOR" ] = ALLTRIM( CONVERTUMLAUTE (  field->TEXT_COLOR  ) )
            endif
         else  
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_TEXT_COLOR" ] = ALLTRIM( field->TEXT_COLOR )
       
       
           endif



           AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

           if VALTYPE( field->BTN_COLOR ) = "
N"
              hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BTN_COLOR" ] = ALLTRIM( field->BTN_COLOR )  
           
           elseif VALTYPE( field->BTN_COLOR ) = "
D"
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_BTN_COLOR" ] = dtoc( field->BTN_COLOR )  
           
           
            elseif VALTYPE( field->BTN_COLOR ) = "
C"  .or. VALTYPE( field->BTN_COLOR ) = "M"
               
               if LEN( ALLTRIM( field->BTN_COLOR ) ) = 0
                  hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BTN_COLOR" ] = ALLTRIM( field->BTN_COLOR )
               else
                  hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BTN_COLOR" ] = ALLTRIM( CONVERTUMLAUTE (  field->BTN_COLOR  ) )
               endif
            else  
               hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BTN_COLOR" ] = ALLTRIM( field->BTN_COLOR )
           
           
              endif


              AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

              if VALTYPE( field->BG_COLOR ) = "
N"
                 hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BG_COLOR" ] = ALLTRIM( field->BG_COLOR )  
             
              elseif VALTYPE( field->BG_COLOR ) = "
D"
                  hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_BG_COLOR" ] = dtoc( field->BG_COLOR )  
               
             
               elseif VALTYPE( field->BG_COLOR ) = "
C"  .or. VALTYPE( field->BG_COLOR ) = "M"
                 
                  if LEN( ALLTRIM( field->BG_COLOR ) ) = 0
                     hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BG_COLOR" ] = ALLTRIM( field->BG_COLOR )
                  else
                     hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BG_COLOR" ] = ALLTRIM( CONVERTUMLAUTE (  field->BG_COLOR  ) )
                  endif
               else  
                  hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_BG_COLOR" ] = ALLTRIM( field->BG_COLOR )
             
             
                 endif
   


 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->FARBE ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FARBE" ] = ALLTRIM( field->FARBE )  
     
     elseif VALTYPE( field->FARBE ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_FARBE" ] = dtoc( field->FARBE )  
     
     
      elseif VALTYPE( field->FARBE ) = "
C"  .or. VALTYPE( field->FARBE ) = "M"
         
         if LEN( ALLTRIM( field->FARBE ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FARBE" ] = ALLTRIM( field->FARBE )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FARBE" ] = ALLTRIM( CONVERTUMLAUTE (  field->FARBE  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_FARBE" ] = ALLTRIM( field->FARBE )
     
     
        endif
 AADD( aRelationship_DBF, ( "
REC" + "_" + ALLTRIM( STR( nRecords ) ) + "_"  )  )

     if VALTYPE( field->LANGUAGE ) = "
N"
        hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_LANGUAGE" ] = ALLTRIM( field->LANGUAGE )  
     
     elseif VALTYPE( field->LANGUAGE ) = "
D"
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR(nRecords ) ) +"_LANGUAGE" ] = dtoc( field->LANGUAGE )  
     
     
      elseif VALTYPE( field->LANGUAGE ) = "
C"  .or. VALTYPE( field->LANGUAGE ) = "M"
         
         if LEN( ALLTRIM( field->LANGUAGE ) ) = 0
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_LANGUAGE" ] = ALLTRIM( field->LANGUAGE )
         else
            hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_LANGUAGE" ] = ALLTRIM( CONVERTUMLAUTE (  field->LANGUAGE  ) )
         endif
      else  
         hHash_DBF[ "
REC" + "_" + ALLTRIM( STR( nRecords ) ) +"_LANGUAGE" ] = ALLTRIM( field->LANGUAGE )
     
     
        endif
      endif
      endif  
  select landingpage
  skip
enddo
select landingpage
use


logging( "
<--Datenbank eingelesen: " + cTMPPage )
  cRecords := str(nRecords)
 
  TEMPLATE PARAMS hIni, hHash_DBF, cRecords,  cApp, cImgPath, cProgram  
 
  <!DOCTYPE html>
  <html>
 
<!-- HARBOURINO HEAD -->
<head>
  <link rel="
manifest" href="manifest.json">
  <meta charset="
utf-8">
  <meta name="
viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta http-equiv="
Cache-Control" content="no-cache, no-store, must-revalidate, private,  max-age=0, no-transform">
  <meta http-equiv="
Pragma" content="no-cache">
  <meta http-equiv="
Expires" content="0">
 

  <script>  
  var oIni=<?prg return hb_jsonEncode( hINI )?>;
 
   document.write( "
<title>" +  oIni[ 'name' ] + " APP</title>");
  </script>  


 
 
  <link rel="
stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 
  <!-- Font Awesome JS -->
  <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-iKbFRxucmOHIcpWdX9NTZ5WETOPm0Goy0WmfyNcl52qSYtc2Buk0NCe6jU1sWWNB" crossorigin="anonymous">
 
 
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
 
 
 
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script src="dist/js/fontawesome-iconpicker.js"></script>
 
 
 
  <body>
 
 
<!-- navbar start -->
<header>

   <script>
document.write('<nav class="navbar navbar-expand-sm fixed-top '+ oIni["navColor"] +'" style="' + oIni["navStyle"] + '">');
</script>
 
   <a class="navbar-brand" href="#">
   
<script>
 var cImgPath = <?prg return hb_jsonEncode(  cImgPath ) ?>
     document.write( '<img src= "' + cImgPath + '"  style=" max-width::200px;height:100px;" />' )

</script>
       
   </a>
   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
    <span class="navbar-toggler-icon"></span>
  </button>
   <div class="collapse navbar-collapse" id="collapsibleNavbar">
  <ul class="navbar-nav">
   
   
    <script>
      document.write( '<li class="nav-item"><a class="nav-link" href="'+  oIni[ "Telefonnummer" ] +'">CALL US</a></li>');
      document.write( '<li class="nav-item"><a class="nav-link" href="'+  oIni[ "Facebook" ] +'">FACEBOOK</a></li>');
   
     </script>
     <li class="nav-item"><a class="nav-link" onclick="displayLang(this.id)" id="de"><i class="far fa-flag"></i> deutsch</a></li>
     <li class="nav-item"><a class="nav-link" onclick="displayLang(this.id)" id="en"><i class="far fa-flag"></i> english</a></li>
     <li class="nav-item"><a class="nav-link" onclick="displayLang(this.id)" id="it"><i class="far fa-flag"></i> italiano</a></li>
   
     

  </ul>
  </div>
 
   </nav>
</header>

<script>

   function displayLang(cLang) {
      cprg = <?prg return  cProgram  ?>;
   
      if (cLang=='en') {
         
         location.href= cprg + '?sprache=en'
      } else if (cLang=='it') {
         
         location.href= cprg + '?sprache=it'
      } else {
         
         location.href= cprg  
      }

}
</script>
<!-- navbar end -->

 
   <div class="container-fluid" style="margin-top:140px">  
         
 
<!-- start cards -->
<div class="card-columns">

<script>  
  var object=<?prg return hb_jsonEncode( hHash_DBF )?>;
  var cKeyneu="";
  var nRecords=<?prg return  cRecords  ?>+1;
  var i;
  var cColor="btn-info";
  var cI;
  var cApp =  <?prg return hb_jsonEncode(  cAPP ) ?>

  for (i = 1; i < nRecords; i++) {
   
    cI=  i.toString();
    cCAPTION = object["REC_" + i.toString() + "_CAPTION"];
    cTITLE = object["REC_" + i.toString() + "_TITLE" ];
    cAWESOME = object["REC_" + i.toString() + "_AWESOME" ];
    cFARBE = object["REC_" + i.toString() + "_FARBE" ];
    cColor = object["REC_" + i.toString() + "_COLOR" ];
    cSprache= object["REC_" + i.toString() + "_LANGUAGE" ];
    cLink =  object["REC_" + i.toString() + "_FUNC" ];
    cID = object["REC_" + i.toString() + "_ID" ];
    cTEXT = object["REC_" + i.toString() + "_TEXT" ];
    cPICTURE = object["REC_" + i.toString() + "_PICTURE" ];
    cTextColor = object["REC_" + i.toString() + "_TEXT_COLOR" ];
    cBgColor = object["REC_" + i.toString() + "_BG_COLOR" ];
    cBtnColor = object["REC_" + i.toString() + "_BTN_COLOR" ];

   

    <!-- start card-->

  //  document.getElementsByClassName("nav-link").addEventListener("click", displayDate);
    //function displayDate() {
      //document.getElementById("demo").innerHTML = this.id;
    //}
   

    document.write( ' <div class="card ' + ' ' + ' text-center ' + ' ' + '" style="background-color:' + cBgColor + '; color:'+cTextColor+'"> ');
    <!--start card-img-top-->
    document.write(cPICTURE);  
    <!-- ende card-img-top-->
   
    <!-- start card body-->
    document.write('<div class="card-body">');  
   
      document.write(' <h4 class="card-title font-weight-bold"><i class="' + cAWESOME + '"></i>&nbsp;' + cCAPTION + '</h4>');  
      document.write('<p class="text-uppercase small">' + cTITLE + '</p>');  
      document.write('<p class="card-text">' + cTEXT + '</p>');  
    document.write('</div>');
    <!-- ende card body-->
    <!-- start card footer-->
    document.write(' <div class="card-footer">');  
    document.write('<button type="button" class="btn stretched-link btn-lg " style="color:' + cTextColor + '" onMouseOver="buttonMouseOver(this.id, object)" onMouseOut="buttonMouseOut(this.id, object)" onclick="myfunction1( this.id, object )" ID=' + cI + ' >');
    document.write('HIER KLICKEN</button>');

    document.write(' </div>');  
    <!-- ende card footer-->
    document.write(' </div>');
   
   
   
   
       
        }
   
     
  function myfunction1(clickId, object) {
   
     window.open( object["REC_" + clickId + "_FUNC" ] );
    }


 function buttonMouseOver(mouseId, object) {

       document.getElementById(mouseId).style.color = object["REC_"+mouseId+"_BG_COLOR"];
       document.getElementById(mouseId).style.background = object["REC_"+mouseId+"_TEXT_COLOR"];
 

  }

  function buttonMouseOut(mouseId, object) {

       document.getElementById(mouseId).style.color = object["REC_"+mouseId+"_TEXT_COLOR"];
       document.getElementById(mouseId).style.background = object["REC_"+mouseId+"_BG_COLOR"];
 

  }  
     
</script>
     </div>
     <!-- ende card-->

 



 
   <footer>
   <div class="container-fluid mt-5 p-3 border border-secondary text-dark">
      <div class="container text-center"><a href="https://winhotel.space/winhotelat/" title="WinHotel&reg;" target="_blank" class="w3-hover-text-blue text-dark" style="text-decoration:none">
         <b>WinHotel<sup>&reg;</sup></b></a> x
         <script>  
            document.write( oIni[ 'name' ] );
            </script>
         </div></div>

  </footer>
 
 
 
 
 
 
  </div>
  </body>
 
  </html>

ENDTEXT

return
//----------------------------------------------------------------------------//


//-- HARBOURINO   --//

INIT PROCEDURE PrgInit
 
  SET CENTURY ON
  SET EPOCH TO YEAR(DATE())-98
 
  SET DELETED ON
  SET EXCLUSIVE OFF
 
  REQUEST HB_Lang_DE
 
  HB_LangSelect("DE")
 
  SET DATE TO GERMAN
 
  rddsetdefault( "DBFCDX" )
 
  EXTERN DESCEND
 
RETURN

function convertUmlaute( cVData )
    local ctest := ""
    local I := 0
   
   
  //  for I := 1 to len(cVData)
   
   // ? ( cVData + CRLF + substr(cVData,I,1) + "  #  "+ str( ASC ( substr(cVData,I,1)) ))
   
   
 //   next
   
   
    cVData  :=  STRTRAN(cVData, chr(228), "&auml;"   )
    cVData  :=  STRTRAN(cVData, chr(132), "&auml;"   )
   
   
    cVData  :=  STRTRAN(cVData, chr(246), "&ouml;"   )
    cVData  :=  STRTRAN(cVData, chr(148), "&ouml;"   )
   
    cVData  :=  STRTRAN(cVData, chr(252), "&uuml;"   )
    cVData  :=  STRTRAN(cVData, chr(129), "&uuml;"   )
   
    cVData  :=  STRTRAN(cVData, chr(196), "&Auml;"   )
    cVData  :=  STRTRAN(cVData, chr(142), "&Auml;"   )
   
   
    cVData  :=  STRTRAN(cVData, chr(214), "&Ouml;"   )
    cVData  :=  STRTRAN(cVData, chr(153), "&Ouml;"   )
   
    cVData  :=  STRTRAN(cVData, chr(220), "&Üuml;" )
    cVData  :=  STRTRAN(cVData, chr(154), "&Üuml;" )
   
    cVData  :=  STRTRAN(cVData, chr(223), "&szlig;" )
    cVData  :=  STRTRAN(cVData, chr(225), "&szlig;" )

    cVData  :=  STRTRAN(cVData, chr(224), "&agrave;" )

    cVData  :=  STRTRAN(cVData, chr(225), "&aacute;" )
 
   
    /*
   
   
    small sharp s ("s-zet")     ß  alt + 225   &szlig;
    small a umlaut  ä  alt + 132   &auml;
    small o umlaut  ö  alt + 148   &ouml;
    small u umlaut  ü  alt + 129   &uuml;
    capital A umlaut    Ä  alt + 142   &Auml;
    capital O umlaut    Ö  alt + 153   &Ouml;
    capital U umlaut    Ü  alt + 154   &Uuml;
   
   
    Zeichen Beschreibung    URL HTML-Entität   Unicode (HTML)
    Ä  Lateinischer Großbuchstabe Umlaut A    %C3%84  &Auml;  &#196;  &#xC4;
    Ö  Lateinischer Großbuchstabe Umlaut O    %C3%96  &Ouml;  &#214;  &#xD6;
    Ü  Lateinischer Großbuchstabe Umlaut U    %C3%9C  &Uuml;  &#220;  &#xDC;
    ß  Lateinischer Kleinbuchstabe Scharfes s  %C3%9F  &szlig; &#223;  &#xDF;
    ä  Lateinischer Kleinbuchstabe Umlaut a    %C3%A4  &auml;  &#228;  &#xE4;
    ö  Lateinischer Kleinbuchstabe Umlaut o    %C3%B6  &ouml;  &#246;  &#xF6;
    ü  Lateinischer Kleinbuchstabe Umlaut u    %C3%BC  &uuml;  &#252;  &#xFC;
    ẞ Lateinischer Großbuchstabe Scharfes S[1]   %E1%BA%9E       &#7838; &#x1E9E;
    HTML-eigene und Wikipedia-spezifische Zeichen
    */

   
return(cVData)


function cFileNoPath( cPathMask )  // returns just the filename no path

   local n := RAt( "\", cPathMask )

return If( n > 0 .and. n < Len( cPathMask ),;
          Right( cPathMask, Len( cPathMask ) - n ),;
          If( ( n := At( "
:", cPathMask ) ) > 0,;
          Right( cPathMask, Len( cPathMask ) - n ),;
          cPathMask ) )

//---------------------------------------------------------------------------//

function READINI()

   local cIni      :=  hb_GetEnv( "
PRGPATH" ) + '/myini.txt'
   
   hIni := hb_jsondecode( memoread( cIni ))
 
retu nil


function INI()

   local cIni      :=  hb_GetEnv( "
PRGPATH" ) + '/myini.txt'
   
 
   hIni[ 'name' ] := 'Charly'
   
   hIni[ 'Facebook' ] := 'Facebook'

   hIni[ 'Telefonnummer' ] := 'Telefonnummer'
   
   hIni[ 'Telefonnummer' ] := 'Telefonnummer'
   
   //  Save your ini
   memowrit( cIni, hb_jsonencode( hIni ) )
 
   //  Read your ini
   h := hb_jsondecode( memoread( cIni ))
 
   ? hIni[ 'name' ]  
   
   ? hIni[ 'Facebook' ]  

   ? hIni[ 'Telefonnummer' ]
   
   ? hIni[ 'Telefonnummer' ]  
   

retu nil

//----------------------------------------------------------------------------//
function Controller( cRequest )
   local aRequest
   
    logging( cRequest )
   
    if "
=" $ cRequest
       aRequest = hb_aTokens( cRequest, "
=" )
       cRequest = aRequest[ 2 ]
       logging( cRequest )
       if val(cRequest) > 0
         lDefault := .f.    // content from database
       endif  
   else
      cRequest = "
de"
   endif    
 
  return( cRequest )
 
  //----------------------------------------------------------------------------//

  function logging( cText )
   local cLog
   local cPRGPath := STRTRAN( HB_GETENV( 'PRGPATH' ), "
/", "\" )
   
   cLog := memoread( cPRGPath+ "
\prg.log")
   cLog   +=  dtos(date())+time()+ "
line: " + ALLTRIM( str(procline(1)) ) + "   : "  + cText+ CRLF
   MEMOWRIT( cPRGPath+ "
\prg.log" , cLog, .f. )
return nil

//----------------------------------------------------------------//

User avatar
Ruth
 
Posts: 156
Joined: Fri Dec 07, 2007 1:26 pm

Re: Creating Language Switcher

Postby Antonio Linares » Mon Jul 26, 2021 5:55 pm

Dear Ruth,

many thanks for sharing it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41403
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 2 guests