-
Notifications
You must be signed in to change notification settings - Fork 1
/
sflocalize.vc2
224 lines (209 loc) · 7.47 KB
/
sflocalize.vc2
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (ES) AUTOGENERADO - ¡¡ATENCIÓN!! - ¡¡NO PENSADO PARA EJECUTAR!! USAR SOLAMENTE PARA INTEGRAR CAMBIOS Y ALMACENAR CON HERRAMIENTAS SCM!!
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.20" SourceFile="sflocalize.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS sflocalize AS custom
*< CLASSDATA: Baseclass="custom" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*m: cresourcesfolder_assign
*m: formatlocalizedstring && Returns the formatted localized string for the specified ID
*m: getadditionalresources && Gets additional resources from XML files
*m: getlanguages && Fills an array with supported languages
*m: getlocalizedstring && Returns the localized string for the specified ID
*m: openresourcetable && Opens the resource table
*p: calias && The alias used for the resource file
*p: clanguage && The language to use for localized resources
*p: cresourcesfolder && The folder for additional resource files
*p: cresourcetable && The name and path for the resource table
*p: _memberdata && XML Metadata for customizable properties
*</DefinedPropArrayMethod>
PROTECTED calias
*<PropValue>
calias =
clanguage = English
cresourcesfolder =
cresourcetable = Resources.dbf
Name = "sflocalize"
Width = 17
_memberdata = <VFPData>
<memberdata name="calias" type="property" display="cAlias"/>
<memberdata name="clanguage" type="property" display="cLanguage"/>
<memberdata name="cresourcesfolder" type="property" display="cResourcesFolder"/>
<memberdata name="cresourcesfolder_assign" type="method" display="cResourcesFolder_Assign"/>
<memberdata name="cresourcetable" type="property" display="cResourceTable"/>
<memberdata name="getadditionalresources" type="method" display="GetAdditionalResources"/>
<memberdata name="getlanguages" type="method" display="GetLanguages"/>
<memberdata name="getlocalizedstring" type="method" display="GetLocalizedString"/>
<memberdata name="openresourcetable" type="method" display="OpenResourceTable"/>
<memberdata name="formatlocalizedstring" display="FormatLocalizedString"/>
</VFPData>
*</PropValue>
PROCEDURE cresourcesfolder_assign
lparameters tcValue
This.cResourcesFolder = tcValue
This.GetAdditionalResources(tcValue)
ENDPROC
PROCEDURE formatlocalizedstring && Returns the formatted localized string for the specified ID
lparameters tcID, ;
tuParameter0, ;
tuParameter1, ;
tuParameter2, ;
tuParameter3, ;
tuParameter4
return Format(This.GetLocalizedString(tcID), tuParameter0, tuParameter1, ;
tuParameter2, tuParameter3, tuParameter4)
ENDPROC
PROCEDURE getadditionalresources && Gets additional resources from XML files
lparameters tcFolder
local lcFolder, ;
laFiles[1], ;
lnFiles, ;
lcAlias, ;
lnSelect, ;
lnSize, ;
lnI, ;
lcFile, ;
lcLanguage, ;
lcCursor, ;
lcResource, ;
lcValue, ;
loException
lcFolder = addbs(tcFolder)
if directory(lcFolder) and This.OpenResourceTable()
lnFiles = adir(laFiles, lcFolder + '*.xml')
lcAlias = This.cAlias
lnSelect = select()
lnSize = fsize('RESOURCE', lcAlias)
for lnI = 1 to lnFiles
lcFile = laFiles[lnI, 1]
lcLanguage = juststem(lcFile)
&& the file is named after the language e.g. french.xml
if type(lcAlias + '.' + lcLanguage) <> 'M'
select *, cast('' as M) as &lcLanguage ;
from (lcAlias) ;
into cursor (lcAlias) readwrite
index on upper(RESTYPE + RESOURCE) tag RESOURCE
endif type(lcAlias + '.' + lcLanguage) <> 'M'
try
lcCursor = sys(2015)
xmltocursor(lcFolder + lcFile, lcCursor, 512)
scan
lcResource = trim(KEY)
lcValue = trim(VALUE)
if seek('S' + padr(upper(lcResource), lnSize), lcAlias)
replace &lcLanguage with lcValue, ;
INACTIVE with .F. in (lcAlias)
else
insert into (lcAlias) ;
(RESTYPE, RESOURCE, ENGLISH, &lcLanguage) ;
values ('S', lcResource, lcResource, lcValue)
endif seek('S' ...
endscan
use
catch to loException
endtry
next lnI
select (lnSelect)
endif directory(lcFolder) ...
ENDPROC
PROCEDURE getlanguages && Fills an array with supported languages
lparameters taArray, ;
tlAllLanguages
local lnLanguages, ;
lnSelect, ;
laFields[1], ;
lnFields, ;
lnI, ;
lcField
lnLanguages = 0
if This.OpenResourceTable()
lnSelect = select()
select (This.cAlias)
lnFields = afields(laFields)
for lnI = 1 to lnFields
lcField = proper(laFields[lnI, 1])
if not inlist(lcField, 'Restype', 'Resource', 'Whereused', ;
'Inactive', 'Usedin', 'Modified', 'Notes')
locate for not empty(&lcField)
if found() or tlAllLanguages
lnLanguages = lnLanguages + 1
dimension taArray[lnLanguages]
taArray[lnLanguages] = lcField
endif found() ...
endif not inlist(lcField ...
next lnI
asort(taArray)
select (lnSelect)
endif This.OpenResourceTable()
return lnLanguages
ENDPROC
PROCEDURE getlocalizedstring && Returns the localized string for the specified ID
lparameters tcID, ;
tlStripHotkey, ;
tlSpaces
local lcReturn, ;
loException as Exception
with This
lcReturn = tcID
do case
case not .OpenResourceTable()
case seek('S' + padr(upper(tcID), fsize('RESOURCE', .cAlias)), ;
.cAlias, 'RESOURCE')
try
lcReturn = evaluate(.cAlias + '.' + .cLanguage)
catch to loException
lcReturn = ''
endtry
if empty(lcReturn)
lcReturn = evaluate(.cAlias + '.ENGLISH')
endif empty(lcReturn)
if '<<' $ lcReturn and '>>' $ lcReturn
lcReturn = textmerge(lcReturn)
endif '<<' $ lcReturn ...
if tlStripHotkey
lcReturn = strtran(lcReturn, '\<')
endif tlStripHotkey
if tlSpaces and left(lcReturn, 1) <> ' '
lcReturn = ' ' + lcReturn
endif tlSpaces ...
if tlSpaces and right(lcReturn, 1) <> ' '
lcReturn = lcReturn + ' '
endif tlSpaces ...
lcReturn = strtran(lcReturn, '\n', chr(10))
endcase
endwith
return lcReturn
ENDPROC
PROTECTED PROCEDURE openresourcetable && Opens the resource table
local llReturn, ;
lnSelect, ;
loException as Exception, ;
lcFolder
with This
lnSelect = select()
do case
case not empty(.cAlias) and used(.cAlias)
llReturn = .T.
case not empty(.cResourceTable) and file(.cResourceTable)
.cAlias = sys(2015)
try
select * from (.cResourceTable) into cursor (.cAlias) readwrite
index on upper(RESTYPE + RESOURCE) tag RESOURCE
catch to loException
endtry
use in select(juststem(.cResourceTable))
llReturn = used(.cAlias)
otherwise
.cAlias = sys(2015)
create cursor (.cAlias) (RESTYPE C(1), RESOURCE C(60), ENGLISH M)
index on upper(RESTYPE + RESOURCE) tag RESOURCE
llReturn = .T.
endcase
select (lnSelect)
endwith
return llReturn
ENDPROC
ENDDEFINE