/
po2lang.hb
129 lines (96 loc) · 3.25 KB
/
po2lang.hb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Converts .po files to core lang modules
*
* Copyright 2013 Viktor Szakats (vszakats.net/harbour)
* www - http://harbour-project.org
*
*/
#pragma -w3
#pragma -km+
#pragma -ko+
#include "hblang.ch"
PROCEDURE Main_po2lang()
POToLang( "hu.po", "l_hu.c", "hu" )
POToLang( "el.po", "l_el.c", "el" )
RETURN
STATIC FUNCTION POToLang( cFileIn, cFileOut, cLang )
LOCAL aTrans
LOCAL cErrorMsg
LOCAL cContent
LOCAL cTranslator
LOCAL nPos
IF ( aTrans := __i18n_potArrayLoad( cFileIn, @cErrorMsg ) ) != NIL
cContent := StrTran( _begin(), e"\n", hb_eol() )
nPos := 0
__i18n_potArrayClean( aTrans,,, {| cTrs, cOri | ProcessTrs( @cContent, cTrs, cOri, @cTranslator, @nPos, cLang ) } )
cContent := "/* Last Translator: " + MaskEMail( cTranslator ) + " */" + hb_eol() + ;
Left( cContent, Len( cContent ) - Len( "," ) - Len( hb_eol() ) ) + hb_eol() + ;
StrTran( StrTran( _end(), e"\n", hb_eol() ), "{LNG}", Upper( cLang ) )
hb_MemoWrit( cFileOut, cContent )
RETURN .T.
ENDIF
? "i18n error", cErrorMsg
RETURN .F.
STATIC FUNCTION MaskEMail( cEMail )
cEMail := StrTran( cEMail, "@", " " )
cEMail := StrTran( cEMail, "<", "(" )
cEMail := StrTran( cEMail, ">", ")" )
RETURN cEMail
STATIC FUNCTION ProcessTrs( /* @ */ cContent, cTrs, cOri, /* @ */ cTranslator, /* @ */ nPos, cLang )
STATIC sc_hEmpty := { ;
3 => { "", "UTF8", "" }, ;
47 => { "", "" }, ;
57 => { "" }, ;
64 => { "", "", "", "" }, ;
80 => { "", "", "" } }
LOCAL tmp
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 == "foo bar <foo.bar@foobaz>"
cTranslator := ""
ENDIF
cContent += Space( 6 ) + ConvToC( cLang ) + "," + hb_eol()
++nPos
ELSE
IF Len( cTrs ) == 0
cTrs := cOri
ENDIF
cContent += Space( 6 ) + ConvToC( cTrs ) + "," + hb_eol()
++nPos
IF nPos $ sc_hEmpty
FOR tmp := 1 TO Len( sc_hEmpty[ nPos ] )
cContent += Space( 6 ) + ConvToC( sc_hEmpty[ nPos ][ tmp ] ) + "," + hb_eol()
NEXT
nPos += Len( sc_hEmpty[ nPos ] )
ENDIF
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