generalizing further

This commit is contained in:
Viktor Szakats
2013-03-31 16:34:28 +02:00
parent ab064dee76
commit 3e3a5a7ff7
4 changed files with 43 additions and 25 deletions

View File

@@ -10,6 +10,12 @@
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
*/
2013-03-31 16:34 UTC+0200 Viktor Szakats (harbour syenar.net)
* utils/hbmk2/_md_make.hb
* utils/hbmk2/_po_pull.hb
* utils/hbmk2/_po_push.hb
+ generalizing further
2013-03-31 15:15 UTC+0200 Viktor Szakats (harbour syenar.net)
* utils/hbmk2/_md_make.hb
* utils/hbmk2/_po_pull.hb

View File

@@ -20,38 +20,46 @@ PROCEDURE Main()
LOCAL cLang
LOCAL cTemp
LOCAL cMain := cBase + "hbmk2.prg"
LOCAL cMain := cBase + "hbmk2.prg" /* must be runnable as script */
LOCAL cDocOptions := "-lang={LANG} -longhelpmd"
LOCAL cBaseLang := "en"
LOCAL cPO_Dir := cBase + hb_DirSepToOS( "po/" )
LOCAL cDoc_Dir := cBase + hb_DirSepToOS( "doc/" )
? "preparing"
FOR EACH file IN Directory( cBase + hb_DirSepToOS( "po/*.po" ) )
FOR EACH file IN Directory( cPO_Dir + "*.po" )
hb_run( hb_StrFormat( "hbi18n -q -g -o%1$s %2$s", ;
cBase + hb_FNameName( file[ F_NAME ] ) + ".hbl", ;
cBase + hb_DirSepToOS( "po/" + file[ F_NAME ] ) ) )
hb_FNameDir( cMain ) + hb_FNameName( file[ F_NAME ] ) + ".hbl", ;
cPO_Dir + file[ F_NAME ] ) )
NEXT
cTemp := hb_FNameExtSet( cMain, ".hrb" )
hb_run( hb_StrFormat( "hbmk2 -hbraw -q0 -gh %1$s -o%2$s", cMain, cTemp ) )
hb_run( hb_StrFormat( "hbmk2 -hbraw -q0 %1$s -gh -o%2$s", cMain, cTemp ) )
? "generating .md help:"
FOR EACH cLang IN hb_ATokens( "en," + hb_regexAll( "-lng=([a-zA-Z0-9_,]*)", hb_MemoRead( hb_FNameExtSet( cMain, ".hbp" ) ),,,,, .T. )[ 1 ][ 2 ], "," )
FOR EACH cLang IN hb_ATokens( cBaseLang + "," + hb_regexAll( "-lng=([a-zA-Z0-9_\-,]*)", hb_MemoRead( hb_FNameExtSet( cMain, ".hbp" ) ),,,,, .T. )[ 1 ][ 2 ], "," )
?? "", cLang
file := cBase + hb_DirSepToOS( "doc/" + hb_FNameName( cMain ) + "." + cLang + ".md" )
hb_run( hb_StrFormat( "hbrun %1$s -lang=%2$s -longhelpmd > %3$s", cTemp, cLang, file ) )
file := cDoc_Dir + hb_FNameName( cMain ) + "." + cLang + ".md"
hb_run( hb_StrFormat( "hbrun %1$s %2$s > %3$s", cTemp, StrTran( cDocOptions, "{LANG}", cLang ), file ) )
FToNativeEOL( file )
file := cBase + hb_DirSepToOS( "../../contrib/hbrun/doc/" + "hbrun" + "." + cLang + ".md" )
hb_run( hb_StrFormat( "hbrun %1$s -lang=%2$s -longhelpmdsh > %3$s", cTemp, cLang, file ) )
FToNativeEOL( file )
/* special case */
IF hb_FNameName( cMain ) == "hbmk2"
file := cBase + hb_DirSepToOS( "../../contrib/hbrun/doc/" ) + "hbrun" + "." + cLang + ".md"
hb_run( hb_StrFormat( "hbrun %1$s -lang=%2$s -longhelpmdsh > %3$s", cTemp, cLang, file ) )
FToNativeEOL( file )
ENDIF
NEXT
FErase( cTemp )
AEval( Directory( cBase + "*.hbl" ), {| tmp | FErase( cBase + tmp[ F_NAME ] ) } )
AEval( Directory( hb_FNameDir( cMain ) + "*.hbl" ), ;
{| tmp | FErase( hb_FNameDir( cMain ) + tmp[ F_NAME ] ) } )
RETURN

View File

@@ -19,7 +19,9 @@ PROCEDURE Main( cLogin )
LOCAL cLang
LOCAL cTemp
LOCAL cProject := "harbour"
LOCAL cMain := cBase + "hbmk2.prg"
LOCAL cPO_Dir := cBase + hb_DirSepToOS( "po/" )
IF Empty( cLogin )
cLogin := GetEnv( "HB_TRANSIFEX_LOGIN" ) /* Format: username:password */
@@ -29,17 +31,17 @@ PROCEDURE Main( cLogin )
? "pulling .po files:"
FOR EACH cLang IN hb_ATokens( hb_regexAll( "-lng=([a-zA-Z0-9_,]*)", hb_MemoRead( hb_FNameExtSet( cMain, ".hbp" ) ),,,,, .T. )[ 1 ][ 2 ], "," )
FOR EACH cLang IN hb_ATokens( hb_regexAll( "-lng=([a-zA-Z0-9_\-,]*)", hb_MemoRead( hb_FNameExtSet( cMain, ".hbp" ) ),,,,, .T. )[ 1 ][ 2 ], "," )
?? "", cLang
hb_run( hb_StrFormat( "curl -s -i -L --user %1$s -X " + ;
"GET https://www.transifex.com/api/2/project/harbour/resource/%2$s/translation/%3$s/ " + ;
"-o %4$s", ;
cLogin, hb_FNameName( cMain ), cLang, cTemp ) )
"GET https://www.transifex.com/api/2/project/%2$s/resource/%3$s/translation/%4$s/ " + ;
"-o %5$s", ;
cLogin, cProject, hb_FNameName( cMain ), cLang, cTemp ) )
IF hb_jsonDecode( GetJSON( hb_MemoRead( cTemp ) ), @json ) > 0
hb_MemoWrit( hb_DirSepToOS( cBase + "po/" + hb_FNameName( cMain ) + "." + cLang + ".po" ), DoctorContent( json[ "content" ] ) )
hb_MemoWrit( cPO_Dir + hb_FNameName( cMain ) + "." + cLang + ".po", DoctorContent( json[ "content" ] ) )
ELSE
? "API error"
ENDIF
@@ -51,7 +53,7 @@ PROCEDURE Main( cLogin )
STATIC FUNCTION DoctorContent( cString )
cString := StrTran( cString, hb_UChar( 9166 ), "\n" ) /* convert RETURN SYMBOL used by Transifex for NEWLINE */
cString := StrTran( cString, hb_UChar( 0x23CE ), "\n" ) /* convert RETURN SYMBOL used by Transifex for NEWLINE */
cString := StrTran( cString, e"\n", hb_eol() )
RETURN cString

View File

@@ -19,7 +19,10 @@ PROCEDURE Main( cLogin )
LOCAL cTemp, cTemp2
LOCAL cContent
LOCAL cProject := "harbour"
LOCAL cMain := cBase + "hbmk2.prg"
LOCAL cBaseLang := "en"
LOCAL cPO_Dir := cBase + hb_DirSepToOS( "po/" )
IF Empty( cLogin )
cLogin := GetEnv( "HB_TRANSIFEX_LOGIN" ) /* Format: username:password */
@@ -39,25 +42,24 @@ PROCEDURE Main( cLogin )
'msgid ""' + hb_eol() + ;
'msgstr ""' + hb_eol() + ;
'"Project-Id-Version: %1$s\n"' + hb_eol() + ;
'"Language: en\n"' + hb_eol() + ;
'"Language: %2$s\n"' + hb_eol() + ;
'"MIME-Version: 1.0\n"' + hb_eol() + ;
'"Content-Type: text/plain; charset=UTF-8\n"' + hb_eol() + ;
'"Content-Transfer-Encoding: 8bit\n"', hb_FNameName( cMain ) ) + hb_eol() + ;
'"Content-Transfer-Encoding: 8bit\n"', hb_FNameName( cMain ), cBaseLang ) + hb_eol() + ;
hb_eol() + ;
hb_MemoRead( cTemp )
hb_MemoWrit( hb_DirSepToOS( cBase + "po/" + hb_FNameName( cMain ) + ".en.po" ), cContent )
hb_MemoWrit( cPO_Dir + hb_FNameName( cMain ) + "." + cBaseLang + ".po", cContent )
? "uploading", "size", Len( cContent )
?
hb_MemoWrit( cTemp, hb_jsonEncode( { "content" => StrTran( cContent, hb_eol(), e"\n" ) } ) )
hb_run( hb_StrFormat( 'curl -s -i -L --user %1$s -X ' + ;
'PUT -d @%2$s -H "Content-Type: application/json" ' + ;
'https://www.transifex.com/api/2/project/harbour/resource/%3$s/content/' + ;
' -o %4$s', ;
cLogin, cTemp, hb_FNameName( cMain ), cTemp2 ) )
'https://www.transifex.com/api/2/project/%3$s/resource/%4$s/content/' + ;
' -o %5$s', ;
cLogin, cTemp, cProject, hb_FNameName( cMain ), cTemp2 ) )
IF hb_jsonDecode( GetJSON( hb_MemoRead( cTemp2 ) ), @json ) > 0
? hb_ValToExp( json )