/* * Xailer source code: * * i18n.prg * Soporte basico de i18n * * Copyright 2015 Jose F. Gimenez * Copyright 2015 Xailer.com * All rights reserved * */ #include "Xailer.ch" STATIC nLanguage := 1 STATIC aStrings, hStrings //------------------------------------------------------------------------------ FUNCTION i18n_Language( nLang ) LOCAL n := nLanguage IF PCount() > 0 nLanguage := nLang ENDIF RETURN n //------------------------------------------------------------------------------ FUNCTION i18n( cText ) LOCAL n IF nLanguage > 1 IF aStrings == Nil LoadStrings() ENDIF IF ( n := XA_SLSearch( hStrings, cText ) ) > 0 IF !Empty( aStrings[ n, nLanguage ] ) RETURN aStrings[ n, nLanguage ] ENDIF ENDIF ENDIF RETURN cText //------------------------------------------------------------------------------ STATIC PROCEDURE LoadStrings() LOCAL n, res, cData, cLine, cItem, aRow aStrings := {} IF !Empty( res := FindResource( 0, "i18n", RT_RCDATA ) ) cData := LoadResource( 0, res ) n := 2 WHILE !Empty( cLine := Trim( MemoLine( cData, 65536, n++ ) ) ) aRow := {} FOR EACH cItem IN hb_aTokens( cLine, ",", .T. ) AAdd( aRow, StrTran( Substr( cItem, 2, Len( cItem ) - 2 ), '""', '"' ) ) NEXT AAdd( aStrings, aRow ) ENDDO hStrings := XA_SLCreate( aStrings,,, 1 ) ENDIF RETURN //------------------------------------------------------------------------------ EXIT PROCEDURE i18n_Exit() IF !Empty( hStrings ) XA_SLFree( hStrings ) ENDIF RETURN //------------------------------------------------------------------------------