2013-04-02 02:43 UTC+0200 Viktor Szakats (harbour syenar.net)

* src/rtl/hbi18n2.prg
    ! __i18n_potArrayClean() to evaluate transformation
      codeblock in normal order (was reverse)

  * tests/lang2po.hb
    + made all necessary modification to allow two-way conversion

  + tests/po2lang.hb
    + added script that converts a core .po back to a lang module

  * src/rtl/strc.c
    * casing in comments

  * config/lang.hb
    + added std script options
This commit is contained in:
Viktor Szakats
2013-04-02 02:51:04 +02:00
parent f29b373946
commit 783f45656d
6 changed files with 148 additions and 18 deletions

View File

@@ -10,6 +10,23 @@
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
*/
2013-04-02 02:43 UTC+0200 Viktor Szakats (harbour syenar.net)
* src/rtl/hbi18n2.prg
! __i18n_potArrayClean() to evaluate transformation
codeblock in normal order (was reverse)
* tests/lang2po.hb
+ made all necessary modification to allow two-way conversion
+ tests/po2lang.hb
+ added script that converts a core .po back to a lang module
* src/rtl/strc.c
* casing in comments
* config/lang.hb
+ added std script options
2013-04-02 00:06 UTC+0200 Viktor Szakats (harbour syenar.net)
- contrib/hbrun/doc/hbrun.md
- utils/hbmk2/doc/hbmk2.md

View File

@@ -31,6 +31,8 @@
*/
#pragma -w3
#pragma -km+
#pragma -ko+
#include "directry.ch"

View File

@@ -344,8 +344,7 @@ FUNCTION __i18n_potArrayClean( aTrans, lKeepSource, lKeepVoidTranslations, bTran
hb_default( @lKeepSource, .T. )
hb_default( @lKeepVoidTranslations, .T. )
FOR EACH item IN aTrans DESCEND
FOR EACH item IN aTrans
IF HB_ISEVALITEM( bTransformTranslation )
FOR EACH cString IN item[ _I18N_MSGSTR ]
tmp := Eval( bTransformTranslation, cString, item[ _I18N_MSGID, cString:__enumIndex() ] )
@@ -354,8 +353,13 @@ FUNCTION __i18n_potArrayClean( aTrans, lKeepSource, lKeepVoidTranslations, bTran
ENDIF
NEXT
ENDIF
IF ! lKeepSource
item[ _I18N_SOURCE ] := ""
ENDIF
NEXT
IF ! lKeepVoidTranslations
IF ! lKeepVoidTranslations
FOR EACH item IN aTrans DESCEND
lVoid := .T.
FOR EACH cString IN item[ _I18N_MSGSTR ]
IF ! Empty( cString ) .AND. !( cString == item[ _I18N_MSGID, cString:__enumIndex() ] )
@@ -367,12 +371,8 @@ FUNCTION __i18n_potArrayClean( aTrans, lKeepSource, lKeepVoidTranslations, bTran
hb_ADel( aTrans, item:__enumIndex(), .T. )
LOOP
ENDIF
ENDIF
IF ! lKeepSource
item[ _I18N_SOURCE ] := ""
ENDIF
NEXT
NEXT
ENDIF
RETURN aTrans

View File

@@ -51,7 +51,7 @@
#include "hbapiitm.h"
#include "hbapierr.h"
/* HB_STRDECODESCAPE( <cEscSeqStr> ) -> <cStr>
/* hb_StrDecodEscape( <cEscSeqStr> ) -> <cStr>
* decode string with \ escape sequences
*/
HB_FUNC( HB_STRDECODESCAPE )
@@ -75,7 +75,7 @@ HB_FUNC( HB_STRDECODESCAPE )
hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* HB_STRCDECODE( <cStr> [, @<lCont> ] ) -> <cResult> | NIL
/* hb_StrCDecode( <cStr> [, @<lCont> ] ) -> <cResult> | NIL
* decode string using C compiler rules
* if second parameter <lCont> is passed by reference then it allows
* to decode multiline strings. In such case <lCont> is set to .T.

View File

@@ -28,13 +28,11 @@ PROCEDURE Main()
cName := SubStr( cName, Len( "HB_LANG_" ) + 1 )
IF Len( cName ) != 5 .AND. ;
! "|" + cName + "|" $ "|RUKOI8|UAKOI8|ZHB5|ZHGB|"
cPO := Item( "", Meta() )
cPO := Item( "", Meta( cName ) )
/* TODO: do something with the metadata (position 0 to 5) */
FOR tmp1 := HB_LANG_ITEM_BASE_MONTH TO HB_LANG_ITEM_MAX_ - 1
IF ! Empty( hb_langMessage( tmp1, "en" ) )
cPO += Item( hb_langMessage( tmp1, "en" ), ;
iif( hb_langMessage( tmp1, "en" ) == hb_langMessage( tmp1, cName ), "", hb_langMessage( tmp1, cName ) ) )
ENDIF
cPO += Item( hb_langMessage( tmp1, "en" ), ;
iif( hb_langMessage( tmp1, "en" ) == hb_langMessage( tmp1, cName ), "", hb_langMessage( tmp1, cName ) ) )
NEXT
hb_MemoWrit( Lower( hb_FNameName( cName ) ) + ".po", hb_StrShrink( cPO, Len( hb_eol() ) ) )
ENDIF
@@ -43,7 +41,7 @@ PROCEDURE Main()
RETURN
STATIC FUNCTION Meta()
STATIC FUNCTION Meta( cName )
LOCAL cISO_TimeStamp := ISO_TimeStamp()
@@ -51,6 +49,7 @@ STATIC FUNCTION Meta()
LOCAL cMeta
LOCAL meta
LOCAL tmp
/* NOTE: workaround for Harbour not retaining definition order of hash literals */
hMeta := { => }
@@ -60,11 +59,15 @@ STATIC FUNCTION Meta()
hMeta[ "POT-Creation-Date:" ] := cISO_TimeStamp
hMeta[ "PO-Revision-Date:" ] := cISO_TimeStamp
hMeta[ "Last-Translator:" ] := "a b <a.b@c.d>"
hMeta[ "Language-Team:" ] := "a b <a.b@c.d>"
hMeta[ "Language-Team:" ] := "https://www.transifex.com/projects/p/harbour/"
hMeta[ "MIME-Version:" ] := "1.0"
hMeta[ "Content-Type:" ] := "text/plain; charset=UTF-8"
hMeta[ "Content-Transfer-Encoding:" ] := "8bit"
FOR tmp := 0 TO 5
hMeta[ hb_StrFormat( "Harbour-Meta-%1$d:", tmp ) ] := hb_langMessage( tmp, cName )
NEXT
cMeta := '"' + e"\n"
FOR EACH meta IN hMeta
cMeta += ;

108
tests/po2lang.hb Normal file
View File

@@ -0,0 +1,108 @@
#pragma -w3
#pragma -km+
#pragma -ko+
#include "hblang.ch"
PROCEDURE Main()
LOCAL cFileIn := "hu.po"
LOCAL cFileOut := "l_hu.c"
PO_2_C( cFileIn, cFileOut )
RETURN
STATIC FUNCTION PO_2_C( cFileIn, cFileOut, ... )
LOCAL aTrans
LOCAL cErrorMsg
LOCAL cContent
LOCAL cTranslator
LOCAL cID
LOCAL nPos
IF ( aTrans := __i18n_potArrayLoad( cFileIn, @cErrorMsg ) ) != NIL
cContent := _begin()
nPos := 0
__i18n_potArrayClean( aTrans,,, {| cTrs, cOri | ProcessTrs( @cContent, cTrs, cOri, @cTranslator, @cID, @nPos ) } )
cContent := "/* Last Translator: " + cTranslator + " */" + hb_eol() + ;
Left( cContent, Len( cContent ) - Len( "," ) - Len( hb_eol() ) ) + hb_eol() + ;
StrTran( _end(), "{LNG}", Upper( cID ) )
hb_MemoWrit( cFileOut, cContent )
RETURN .T.
ENDIF
? "i18n error", cErrorMsg
RETURN .F.
STATIC FUNCTION ProcessTrs( /* @ */ cContent, cTrs, cOri, /* @ */ cTranslator, /* @ */ cID, /* @ */ nPos )
LOCAL tmp, tmp1
SWITCH nPos
CASE HB_LANG_ITEM_BASE_ID ; tmp := "/* Identification */" ; EXIT
CASE HB_LANG_ITEM_BASE_MONTH ; tmp := "/* Month names */" ; EXIT
CASE HB_LANG_ITEM_BASE_DAY ; tmp := "/* Day names */" ; EXIT
CASE HB_LANG_ITEM_BASE_NATMSG ; tmp := "/* CA-Cl*pper compatible natmsg items */" ; EXIT
CASE HB_LANG_ITEM_BASE_ERRDESC ; tmp := "/* Error description names */" ; EXIT
CASE HB_LANG_ITEM_BASE_ERRINTR ; tmp := "/* Internal error names */" ; EXIT
CASE HB_LANG_ITEM_BASE_TEXT ; tmp := "/* Texts */" ; EXIT
OTHERWISE ; tmp := NIL
ENDSWITCH
IF tmp != NIL
cContent += iif( nPos > 0, hb_eol(), "" ) + Space( 6 ) + tmp + hb_eol() + hb_eol()
ENDIF
IF nPos == 0
cTranslator := hb_regexAll( "Last-Translator: ([^\n]*)", cTrs,,,,, .T. )[ 1 ][ 2 ]
IF cTranslator == "a b <a.b@c.d>"
cTranslator := ""
ENDIF
FOR tmp := 0 TO 5
cContent += Space( 6 ) + ConvToC( tmp1 := hb_regexAll( hb_StrFormat( "Harbour-Meta-%1$d: ([\S]*)", tmp ), cTrs,,,,, .T. )[ 1 ][ 2 ] ) + "," + hb_eol()
++nPos
IF tmp == 0
cID := tmp1
ENDIF
NEXT
ELSE
IF Len( cTrs ) == 0
cTrs := cOri
ENDIF
cContent += Space( 6 ) + ConvToC( cTrs ) + "," + hb_eol()
++nPos
ENDIF
RETURN NIL
STATIC FUNCTION ConvToC( cStr )
RETURN '"' + hb_StrReplace( cStr, { '"' => '\"' } ) + '"'
STATIC FUNCTION _begin()
#pragma __cstream | RETURN %s
#include "hbapilng.h"
static HB_LANG s_lang =
{
{
#pragma __endtext
STATIC FUNCTION _end()
#pragma __cstream | RETURN %s
}
};
#define HB_LANG_ID {LNG}
#include "hbmsgreg.h"
#pragma __endtext