To Antonio: fwstring

To Antonio: fwstring

Postby Silvio.Falconi » Tue Oct 08, 2013 2:35 pm

Dear Antonio,
I try to converte fwstrings functions into methods of a Tapplication


METHOD LanguageID()
METHOD LoadPreferences()
METHOD SavePreferences()
METHOD FWSetLanguage( nNewLanguage )
METHOD FWAddLanguage( aLang, nLang )
METHOD FWString( cString )
METHOD FWAddString( aString )
METHOD FWMissingStrings()

astrings and amissings are data


I saw the error is on this array




if the astring is only

::aStrings := { ;
{ "Attention" , "Atención" ,"Attention" ,"Atenção" ,"Achtung" , "Attenzione" }}

it run ok

if I add aline on the astrings it make error

::aStrings := { ;
{ "Attention" , "Atención" ,"Attention" ,"Atenção" ,"Achtung" , "Attenzione" },;
{ "Language" , "Lenguaje" ,"Language" ,"Language" ,"Language" ,"Linguaggio" },;
}


why ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Silvio.Falconi » Tue Oct 08, 2013 2:43 pm

sorry I found the error
::aStrings := { ;
{ "Attention" , "Atención" ,"Attention" ,"Atenção" ,"Achtung" , "Attenzione" },;
{ "Language" , "Lenguaje" ,"Language" ,"Language" ,"Language" ,"Linguaggio" }}

instead of

::aStrings := { ;
{ "Attention" , "Atención" ,"Attention" ,"Atenção" ,"Achtung" , "Attenzione" },;
{ "Language" , "Lenguaje" ,"Language" ,"Language" ,"Language" ,"Linguaggio" },;
}

strange !!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Silvio.Falconi » Tue Oct 08, 2013 3:00 pm

Antonio,

I think astrings is to easy if we load the string from ascii extern file

lang.lng
Code: Select all  Expand view

[LANG]
1=Attention|Atención|Attention|Atenção|Achtung|Attenzione
2=Language|Lenguaje|Language|Language|Language|Linguaggio
3=English|Inglés|English|English|English|Inglese
4=Spanish|Español|Español|Español|Español|Spagnolo
5=French|Frances|Frances|Frances|Frances|Francese
6=German|Alemán|German|German|German|Tedesco
7=Portuguese|Portugues|Portugues|Portugues|Portugues|Portoghese
8=Italian|Italiano|Italiano|Italiano|Italiano|Italiano
9=Preferences|Preferences|Preferences|Preferences|Preferences|Preferenze
10=&Ok|&Ok|&Ok|&Ok|&Ok|&Conferma
11=&Cancel|&Cancel|&Cancel|&Cancel|&Cancel|&Annulla
12=&Archivio|&Archivio|&Archivio|&Archivio|&Archivio|&Archivio
13=


on main application we insert

::aStrings := Load_aStrings()


Function Load_aStrings()
Code: Select all  Expand view

Function Load_aStrings()
   Local cInistrings:=cFilePath(GetModuleFileName( GetInstance() ) ) + "lang.lng"
   LOCAL cString    :=""
   LOCAL i          := 1
   LOCAL lContinue  := .T.
     aStrings   := {}
 DO WHILE lContinue = .T.
         cString :=  GetIni( cInistrings, "LANG", ALLTRIM(STR(i++,4)), "" )
      IF .NOT. EMPTY( cString )
         AADD( aStrings, { ALLTRIM( StrToken( cString, 1, "|" ) ), ;
                          ALLTRIM( StrToken(  cString, 2, "|" ) ), ;
                          ALLTRIM( StrToken(  cString, 3, "|" ) ), ;
                          ALLTRIM( StrToken(  cString, 4, "|" ) ), ;
                          ALLTRIM( StrToken(  cString, 5, "|" ) ), ;
                          ALLTRIM( StrToken(  cString, 6, "|" ) ) } )
      ELSE
         lContinue := .F.
      ENDIF
   ENDDO
   IF LEN( aStrings ) = 0
      MsgStop( "Nessuna lingua definita in " + ALLTRIM( cInistrings ) )
      RETURN(.F.)
   ELSE
      //only for trace
     // xbrowser aStrings
   ENDIF
   RETURN aStrings
 


do you like this idea ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Antonio Linares » Tue Oct 08, 2013 4:03 pm

Silvio,

Yes, good idea, thanks! :-)

I propose this code based on yours:
Code: Select all  Expand view
function FWLoadStrings( cFileName )

   local cLine, n := 1

   DEFAULT cFileName := cFilePath( GetModuleFileName( GetInstance() ) ) + ;
                        "fwstrings.ini"
   
   while ! Empty( cLine := GetProfString( cFileName, "LANG", AllTrim( Str( n++, 4 ) ) ) )
      AAdd( aStrings, { AllTrim( StrToken( cLine, 1, "|" ) ),;
                        AllTrim( StrToken( cLine, 2, "|" ) ),;
                        AllTrim( StrToken( cLine, 3, "|" ) ),;
                        AllTrim( StrToken( cLine, 4, "|" ) ),;
                        AllTrim( StrToken( cLine, 5, "|" ) ),;
                        AllTrim( StrToken( cLine, 6, "|" ) ) } )
   end
   
return nil
regards, saludos

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

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 10:14 am

trying your code here make error
Code: Select all  Expand view
Error description: Error BASE/1123  Argument error: AADD
   Args:
     [   1] = U  
     [   2] = A   { ... }

Stack Calls
===========
   Called from:  => AADD( 0 )
   Called from: source\main.prg => TAPPLICATION:FWLOADSTRINGS( 417 )
   Called from: source\main.prg => TAPPLICATION:NEW( 117 )
   Called from: source\main.prg => MAIN( 29 )
 



Please compile this test
Code: Select all  Expand view


#include "FiveWin.ch"

REQUEST DBFCDX
REQUEST DBFFPT



memvar oApp



FUNCTION Main()

   PUBLIC oApp

   RddSetDefault( "DBFCDX" )


   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

   WITH OBJECT oApp := TApplication():New()
      :Activate()
   END

RETURN nil



CLASS tApplication

   data cAppName
   data cVersion
   data cEdicion
   data cBuild
   data cUrl
   data cMsgBar

   DATA cIniFile
   DATA cZipPath

   DATA oWndMain
   DATA oFont
   DATA oBar
   DATA oExit
   DATA oIcon
   DATA oMsgItem1
   DATA oMsgItem2
   DATA oMsgItem3
   DATA oDlg
   DATA oGrid
   DATA oTab
   DATA oSplit
   DATA nEdit

   DATA nLanguage
   DATA aStrings
   DATA aMissing

   METHOD New() CONSTRUCTOR

   METHOD Activate()

   METHOD BuildMenu()
   METHOD BuildBtnBar()

   METHOD Close()

   METHOD End() INLINE ( /*SetWinCoors( ::oWndMain, ::cIniFile ),*/ ::oWndMain:End() )

   METHOD ExitFromX()
   METHOD ExitFromBtn()
   METHOD ExitFromSource()




    METHOD LanguageID()
    METHOD LoadPreferences()
    METHOD SavePreferences()
    METHOD FWSetLanguage( nNewLanguage )
    METHOD FWAddLanguage( aLang, nLang )
    METHOD FWString( cString )
    METHOD FWMissingStrings()
    METHOD FWLoadStrings( cFileName )
    METHOD FWAddString()

ENDCLASS

/*_____________________________________________________________________________*/

METHOD New() CLASS tApplication

   ::cAppName  := i18n("Fsdi 2013")
   ::cVersion  := "1.00 RC-1"
   ::cBuild    := "build 08.10.13"
   ::cUrl      := "http://www.eoeo.it"
   ::cMsgBar   := "© eoeo software"
   ::cIniFile    := cFilePath( GetModuleFileName( GetInstance() ) ) + "fsdi.ini"
   ::nLanguage   := 2  // Spanish. By default it is 1 English
   ::aMissing := {}
   ::oFont = TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, )
   ::aMissing := {}

   ::astrings:=::FWLoadStrings("lang.lng")


   ::FWSetLanguage( ::nLanguage) // Spanish. By default it is 1 English
   ::LoadPreferences()


    ? ::LanguageID()


   DEFINE WINDOW ::oWndMain   ;
      TITLE ::cAppName + ::cVersion ;
      MENU ::BuildMenu()      ;
      COLOR CLR_BLACK, GetSysColor( 15 ) - Rgb( 30, 30, 30 ) ;
      ICON ::oIcon

      SET MESSAGE OF ::oWndMain TO ::cMsgBar CENTER NOINSET



      DEFINE MSGITEM ::oMsgItem2;
         OF ::oWndMain:oMsgBar ;
         PROMPT ::cMsgBar      ;
         SIZE 100              ;
         BITMAPS "MSG_LOTUS", "MSG_LOTUS";
         TOOLTIP " " + i18n("Acerca de...") + " ";
         ACTION MsgInfo( "Test with strings" )

      DEFINE MSGITEM ::oMsgItem3 OF ::oWndMain:oMsgBar ;
         SIZE 132 ;
         TOOLTIP i18n( "Visitare il sito web di eoeo  in internet" ) ;
         PROMPT "www.eoeo.it" ;
         COLOR CLR_HBLUE, GetSysColor(15)    ;
         ACTION NIL

      ::oWndMain:oMsgBar:DateOn()

   ::BuildBtnBar()

RETURN Self

/*_____________________________________________________________________________*/

method Activate() class TApplication

   //GetWinCoors( ::oWndMain, ::cInifile )

   ::oWndMain:bResized := {|| ResizeWndMain() }

   ACTIVATE WINDOW ::oWndMain ;
      VALID ::ExitFromX()

   ::oFont:End()




return NIL

/*_____________________________________________________________________________*/

METHOD BuildMenu() CLASS TApplication

   local oMenu

   MENU oMenu 2010

*  MENUITEM "&Archivo"
    MENUITEM ::FWSTRING("&Archivo")
         MENU
            MENUITEM i18n( "Especificar impresora" ) ;
               ACTION PrinterSetup() ;
               MESSAGE i18n( " Establecer la Configuración de su impresora. " )
            SEPARATOR

             MENUITEM i18n( "Configuración" ) ;
               ACTION Preferences() ;
               MESSAGE i18n( " Establecer la Configuración de su impresora. " )
            SEPARATOR

            MENUITEM i18n( "Salir" ) ;
               ACTION ::ExitFromBtn() ;
               MESSAGE i18n( " Terminar la ejecución del programa. " )
         ENDMENU
   ENDMENU

   RETURN oMenu







/*_____________________________________________________________________________*/

METHOD BuildBtnBar() CLASS TApplication

   local oBtnTbl

   DEFINE BUTTONBAR ::oBar _3D SIZE 44, 46 OF ::oWndMain //36, 40

      ::oBar:bRClicked := { || .t. }

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      NOBORDER

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      NOBORDER

   DEFINE BUTTON ::oExit OF ::oBar  ;
      RESOURCE "BB2"      ;
      TOOLTIP i18n( "Salir del programa" ) ;
      MESSAGE i18n( "Finalizar el uso del programa." ) ;
      ACTION ( ::ExitFromBtn() ) ;
      GROUP NOBORDER

RETURN Self




/*_____________________________________________________________________________*/


METHOD Close() CLASS TApplication

   ResAllFree()

RETURN nil

/*_____________________________________________________________________________*/


METHOD ExitFromBtn() CLASS tApplication

   ::oWndMain:End()

RETURN nil

/*_____________________________________________________________________________*/

METHOD ExitFromX() CLASS tApplication

   if oApp:oDlg != nil
      if oApp:nEdit > 0
         msgStop( i18n("No puede salir del programa hasta que no cierre las ventanas abiertas sobre el mantenimiento que está manejando.") )
         RETURN .f.
      end

   end
   if msgYesNo( i18n("¿Desea finalizar el programa?") )
      if oApp:oDlg != nil
         oApp:oDlg:End()
      endif
     // SetWinCoors( ::oWndMain, ::cIniFile )
      RETURN .t.
   end

RETURN .F.

/*_____________________________________________________________________________*/

METHOD ExitFromSource() CLASS tApplication

   ::oWndMain:bValid := { ||::FWMissingStrings() /*SetWinCoors( ::oWndMain, ::cIniFile )*/, .t. }
   ::oWndMain:End()

RETURN nil

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

METHOD LanguageID()    CLASS tApplication

   if Empty( ::nLanguage )
      ::nLanguage   = Max( 1, AScan( { "EN", "ES", "FR", "PT", "DE", "IT" },;
                        Upper( Left( HB_LangSelect(), 2 ) ) ) )
   endif

return ::nLanguage

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

METHOD  LoadPreferences()  CLASS tApplication
   ::nLanguage :=  GetIni( ::cIniFile, "Default", "Language", ::FWSetLanguage() )
   ::FWSetLanguage( ::nLanguage )
return nil
//----------------------------------------------------------------------------//
METHOD SavePreferences() CLASS tApplication
   ::nLanguage := ::FWSetLanguage()
   SetIni( ::cIniFile, "Default", "Language",::nLanguage )
return nil
//----------------------------------------------------------------------------//

METHOD FWSetLanguage( nNewLanguage ) CLASS tApplication

   local nOldLanguage := ::LanguageID()

   if ! Empty( nNewLanguage )
      ::nLanguage := Max( 1, Min( nNewLanguage, Len( ::aStrings[ 1 ] ) ) )
   endif

return nOldLanguage

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

METHOD FWAddLanguage( aLang, nLang )  CLASS tApplication

   if ValType( aLang ) == 'A' .and. ! Empty( aLang )
      ::aStrings    := ArrTranspose( ::aStrings )
      if nLang == nil .or. nLang > Len( ::aStrings )
         AAdd( ::aStrings, aLang )
         nLang := Len( ::aStrings )
      else
         ::aStrings[ nLang ] := aLang
      endif
      ::aStrings    := ArrTranspose( ::aStrings )
      ::FWSetLanguage( nLang )
   endif

   return nLang
//----------------------------------------------------------------------------//

METHOD FWString( cString ) CLASS tApplication

   local nAt

   if ::LanguageID() == 1
      return cString
   elseif ( nAt := AScan( ::aStrings, { | aString | Upper( aString[ 1 ] ) == Upper( cString ) } ) ) != 0
      return IfNil( ::aStrings[ nAt ][ ::LanguageID() ], cString )
   else
      if '&' $ cString
         cString  := StrTran( cString, '&', '' )
         if ( nAt := AScan( ::aStrings, { | aString | Upper( aString[ 1 ] ) == Upper( cString ) } ) ) != 0
            return '&' + IfNil( ::aStrings[ nAt ][::LanguageID() ], cString )
         endif
      endif
      MsgInfo( 'La stringa: "' + cString + '"' + CRLF + ;
               "definita in: " + ProcName( 1 ) + " linea " + ;
               AllTrim( Str( ProcLine( 1 ) ) ) + " in " + ProcFile( 1 ) + CRLF + ;
               "non è stata trovata in archivio lingue" + CRLF + ;
               " " )
      AAdd( ::aMissing, cString )
   endif

   return cString
//----------------------------------------------------------------------------//

  METHOD FWMissingStrings()  CLASS tApplication

   local cResult := ""

   AEval( ::aMissing, { | cString | cResult += Space( 7 ) + '{ "' + cString + ;
                                  '", "" },;' + CRLF } )
   if ! Empty( cResult )
      MemoEdit( cResult, "Copy and paste in FWH\source\function\strings.prg" )
   endif

   return cResult

//----------------------------------------------------------------------------//
      /*
METHOD FWLoadStrings( cFileName )  CLASS tApplication

        local cLine :="", n := 1
         local aStrings   := {}
   DEFAULT cFileName := cFilePath( GetModuleFileName( GetInstance() ) ) + ;
                        "fwstrings.ini"

   while ! Empty( cLine := GetProfString( cFileName, "LANG", AllTrim( Str( n++, 4 ) ) ) )
      AAdd( ::aStrings, { AllTrim( StrToken( cLine, 1, "|" ) ),;
                        AllTrim( StrToken( cLine, 2, "|" ) ),;
                        AllTrim( StrToken( cLine, 3, "|" ) ),;
                        AllTrim( StrToken( cLine, 4, "|" ) ),;
                        AllTrim( StrToken( cLine, 5, "|" ) ),;
                        AllTrim( StrToken( cLine, 6, "|" ) ) } )
   end

   return aStrings
   */



METHOD FWLoadStrings( cFileName )  CLASS tApplication
 Local cInistrings:=cFilePath(GetModuleFileName( GetInstance() ) ) + "lang.lng"
   LOCAL cString    :=""
   LOCAL i          := 1    
   LOCAL lContinue  := .T.

   Local aTranslates := {}


 DO WHILE lContinue = .T.
         cString :=  GetIni( cInistrings, "LANG", ALLTRIM(STR(i++,4)), "" )
      IF .NOT. EMPTY( cString )
         AADD( aTranslates, { ALLTRIM( StrToken(  cString, 1, "|" ) ), ;
                              ALLTRIM( StrToken(  cString, 2, "|" ) ), ;
                              ALLTRIM( StrToken(  cString, 3, "|" ) ), ;
                              ALLTRIM( StrToken(  cString, 4, "|" ) ), ;
                              ALLTRIM( StrToken(  cString, 5, "|" ) ), ;
                              ALLTRIM( StrToken(  cString, 6, "|" ) ) } )
      ELSE                  
         lContinue := .F.  
      ENDIF                
   ENDDO


   IF LEN( aTranslates ) = 0
      MsgStop( "Nessuna lingua definita in " + ALLTRIM( cInistrings ) )
      RETURN(.F.)          
   ELSE                    
      //only for trace      
     // xbrowser aTranslates
   ENDIF                    
   RETURN aTranslates

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

METHOD FWAddString()  CLASS tApplication

return AAdd( ::aStrings, aString )
//----------------------------------------------------------------------------//

FUNCTION oApp()
   Return oApp

 FUNCTION FWString(cMessage)
       Return oApp():FWString(cMessage)








Function ResizeWndMain()

return NIL


function Preferences()

   local oDlg

   DEFINE DIALOG oDlg TITLE FWString( "Preferences" ) SIZE 400, 300



   @ 4.6, 1.5 SAY FWString( "Language" ) OF oDlg

   DEFAULT oApp:nLanguage := ::FWSetLanguage()

   @ 6, 1.2 COMBOBOX oApp:nLanguage ;
      ITEMS { FWString( "English" ), FWString( "Spanish" ), FWString( "French" ),;
              FWString( "Portuguese" ), FWString( "German" ) , FWString( "Italian" ) } ;
      OF oDlg SIZE 180, 150 ;
      ON CHANGE ( oApp:FWSetLanguage( oApp:nLanguage ), oApp:oWndMain:SetMenu( oApp:BuildMenu() ),;
                  oApp:BuildBtnBar() )

   @ 7, 7 BUTTON FWString( "&Ok" ) OF oDlg SIZE 45, 13 ;
      ACTION (oApp:SavePreferences(), oDlg:End() )

   @ 7, 18 BUTTON FWString( "&Cancel" ) OF oDlg SIZE 45, 13 ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

return nil








   FUNCTION SetIni( cIni, cSection, cEntry, xVar )

   LOCAL oIni

   DEFAULT cIni := oApp:cIniFile

   INI oIni FILE cIni
      SET SECTION cSection ;
         ENTRY cEntry      ;
         TO xVar           ;
         OF oIni
   ENDINI

RETURN nil

/*_____________________________________________________________________________*/

FUNCTION GetIni( cIni, cSection, cEntry, xDefault )

   LOCAL oIni
   LOCAL xVar := xDefault

   DEFAULT cIni := oApp:cIniFile

   INI oIni FILE cIni
      GET xVar            ;
         SECTION cSection ;
         ENTRY cEntry     ;
         DEFAULT xDefault ;
         OF oIni
   ENDINI

RETURN xVar




/*_____________________________________________________________________________*/

//___ manejo de fuentes © Paco García 2006 ____________________________________//

#pragma BEGINDUMP
#include "Windows.h"
#include "hbapi.h"

HB_FUNC( GETDEFAULTFONTNAME )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retc( lf.lfFaceName );
}

HB_FUNC( GETDEFAULTFONTHEIGHT )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retni( lf.lfHeight );
}


#pragma ENDDUMP

//_____________________________________________________________________________//









 




the lang.lng
Code: Select all  Expand view

[Lang]
1=Attention|Atención|Attention|Atenção|Achtung|Attenzione
2=Language|Lenguaje|Language|Language|Language|Linguaggio
3=English|Inglés|English|English|English|Inglese
4=Spanish|Español|Español|Español|Español|Spagnolo
5=French|Frances|Frances|Frances|Frances|Francese
6=German|Alemán|German|German|German|Tedesco
7=Portuguese|Portugues|Portugues|Portugues|Portugues|Portoghese
8=Italian|Italiano|Italiano|Italiano|Italiano|Italiano
9=Preferences|Preferences|Preferences|Preferences|Preferences|Preferenze
10=&Ok|&Ok|&Ok|&Ok|&Ok|&Conferma
11=&Cancel|&Cancel|&Cancel|&Cancel|&Cancel|&Annulla
12=&Archivo|&Archivio|&Archivio|&Archivio|&Archivio|&Archivio
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 10:26 am

add this methos to the class

METHOD FWModStrings() to modify the strings

Code: Select all  Expand view
METHOD  FWModStrings() CLASS tApplication
   Local oBrwstrings,oFont

       DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -14

   DEFINE DIALOG oDlg SIZE 640,450 PIXEL ;
      FONT oFont TITLE FWString('Modify strings languages')


   @ 0,0 XBROWSE oBrwstrings OF  oDlg                   ;
      COLUMNS 1, 2, 3, 4, 5, 6                          ;
      HEADERS FWString("English"),FWString("Spanish")  ,;
              FWString("French"), FWString("Portugese"),;
              FWString("German"), FWString("Italian")   ;
      COLSIZES 100, 100, 100, 100,100,100           ;
      ARRAY ::aStrings LINES FASTEDIT CELL  SIZE 320, 200

   oBrwstrings:nMarqueeStyle    = MARQSTYLE_HIGHLWIN7

WITH OBJECT oBrwstrings
      :nEditTypes   := EDIT_GET
      :CreateFromCode()
   END


    ACTIVATE DIALOG oDlg CENTERED

   RELEASE FONT oFont

return nil


I not Know how save the lang.lng file
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Antonio Linares » Wed Oct 09, 2013 12:49 pm

Silvio,

Your aStrings must be initialized as {}

static aStrings := {}
regards, saludos

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

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 7:34 pm

Antonio,
I tried also
my astrings is a data ::astrings
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 8:46 pm

Antonio,
I made another test It seems run ok but then I have this error when open the prefrences and save a new lang



Code: Select all  Expand view


Time from start: 0 hours 0 mins 22 secs
   Error occurred at: 09-10-2013, 22:30:53
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   { ... }
     [   2] = N   1

Stack Calls
===========
   Called from: source\ut\strings.prg => FWSETLANGUAGE( 45 )
   Called from: source\ut\strings.prg => (b)PREFERENCES( 168 )
   Called from: .\source\classes\COMBOBOX.PRG => TCOMBOBOX:CHANGE( 420 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1698 )
   Called from: .\source\classes\COMBOBOX.PRG => TCOMBOBOX:HANDLEEVENT( 686 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3183 )
   Called from:  => SENDMESSAGE( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 410 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 892 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 274 )
   Called from: source\ut\strings.prg => PREFERENCES( 182 )
   Called from: source\main.prg => (b)TAPPLICATION:BUILDMENU( 185 )
   Called from: .\source\classes\MENU.PRG => TMENU:COMMAND( 463 )
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND( 1043 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3183 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 996 )
   Called from: source\main.prg => TAPPLICATION:ACTIVATE( 164 )
   Called from: source\main.prg => MAIN( 50 )
 




I used your strings.prg and load the strings array from file at the init of New method with FWLoadStrings( "fwstrings.ini" )

fwstrings.ini

Code: Select all  Expand view
[Lang]
1=Attention|Atención|Attention|Atenção|Achtung|Attenzione






Main.prg

Code: Select all  Expand view


#include "FiveWin.ch"
#define NOME_PROGRAMMA_TITLE  "teststrings"

REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO



memvar oApp






/*_____________________________________________________________________________*/

FUNCTION Main()

   PUBLIC oApp

   RddSetDefault( "DBFCDX" )

   SetHandleCount( 100 )

   aStrings := {}

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

   SetBalloon( .T. )


    IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )
        MsgWait(NOME_PROGRAMMA_TITLE+"  è già in esecuzione !","Attenzione")
        SHOWWINDOW( FINDWINDOW( 0, NOME_PROGRAMMA_TITLE ), 9 )
        SETFOREGROUNDWINDOW( FINDWINDOW( 0, NOME_PROGRAMMA_TITLE ) )
        RETURN NIL
    ENDIF



   WITH OBJECT oApp := TApplication():New()
      :Activate()
   END

RETURN nil

/*_____________________________________________________________________________*/

CLASS tApplication

   data cAppName
   data cVersion
   data cEdicion
   data cBuild
   data cUrl
   data cMsgBar

   DATA cIniFile
   DATA cZipPath

   DATA oWndMain
   DATA oFont
   DATA oBar
   DATA oExit
   DATA oIcon
   DATA oMsgItem1
   DATA oMsgItem2
   DATA oMsgItem3
   DATA oDlg
   DATA oGrid
   DATA oTab
   DATA oSplit
   DATA nEdit



   METHOD New() CONSTRUCTOR

   METHOD Activate()

   METHOD BuildMenu()
   METHOD BuildBtnBar()

   METHOD Close()

   METHOD End() INLINE (/* SetWinCoors( ::oWndMain, ::cIniFile ),*/ ::oWndMain:End() )

   METHOD ExitFromX()
   METHOD ExitFromBtn()
   METHOD ExitFromSource()

ENDCLASS

/*_____________________________________________________________________________*/

METHOD New() CLASS tApplication

   ::cAppName  := i18n("Test string Language")
   ::cVersion  := "1.00 RC-1"
   ::cBuild    := "build 09.10.2013"

   ::cUrl        := "http://www.fivetech.com"
   ::cMsgBar     := " software"

   ::cIniFile    := cFilePath( GetModuleFileName( GetInstance() ) ) + "fsdi.ini"

   ::oDlg        := nil
   ::nEdit       := 0

   ::oFont = TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, )
   DEFINE ICON ::oIcon RESOURCE "ICON1"


    FWLoadStrings( "fsdi.ini" )    // load the strings from file


   DEFINE WINDOW ::oWndMain   ;
      TITLE ::cAppName + ::cVersion ;
      MENU ::BuildMenu()      ;
      COLOR CLR_BLACK, GetSysColor( 15 ) - Rgb( 30, 30, 30 ) ;
      ICON ::oIcon

   SET MESSAGE OF ::oWndMain TO ::cMsgBar CENTER NOINSET


      DEFINE MSGITEM ::oMsgItem2;
         OF ::oWndMain:oMsgBar ;
         PROMPT ::cMsgBar      ;
         SIZE 100              ;
         BITMAPS "MSG_LOTUS", "MSG_LOTUS";
         TOOLTIP " " + i18n("Acerca de...") + " ";
         ACTION MsgInfo( "Test de strings languages" )

      DEFINE MSGITEM ::oMsgItem3 OF ::oWndMain:oMsgBar ;
         SIZE 132 ;
         TOOLTIP i18n( "Visitar la web de fivetech en internet" ) ;
         PROMPT "www.fivetechsoft.com" ;
         COLOR CLR_HBLUE, GetSysColor(15)    ;
         ACTION ( GoWeb( ::cUrl ) )

      ::oWndMain:oMsgBar:DateOn()

   ::BuildBtnBar()

RETURN Self

/*_____________________________________________________________________________*/

method Activate() class TApplication

 //  GetWinCoors( ::oWndMain, ::cInifile )

   ::oWndMain:bResized := {|| ResizeWndMain() }

   ACTIVATE WINDOW ::oWndMain ;
      VALID ::ExitFromX()

   ::oFont:End()

return NIL

/*_____________________________________________________________________________*/

METHOD BuildMenu() CLASS TApplication

   local oMenu
   MENU oMenu
      MENUITEM FWString("&Archivo")
         MENU
            MENUITEM FWString( "Especificar impresora" ) ;
               ACTION PrinterSetup() ;
               MESSAGE FWString( "Establecer la Configuración de su impresora." )

              SEPARATOR
             MENUITEM FWString( "Preferences" ) ;
               ACTION Preferences() ;
               MESSAGE FWString( "Establecer la Configuración de su impresora." )
               SEPARATOR
             MENUITEM FWString( "List Missings" ) ;
               ACTION FWMissingStrings() ;
               MESSAGE FWString( "Establecer la Configuración de su impresora." )

            SEPARATOR
            MENUITEM FWString( "Salir" ) ;
               ACTION ::ExitFromBtn() ;
               MESSAGE FWString( "Terminar la ejecución del programa. " )
         ENDMENU
   ENDMENU
RETURN oMenu

/*_____________________________________________________________________________*/

METHOD BuildBtnBar() CLASS TApplication

   local oBtnTbl

   DEFINE BUTTONBAR ::oBar _3D SIZE 44, 46 OF ::oWndMain //36, 40

      ::oBar:bRClicked := { || .t. }

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      ACTION NIL   ;
      NOBORDER

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      ACTION NIL   ;
      NOBORDER

   DEFINE BUTTON ::oExit OF ::oBar  ;
      RESOURCE "BB2"      ;
      TOOLTIP i18n( "Salir del programa" ) ;
      MESSAGE i18n( "Finalizar el uso del programa." ) ;
      ACTION ( ::ExitFromBtn() ) ;
      GROUP NOBORDER

RETURN Self

/*_____________________________________________________________________________*/


METHOD Close() CLASS TApplication

   ResAllFree()

RETURN nil

/*_____________________________________________________________________________*/


METHOD ExitFromBtn() CLASS tApplication

   ::oWndMain:End()

RETURN nil

/*_____________________________________________________________________________*/

METHOD ExitFromX() CLASS tApplication

   if oApp:oDlg != nil
      if oApp:nEdit > 0
         msgStop( i18n("No puede salir del programa hasta que no cierre las ventanas abiertas sobre el mantenimiento que está manejando.") )
         RETURN .f.
      end

   end
   if msgYesNo( i18n("¿Desea finalizar el programa?") )
      if oApp:oDlg != nil
         oApp:oDlg:End()
      endif
    //  SetWinCoors( ::oWndMain, ::cIniFile )
      RETURN .t.
   end

RETURN .F.

/*_____________________________________________________________________________*/

METHOD ExitFromSource() CLASS tApplication

   ::oWndMain:bValid := { || FWMissingStrings()/*SetWinCoors( ::oWndMain, ::cIniFile )*/, .t. }
   ::oWndMain:End()

RETURN nil

FUNCTION oApp()
Return oApp
/*_____________________________________________________________________________*/


#pragma BEGINDUMP
#include "Windows.h"
#include "hbapi.h"

HB_FUNC( GETDEFAULTFONTNAME )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retc( lf.lfFaceName );
}

HB_FUNC( GETDEFAULTFONTHEIGHT )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retni( lf.lfHeight );
}


#pragma ENDDUMP

//_____________________________________________________________________________//

Function ResizeWndMain()

return NIL

  FUNCTION GoWeb( cUrl )

   cUrl := allTrim( cUrl )
   IF cURL == ""
      MsgStop("La dirección web está vacia.")
      RETURN NIL
   ENDIF

   IF ! IsWinNt()
      WinExec("start urlto:"+cURL,0)
   ELSE
      WinExec("rundll32.exe url.dll,FileProtocolHandler " + cURL)
   ENDIF

   RETURN nil

 



strings.prg

Code: Select all  Expand view
// FWH strings multiple languages support

#include "FiveWin.ch"

static nLanguage := 0   // Initially will be set by LanguageID() function
// 1 English, 2 Spanish, 3 French, 4 Portugese, 5 German, 6 Italian

static aStrings := {}
static aMissing := {}


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

function FWString( cString )

   local nAt

   if LanguageID() == 1
      return cString
   elseif ( nAt := AScan( aStrings, { | aString | Upper( aString[ 1 ] ) == Upper( cString ) } ) ) != 0
      return IfNil( aStrings[ nAt ][ LanguageID() ], cString )
   else
      if '&' $ cString
         cString  := StrTran( cString, '&', '' )
         if ( nAt := AScan( aStrings, { | aString | Upper( aString[ 1 ] ) == Upper( cString ) } ) ) != 0
            return '&' + IfNil( aStrings[ nAt ][ LanguageID() ], cString )
         endif
      endif
      MsgInfo( 'The string: "' + cString + '"' + CRLF + ;
               "defined from: " + ProcName( 1 ) + " line " + ;
               AllTrim( Str( ProcLine( 1 ) ) ) + " in " + ProcFile( 1 ) + CRLF + ;
               "is not defined in FWH strings" + CRLF + ;
               "Please add it to FWH\source\function\strings.prg" )
      AAdd( aMissing, cString )
   endif

return cString

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

function FWSetLanguage( nNewLanguage )

   local nOldLanguage := LanguageID()

   nLanguage = Max( 1, Min( nNewLanguage, Len( aStrings[ 1 ] ) ) )

return nOldLanguage

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

function FWAddLanguage( aLang, nLang )

   if ValType( aLang ) == 'A' .and. ! Empty( aLang )
      aStrings    := ArrTranspose( aStrings )
      if nLang == nil .or. nLang > Len( aStrings )
         AAdd( aStrings, aLang )
         nLang := Len( aStrings )
      else
         aStrings[ nLang ] := aLang
      endif
      aStrings    := ArrTranspose( aStrings )
      FWSetLanguage( nLang )
   endif

return nLang

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

function FWMissingStrings()

   local cResult := ""

   AEval( aMissing, { | cString | cResult += Space( 7 ) + '{ "' + cString + ;
                                  '", "" },;' + CRLF } )
   if ! Empty( cResult )
      MemoEdit( cResult, "Copy and paste in FWH\source\function\strings.prg" )
   endif

return cResult

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

function FWAddString( aString )

return AAdd( aStrings, aString )

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

static function LanguageID()

   if Empty( nLanguage )
      nLanguage   = Max( 1, AScan( { "EN", "ES", "FR", "PT", "DE", "IT" }, ;
                        Upper( Left( HB_LangSelect(), 2 ) ) ) )
   endif

return nLanguage

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


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

function LoadPreferences()

   local oIni

   if File( GetEnv( "APPDATA" ) + "\fivedbu.ini" )
      INI oIni FILE GetEnv( "APPDATA" ) + "\fivedbu.ini"
         GET cDefRdd SECTION "Default" ENTRY "RDD"    DEFAULT "DBFCDX" OF oIni
         GET lShared SECTION "Default" ENTRY "Shared" DEFAULT .T. OF oIni
         GET nLanguage SECTION "Default" ENTRY "Language" ;
            DEFAULT FWSetLanguage() OF oIni
         FWSetLanguage( nLanguage )
      ENDINI
   endif

return nil

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

function SavePreferences()

   local oIni

   DEFAULT nLanguage := FWSetLanguage()

   INI oIni FILE GetEnv( "APPDATA" ) + "\fivedbu.ini"
      SET SECTION "Default" ENTRY "RDD" OF oIni TO cDefRdd
      SET SECTION "Default" ENTRY "Shared" OF oIni TO lShared
      SET SECTION "Default" ENTRY "Language" OF oIni TO nLanguage
   ENDINI

return nil

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

 function FWLoadStrings( cFileName )

   local cLine:="", n := 1

   DEFAULT cFileName := cFilePath( GetModuleFileName( GetInstance() ) ) + ;
                        "fwstrings.ini"

   while ! Empty( cLine := GetIni(  cFileName, "LANG", AllTrim( Str( n++, 4 ) ) ) )
      AAdd( aStrings, { AllTrim( StrToken( cLine, 1, "|" ) ),;
                        AllTrim( StrToken( cLine, 2, "|" ) ),;
                        AllTrim( StrToken( cLine, 3, "|" ) ),;
                        AllTrim( StrToken( cLine, 4, "|" ) ),;
                        AllTrim( StrToken( cLine, 5, "|" ) ),;
                        AllTrim( StrToken( cLine, 6, "|" ) ) } )
   end
   
   return nil

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



 function Preferences()

   local oDlg

   DEFINE DIALOG oDlg TITLE FWString( "Preferences" ) SIZE 400, 300


   @ 4.6, 1.5 SAY FWString( "Language" ) OF oDlg

   DEFAULT nLanguage := FWSetLanguage()

   @ 6, 1.2 COMBOBOX nLanguage ;
      ITEMS { FWString( "English" ), FWString( "Spanish" ), FWString( "French" ),;
              FWString( "Portuguese" ), FWString( "German" ) , FWString( "Italian" ) } ;
      OF oDlg SIZE 180, 150 ;
      ON CHANGE ( FWSetLanguage( nLanguage ), oApp:oWndMain:SetMenu( oApp:BuildMenu() ),;
                  oApp:BuildBtnBar() )

   @ 7, 7 BUTTON FWString( "&Ok" ) OF oDlg SIZE 45, 13 ;
      ACTION (SavePreferences(), oDlg:End() )

   @ 7, 18 BUTTON FWString( "&Cancel" ) OF oDlg SIZE 45, 13 ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

   return nil

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

FUNCTION SetIni( cIni, cSection, cEntry, xVar )

   LOCAL oIni

   DEFAULT cIni := oApp:cIniFile

   INI oIni FILE cIni
      SET SECTION cSection ;
         ENTRY cEntry      ;
         TO xVar           ;
         OF oIni
   ENDINI

RETURN nil

/*_____________________________________________________________________________*/

FUNCTION GetIni( cIni, cSection, cEntry, xDefault )

   LOCAL oIni
   LOCAL xVar := xDefault

   DEFAULT cIni := oApp:cIniFile

   INI oIni FILE cIni
      GET xVar            ;
         SECTION cSection ;
         ENTRY cEntry     ;
         DEFAULT xDefault ;
         OF oIni
   ENDINI

RETURN xVar
//----------------------------------------------------------------------------//
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Antonio Linares » Wed Oct 09, 2013 8:52 pm

Silvio,

function Preferences() is missing from your code so we can not test it
regards, saludos

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

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 9:07 pm

No Prefernces() is on strings.prg and I modify also

New Method I insert then this line SET MESSAGE OF ::oWndMain TO ::cMsgBar CENTER NOINSET

::oWndMain:bInit := { || LoadPreferences() }

then I modify this function at strimgs.prg because give me error

SavePreferences()
LoadPreferences()

FWMissingStrings() it create the new string to put on ini file with "|||||"


Code: Select all  Expand view

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

function LoadPreferences()

    nLanguage := GetIni( oApp:cIniFile, "Default", "Language", )

    FWSetLanguage( nLanguage )

return nil

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

function SavePreferences()

   DEFAULT nLanguage := FWSetLanguage()

    SetIni( oApp:cIniFile, "Default", "Language", nLanguage )

return nil

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

function FWMissingStrings()

   local cResult := ""

   AEval( aMissing, { | cString | cResult += '=' + cString + ;
                                  '|||||' + CRLF } )
   if ! Empty( cResult )
      MemoEdit( cResult, "Copy and paste in your lang file" )
   endif

return cResult


 



Now with these modifies it seem run ok
I'm trying to test it

Only I wish create something to modify the string with xbrowse from my app
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Antonio: fwstring

Postby Silvio.Falconi » Wed Oct 09, 2013 9:19 pm

Now I have the error on button I not see & the line


Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests