From 4f1db3a0b0b0b3a8630bedcb4f1d87665aa950dc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 31 Mar 2013 22:55:32 +0200 Subject: [PATCH] 2013-03-31 22:52 UTC+0200 Viktor Szakats (harbour syenar.net) * include/harbour.hbx * src/rtl/hbi18n2.prg + added __i18n_potArraySort( aTrans ) -> aTrans to sort .pot files to a predictable order (of first occurrence in file). It helps reducing unnecessarily large and unusable diffs when updating .pots and their related .po files * utils/hbmk2/hbmk2.prg * marked some string previously (and intentionally) marked as non-translatable, as translatable. One exception less. * utils/hbmk2/_po_push.hb + sort .pot before saving and pushing to localization service --- ChangeLog.txt | 16 ++++++++++++++++ include/harbour.hbx | 1 + src/rtl/hbi18n2.prg | 26 ++++++++++++++++++++++++-- utils/hbmk2/_po_push.hb | 20 +++++++++++++++++++- utils/hbmk2/hbmk2.prg | 18 ++++++++---------- 5 files changed, 68 insertions(+), 13 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6485a14aad..60dd9b7e2d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,22 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-03-31 22:52 UTC+0200 Viktor Szakats (harbour syenar.net) + * include/harbour.hbx + * src/rtl/hbi18n2.prg + + added __i18n_potArraySort( aTrans ) -> aTrans + to sort .pot files to a predictable order (of first + occurrence in file). It helps reducing unnecessarily + large and unusable diffs when updating .pots and their + related .po files + + * utils/hbmk2/hbmk2.prg + * marked some string previously (and intentionally) marked + as non-translatable, as translatable. One exception less. + + * utils/hbmk2/_po_push.hb + + sort .pot before saving and pushing to localization service + 2013-03-31 22:01 UTC+0200 Viktor Szakats (harbour syenar.net) * .gitignore * better rules to exclude lib subdir diff --git a/include/harbour.hbx b/include/harbour.hbx index 88341e9d38..551a0c16f6 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -1403,6 +1403,7 @@ DYNAMIC __i18n_hashTable DYNAMIC __i18n_potArrayJoin DYNAMIC __i18n_potArrayLoad DYNAMIC __i18n_potArraySave +DYNAMIC __i18n_potArraySort DYNAMIC __i18n_potArrayToHash DYNAMIC __i18n_potArrayTrans DYNAMIC __Input diff --git a/src/rtl/hbi18n2.prg b/src/rtl/hbi18n2.prg index 73d6d3a841..bc54bedcb2 100644 --- a/src/rtl/hbi18n2.prg +++ b/src/rtl/hbi18n2.prg @@ -292,7 +292,7 @@ FUNCTION __i18n_potArrayLoad( cFile, cErrorMsg ) RETURN aTrans -STATIC FUNCTION IsBOM_UTF8( cFileName ) +STATIC FUNCTION __i18n_IsBOM_UTF8( cFileName ) LOCAL fhnd := FOpen( cFileName, FO_READ ) LOCAL cBuffer @@ -310,6 +310,28 @@ STATIC FUNCTION IsBOM_UTF8( cFileName ) RETURN .F. +FUNCTION __i18n_potArraySort( aTrans ) + + ASort( aTrans,,, {| item1, item2 | __i18n_ItemToStr( item1 ) < __i18n_ItemToStr( item2 ) } ) + + RETURN aTrans + +STATIC FUNCTION __i18n_ItemToStr( item ) + + LOCAL cSource := item[ _I18N_SOURCE ] + LOCAL tmp + + /* first source occurrence */ + IF ( tmp := At( " ", cSource ) ) > 0 + cSource := Left( cSource, tmp - 1 ) + ENDIF + + IF ( tmp := RAt( ":", cSource ) ) > 0 + cSource := Left( cSource, tmp - 1 ) + Str( Val( SubStr( cSource, tmp + 1 ) ), 10, 0 ) + ENDIF + + RETURN cSource + Left( item[ _I18N_MSGID, 1 ], 30 ) + FUNCTION __i18n_potArraySave( cFile, aTrans, cErrorMsg, lVersionNo, lSourceRef ) LOCAL aItem @@ -324,7 +346,7 @@ FUNCTION __i18n_potArraySave( cFile, aTrans, cErrorMsg, lVersionNo, lSourceRef ) lRet := .F. cEol := hb_eol() cFlg := "#, c-format" + cEol - cPOT := iif( hb_FileExists( cFile ) .AND. IsBOM_UTF8( cFile ), _UTF8_BOM + cEol, "" ) + ; /* Put it in separate line to less confuse non-BOM aware parsers */ + cPOT := iif( hb_FileExists( cFile ) .AND. __i18n_IsBOM_UTF8( cFile ), _UTF8_BOM + cEol, "" ) + ; /* Put it in separate line to less confuse non-BOM aware parsers */ "#" + cEol + ; "# This file is generated by " + iif( lVersionNo, hb_Version(), "Harbour" ) + cEol + ; "#" + cEol diff --git a/utils/hbmk2/_po_push.hb b/utils/hbmk2/_po_push.hb index c874c9ca0c..0ef9f86118 100644 --- a/utils/hbmk2/_po_push.hb +++ b/utils/hbmk2/_po_push.hb @@ -31,10 +31,14 @@ PROCEDURE Main( cLogin ) FClose( hb_FTempCreateEx( @cTemp, , , ".pot" ) ) FClose( hb_FTempCreateEx( @cTemp2 ) ) - ? "generating pot" + ? "generating .pot" hb_run( hb_StrFormat( "hbmk2 -hbraw -q0 %1$s -j%2$s -s", cMain, cTemp ) ) + ? "sorting .pot" + + POT_Sort( cTemp ) + ? "saving locally" cContent := hb_StrFormat( ; @@ -78,3 +82,17 @@ STATIC FUNCTION GetJSON( cString ) cString := Left( cString, RAt( "}", cString ) ) RETURN cString + +STATIC FUNCTION POT_Sort( cFileName ) + + LOCAL aTrans + LOCAL cErrorMsg + + IF ( aTrans := __i18n_potArrayLoad( cFileName, @cErrorMsg ) ) != NIL .AND. ; + __i18n_potArraySave( cFileName, __i18n_potArraySort( aTrans ), @cErrorMsg ) + RETURN .T. + ENDIF + + ? cErrorMsg + + RETURN .F. diff --git a/utils/hbmk2/hbmk2.prg b/utils/hbmk2/hbmk2.prg index e8416f2f7e..d52d106f96 100644 --- a/utils/hbmk2/hbmk2.prg +++ b/utils/hbmk2/hbmk2.prg @@ -15896,21 +15896,19 @@ STATIC PROCEDURE ShowHelp( hbmk, lMore, lLong ) { "-longhelp" , I_( "long help" ) }, ; { "-longhelpmd" , I_( "long help in Markdown format" ) } } - /* Internal option descriptions intentionally not marked as translatable */ LOCAL aHdr_Opt_Internal := { ; "", ; - "Options below are internal/developer ones (compatibility not guaranteed):" } + I_( "Options below are internal/developer ones (compatibility not guaranteed):" ) } - /* Internal option descriptions intentionally not marked as translatable */ LOCAL aLst_Opt_Internal := { ; NIL, ; - { "-debugtime" , "measure time spent on the build" }, ; - { "-debuginc" , "display internals of incremental build" }, ; - { "-debugstub" , "display content of all internally generated source files" }, ; - { "-debugi18n" , "display internals on translation file generation" }, ; - { "-debugdepd" , "display internals of dependency detection" }, ; - { "-debugpars" , "display all input parameters in processing order" }, ; - { "-debugrte" , "generate a run-time error" } } + { "-debugtime" , I_( "measure time spent on the build" ) }, ; + { "-debuginc" , I_( "display internals of incremental build" ) }, ; + { "-debugstub" , I_( "display content of all internally generated source files" ) }, ; + { "-debugi18n" , I_( "display internals on translation file generation" ) }, ; + { "-debugdepd" , I_( "display internals of dependency detection" ) }, ; + { "-debugpars" , I_( "display all input parameters in processing order" ) }, ; + { "-debugrte" , I_( "generate a run-time error" ) } } LOCAL aHdr_Opt_Self := { ; NIL, ;