21746
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
21273
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2001 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
6117
|
14 |
"{ Package: 'stx:libbasic' }"
|
5996
|
15 |
|
17538
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
5996
|
18 |
Object subclass:#UserMessage
|
|
19 |
instanceVariableNames:'defaultString key catalogID'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Interface-Internationalization'
|
|
23 |
!
|
|
24 |
|
6008
|
25 |
!UserMessage class methodsFor:'documentation'!
|
|
26 |
|
21273
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2001 by eXept Software AG
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
6008
|
41 |
documentation
|
|
42 |
"
|
|
43 |
added for vw5i compatibility, which accesses messageCatalogs
|
|
44 |
via:
|
|
45 |
(#key << #catalogID >> 'defaultMessage')
|
|
46 |
which creates an instance of UserMessage.
|
|
47 |
|
|
48 |
Currently, this is a dummy operation in ST/X, however it is mapped onto
|
|
49 |
the resource mechanism, if the given catalogID is the name of a class;
|
|
50 |
i.e.
|
|
51 |
(YesNoBox classResources string:'continue')
|
13364
|
52 |
|
6008
|
53 |
can now also be written as:
|
13364
|
54 |
|
|
55 |
(#continue << YesNoBox) asString
|
|
56 |
(#continue << #YesNoBox >> 'Continue really') asString
|
|
57 |
"
|
|
58 |
!
|
|
59 |
|
|
60 |
examples
|
|
61 |
"
|
|
62 |
Use a class as catalog:
|
|
63 |
[exBegin]
|
|
64 |
self warn:(#continue << YesNoBox) asString
|
|
65 |
[exEnd]
|
|
66 |
Use a class name as catalog:
|
|
67 |
[exBegin]
|
|
68 |
self warn:(#continue << #YesNoBox) asString
|
|
69 |
[exEnd]
|
|
70 |
Some default text if the symbol is not present in the catalog:
|
|
71 |
[exBegin]
|
|
72 |
self warn:(#continue << #YesNoBox >> 'Default for continue') asString.
|
|
73 |
self warn:(#continueRRRRRRR << #YesNoBox >> 'Default for continue') asString
|
|
74 |
[exEnd]
|
|
75 |
Here we inherit from the top catalog:
|
|
76 |
[exBegin]
|
|
77 |
self information:(Time now printStringFormat:(#TIMEFORMAT << self >> 'Resolved via default %h:%m:%s') asString)
|
|
78 |
[exEnd]
|
|
79 |
|
|
80 |
Can also use a package's catalog:
|
|
81 |
[exBegin]
|
|
82 |
self information:((#'WARN_RENAME' << #'stx:libtool' )
|
|
83 |
withCRs bindWith:'ARG1' with:'ARG2')
|
|
84 |
[exEnd]
|
|
85 |
|
|
86 |
Lazy resolving the catalog in a block
|
|
87 |
(if you generate the messages at startup and want to recognize language changes):
|
|
88 |
[exBegin]
|
|
89 |
self information:((#'WARN_RENAME' << [ Tools::NewSystemBrowser classResources ] )
|
|
90 |
withCRs bindWith:'ARG1' with:'ARG2')
|
|
91 |
[exEnd]
|
6008
|
92 |
"
|
|
93 |
! !
|
5996
|
94 |
|
|
95 |
!UserMessage class methodsFor:'instance creation'!
|
|
96 |
|
|
97 |
key:aKeySymbol catalogID:aCatalogSymbol
|
|
98 |
^ self new key:aKeySymbol catalogID:aCatalogSymbol
|
|
99 |
!
|
|
100 |
|
|
101 |
key:aKeySymbol defaultString:aString
|
|
102 |
^ self new key:aKeySymbol defaultString:aString
|
|
103 |
! !
|
|
104 |
|
13364
|
105 |
!UserMessage methodsFor:'Compatibility-V''Age'!
|
|
106 |
|
|
107 |
bindWith:aString
|
|
108 |
"return a copy of the receiver, where a '%1' escape is
|
|
109 |
replaced by aString.
|
|
110 |
This has been added for VisualAge compatibility."
|
|
111 |
|
|
112 |
^ self expandPlaceholdersWith:(Array with:aString)
|
|
113 |
|
|
114 |
"
|
|
115 |
'do you like %1 ?' bindWith:'smalltalk'
|
|
116 |
"
|
|
117 |
!
|
|
118 |
|
|
119 |
bindWith:string1 with:string2
|
|
120 |
"return a copy of the receiver, where a '%1' escape is
|
|
121 |
replaced by string1 and '%2' is replaced by string2.
|
|
122 |
This has been added for VisualAge compatibility."
|
|
123 |
|
|
124 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2)
|
|
125 |
|
|
126 |
"
|
|
127 |
'do you prefer %1 or rather %2 ?'
|
|
128 |
bindWith:'smalltalk' with:'c++'
|
|
129 |
"
|
|
130 |
!
|
|
131 |
|
|
132 |
bindWith:str1 with:str2 with:str3
|
|
133 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes
|
|
134 |
are replaced by str1, str2 and str3 respectively.
|
|
135 |
This has been added for VisualAge compatibility."
|
|
136 |
|
|
137 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3)
|
|
138 |
|
|
139 |
"
|
|
140 |
'do you prefer %1 or rather %2 (not talking about %3) ?'
|
|
141 |
bindWith:'smalltalk' with:'c++' with:'c'
|
|
142 |
"
|
|
143 |
!
|
|
144 |
|
|
145 |
bindWith:str1 with:str2 with:str3 with:str4
|
|
146 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes
|
|
147 |
are replaced by str1, str2, str3 and str4 respectively.
|
|
148 |
This has been added for VisualAge compatibility."
|
|
149 |
|
|
150 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4)
|
|
151 |
|
|
152 |
"
|
|
153 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?'
|
|
154 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler'
|
|
155 |
"
|
|
156 |
!
|
|
157 |
|
|
158 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5
|
|
159 |
"return a copy of the receiver, where a '%1' .. '%5' escapes
|
|
160 |
are replaced by str1 .. str5 respectively.
|
|
161 |
This has been added for VisualAge compatibility."
|
|
162 |
|
|
163 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5)
|
|
164 |
|
|
165 |
"Created: 31.1.1997 / 16:25:42 / cg"
|
|
166 |
!
|
|
167 |
|
|
168 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6
|
|
169 |
"return a copy of the receiver, where a '%1' .. '%6' escapes
|
|
170 |
are replaced by str1 .. str6 respectively.
|
|
171 |
This has been added for VisualAge compatibility."
|
|
172 |
|
|
173 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2
|
|
174 |
with:str3 with:str4
|
|
175 |
with:str5 with:str6)
|
|
176 |
!
|
|
177 |
|
|
178 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7
|
|
179 |
"return a copy of the receiver, where a '%1' .. '%7' escapes
|
|
180 |
are replaced by str1 .. str7 respectively.
|
|
181 |
This has been added for VisualAge compatibility."
|
|
182 |
|
|
183 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2
|
|
184 |
with:str3 with:str4
|
|
185 |
with:str5 with:str6
|
|
186 |
with:str7)
|
|
187 |
!
|
|
188 |
|
22923
|
189 |
bindWithArguments:argumentsCollection
|
13364
|
190 |
"return a copy of the receiver, where a '%i' escape
|
21746
|
191 |
is replaced by the corresponding string from the argument array.
|
22923
|
192 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed),
|
|
193 |
or %(key); the argumentsCollection must then be a dictionary.
|
21254
|
194 |
To get an integer-indexed placeHolder followed by another digit,
|
|
195 |
or an index > 9, you must use %(digit).
|
13364
|
196 |
This has been added for VisualAge compatibility."
|
|
197 |
|
22923
|
198 |
^ self expandPlaceholdersWith:argumentsCollection
|
13364
|
199 |
|
|
200 |
"
|
|
201 |
'do you prefer %1 or rather %2 (not talking about %3) ?'
|
|
202 |
bindWithArguments:#('smalltalk' 'c++' 'c')
|
|
203 |
|
|
204 |
'do you %(what) ?'
|
|
205 |
bindWithArguments:(Dictionary new at:#'what' put:'understand'; yourself)
|
|
206 |
"
|
21746
|
207 |
|
|
208 |
"Modified (comment): / 11-05-2017 / 12:42:01 / mawalch"
|
13364
|
209 |
! !
|
|
210 |
|
5996
|
211 |
!UserMessage methodsFor:'accessing'!
|
|
212 |
|
|
213 |
catalogID
|
|
214 |
^ catalogID
|
|
215 |
!
|
|
216 |
|
|
217 |
catalogID:aCatalogSymbol
|
|
218 |
catalogID := aCatalogSymbol
|
|
219 |
!
|
|
220 |
|
|
221 |
defaultString
|
|
222 |
^ defaultString
|
|
223 |
!
|
|
224 |
|
|
225 |
defaultString:aString
|
|
226 |
defaultString := aString
|
|
227 |
!
|
|
228 |
|
|
229 |
key
|
|
230 |
^ key
|
|
231 |
!
|
|
232 |
|
|
233 |
key:aKeySymbol
|
|
234 |
key := aKeySymbol.
|
|
235 |
!
|
|
236 |
|
|
237 |
key:aKeySymbol catalogID:aCatalogSymbol
|
|
238 |
key := aKeySymbol.
|
|
239 |
catalogID := aCatalogSymbol
|
|
240 |
!
|
|
241 |
|
|
242 |
key:aKeySymbol defaultString:aString
|
|
243 |
key := aKeySymbol.
|
|
244 |
defaultString := aString
|
|
245 |
! !
|
|
246 |
|
|
247 |
!UserMessage methodsFor:'converting'!
|
|
248 |
|
|
249 |
asString
|
13364
|
250 |
"convert the user message to a string.
|
|
251 |
If there us no mapping for the user message -
|
|
252 |
for now: return the defaultString, ignoring the catalogID."
|
5996
|
253 |
|
|
254 |
|str|
|
|
255 |
|
|
256 |
str := self lookupInMessageCatalog.
|
|
257 |
str notNil ifTrue:[ ^ str ].
|
|
258 |
defaultString notNil ifTrue:[
|
|
259 |
^ defaultString
|
|
260 |
].
|
|
261 |
^ key asString
|
6117
|
262 |
!
|
|
263 |
|
13364
|
264 |
string
|
|
265 |
^ self asString
|
|
266 |
! !
|
|
267 |
|
|
268 |
!UserMessage methodsFor:'printing & storing'!
|
|
269 |
|
|
270 |
displayOn:aStream
|
17538
|
271 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
|
21545
|
272 |
"/ old ST80 means: draw-yourself on a GC.
|
16748
|
273 |
(aStream isStream) ifFalse:[
|
13364
|
274 |
self asString displayOn:aStream.
|
|
275 |
^ self
|
|
276 |
].
|
|
277 |
|
|
278 |
key storeOn:aStream.
|
|
279 |
aStream nextPutAll:' << '.
|
|
280 |
catalogID storeOn:aStream.
|
|
281 |
defaultString notNil ifTrue:[
|
|
282 |
aStream nextPutAll:' >> '.
|
|
283 |
defaultString storeOn:aStream.
|
|
284 |
].
|
21545
|
285 |
|
|
286 |
"Modified (comment): / 22-02-2017 / 16:48:03 / cg"
|
13364
|
287 |
!
|
|
288 |
|
|
289 |
printOn:aStream
|
|
290 |
aStream nextPutAll:self asString
|
|
291 |
! !
|
|
292 |
|
|
293 |
!UserMessage methodsFor:'special string converting'!
|
|
294 |
|
6117
|
295 |
expandMacros
|
|
296 |
^ self asString expandMacros
|
|
297 |
|
|
298 |
!
|
|
299 |
|
|
300 |
expandMacrosWith:arg1
|
|
301 |
^ self asString expandMacrosWith:arg1
|
|
302 |
|
12092
|
303 |
!
|
|
304 |
|
13364
|
305 |
expandPlaceholdersWith:argArrayOrDictionary
|
|
306 |
^ self asString expandPlaceholdersWith:argArrayOrDictionary
|
|
307 |
!
|
6591
|
308 |
|
13364
|
309 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream
|
|
310 |
^ self asString expandPlaceholdersWith:argArrayOrDictionary on:aStream
|
|
311 |
!
|
6591
|
312 |
|
13364
|
313 |
withCRs
|
|
314 |
^ self asString withCRs
|
6591
|
315 |
! !
|
|
316 |
|
5996
|
317 |
!UserMessage methodsFor:'utilities'!
|
|
318 |
|
|
319 |
<< aSymbol
|
|
320 |
"set the catalogID"
|
|
321 |
|
|
322 |
self catalogID:aSymbol
|
|
323 |
!
|
|
324 |
|
|
325 |
>> aString
|
|
326 |
"set the default string"
|
|
327 |
|
|
328 |
self defaultString:aString
|
|
329 |
|
|
330 |
"
|
|
331 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass')
|
|
332 |
"
|
|
333 |
!
|
|
334 |
|
|
335 |
lookupInMessageCatalog
|
13364
|
336 |
|messageCatalog resolvedMessageCatalog|
|
5996
|
337 |
|
13364
|
338 |
"catalogID may be a block"
|
|
339 |
messageCatalog := resolvedMessageCatalog :=catalogID value.
|
5996
|
340 |
|
13364
|
341 |
"for now - handle the case that the catalogID is
|
|
342 |
a classes name; in that case, ask its resourcePack."
|
|
343 |
messageCatalog isSymbol ifTrue:[
|
|
344 |
resolvedMessageCatalog := Smalltalk at:messageCatalog.
|
|
345 |
resolvedMessageCatalog isNil ifTrue:[
|
|
346 |
"no class, so it is a packageID"
|
|
347 |
resolvedMessageCatalog := ResourcePack forPackage:messageCatalog cached:true.
|
|
348 |
].
|
6887
|
349 |
].
|
13364
|
350 |
resolvedMessageCatalog isBehavior ifTrue:[
|
|
351 |
resolvedMessageCatalog := resolvedMessageCatalog classResources.
|
5996
|
352 |
].
|
13364
|
353 |
(resolvedMessageCatalog isNil) ifTrue:[
|
6887
|
354 |
defaultString isNil ifTrue:[
|
18683
|
355 |
^ 'Non-existent message: (%1<<%2)' bindWith:key with:catalogID printString.
|
6887
|
356 |
].
|
|
357 |
^ defaultString.
|
|
358 |
].
|
|
359 |
|
13364
|
360 |
^ resolvedMessageCatalog at:key ifAbsent:nil.
|
5996
|
361 |
|
|
362 |
"
|
13364
|
363 |
(#'WARN_RENAME' << #BrowserView >> 'A class named %1 already exists (in ''%2'')\\that class will no longer be visible (i.e. removed) if you continue.\\Continue ?' ) asString
|
|
364 |
(#'WARN_RENAME' << #BrowserView) asString
|
|
365 |
(#'WARN_RENAME' << BrowserView classResources) asString
|
|
366 |
(#'WARN_RENAME' << [ BrowserView classResources] ) asString
|
|
367 |
(#'WARN_RENAME' << #'stx:libtool' ) asString
|
6887
|
368 |
(#dontKnow << #nonExistantMessageCatalog) asString
|
13364
|
369 |
(#dontKnow << [YesNoBox]) asString
|
|
370 |
(#dontKnow << #nonExistantMessageCatalog >> 'Default text') asString
|
5996
|
371 |
"
|
|
372 |
! !
|
|
373 |
|
|
374 |
!UserMessage class methodsFor:'documentation'!
|
|
375 |
|
|
376 |
version
|
18683
|
377 |
^ '$Header$'
|
12092
|
378 |
!
|
|
379 |
|
|
380 |
version_CVS
|
18683
|
381 |
^ '$Header$'
|
5996
|
382 |
! !
|
16748
|
383 |
|