author | Claus Gittinger <cg@exept.de> |
Fri, 12 Oct 2018 11:36:38 +0200 | |
changeset 8498 | 58020bf9e736 |
parent 8496 | 8f3546dc85d4 |
child 8509 | a3314a51aaaf |
permissions | -rw-r--r-- |
8445 | 1 |
"{ Encoding: utf8 }" |
2 |
||
5 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
8462 | 5 |
All Rights Reserved |
5 | 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 |
" |
|
3263 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6767 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Dictionary subclass:#ResourcePack |
8470 | 19 |
instanceVariableNames:'packsClassName packsFileName fileReadFailed superPack projectPack |
20 |
usedKeys cache' |
|
21 |
classVariableNames:'Packs FailedToLoadPacks DebugModifications |
|
22 |
KeepStatisticsOnUsedKeys' |
|
23 |
poolDictionaries:'' |
|
24 |
category:'Interface-Internationalization' |
|
0 | 25 |
! |
26 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
27 |
!ResourcePack class methodsFor:'documentation'! |
46 | 28 |
|
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
8462 | 32 |
All Rights Reserved |
5 | 33 |
|
46 | 34 |
This software is furnished under a license and may be used |
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
5 | 42 |
|
46 | 43 |
documentation |
44 |
" |
|
1942 | 45 |
This class supports easy customization of smalltalk code (i.e. internationalization |
46 |
and viewStyle adaption). |
|
145 | 47 |
ResourcePacks are class specific, meaning that every subclass of View |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
48 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
1942 | 49 |
which is created when the first instance of the view/app is created, |
50 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 51 |
|
50 | 52 |
The resourcePack consists of a mapping from strings to values, which are |
53 |
then used in labels, buttons, menus etc. |
|
54 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
55 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 56 |
|
50 | 57 |
Conditional mappings are possible, by including lines as: |
7649 | 58 |
#if <expression> |
59 |
#endif |
|
50 | 60 |
in the resourcefile. Example: |
61 |
file 'foo.rs': |
|
7649 | 62 |
#if Language == #de |
63 |
'abort' 'Abbruch' |
|
64 |
#endif |
|
65 |
#if Language == #fr |
|
66 |
'abort' 'canceller' |
|
67 |
#endif |
|
145 | 68 |
|
69 |
the corresponding resource-strings are accessed (from methods within the class) |
|
70 |
using: |
|
7649 | 71 |
resources string:'abort' |
145 | 72 |
|
54 | 73 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 74 |
to #de).. |
145 | 75 |
|
1942 | 76 |
If no corresponding entry is found in the resources, the key is returned; |
77 |
alternatively, use: |
|
7649 | 78 |
resources string:'foo' default:'bar' |
1942 | 79 |
which returns 'bar', if no resource definition for 'foo' is found. |
80 |
||
54 | 81 |
Translations can also include arguments, such as: |
7649 | 82 |
resources string:'really delete %1' with:fileName |
145 | 83 |
|
84 |
This scheme has the advantage, that you can write your programs using your |
|
85 |
native language strings. Later, when new languages are to be supported, |
|
86 |
simply create a resource file for the class and add translations for |
|
87 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 88 |
of 'string:*'). |
89 |
Notice, that the grammar of different languages may imply a reordering, |
|
8445 | 90 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
1942 | 91 |
so using percent-placeholders is much better than simple concatenations of |
92 |
arguments to the question. |
|
145 | 93 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
94 |
More languages can be added later without any change in the code, or recompilation |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
95 |
or the like. Even by people without access to the source code (i.e. which only have the |
8428 | 96 |
application's binary). |
145 | 97 |
|
98 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
99 |
write your application in (say) english, and only plan to use it in english, |
|
5653 | 100 |
no additional work is required (i.e you don't even need a resource file then). |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
101 |
Strings for unknown languages will come in english |
145 | 102 |
(which is better than nothing or empty button labels ;-) |
103 |
||
7649 | 104 |
Notice, that you can also translate english to english, by providing an en.rs file. |
5653 | 105 |
This is sometimes useful to fix typing errors or bad syntax in the english, |
106 |
as sometimes made by the programmer, without a need to recompile or to also adjust other |
|
107 |
language translations. |
|
108 |
||
109 |
Finally, this scheme is also compatible to a pure enum-key based translation mechanism, |
|
110 |
as typically used in the C-world. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
111 |
Simple use keys as argument, and provide translations for all languages (incl. english). |
5653 | 112 |
For example: |
7649 | 113 |
Button label:(resources string:#BTN_FOO_LABEL) |
5653 | 114 |
|
115 |
||
145 | 116 |
Summary: |
7649 | 117 |
in subclasses of View and ApplicationModel, instead of writing: |
145 | 118 |
|
7649 | 119 |
... |
120 |
b := Button label:'press me' |
|
121 |
... |
|
145 | 122 |
|
7649 | 123 |
always write: |
612 | 124 |
|
7649 | 125 |
... |
126 |
b := Button label:(resources string:'press me') |
|
127 |
... |
|
145 | 128 |
|
7649 | 129 |
if your class is not a subclass of one of the above, AND you need |
130 |
resource translations, you won't inherit the resources variable |
|
131 |
(which is automatically initialized). |
|
132 |
In this case, you have to ask the ResourcePack class explicitely for |
|
133 |
a corresponding package: |
|
5483 | 134 |
|
7649 | 135 |
ResourcePack for:aClassName |
136 |
or (even better): |
|
137 |
ResourcePack forPackage:aPackageID |
|
145 | 138 |
|
7649 | 139 |
as an example, see how the Date class gets the national names of |
140 |
week & monthnames. |
|
145 | 141 |
|
5483 | 142 |
Debugging: |
7649 | 143 |
in the past, it happened that strings as returned by me were modified by someone else |
144 |
(replaceAll:with:) and then lead to invalid presentation in the future. |
|
145 |
To detect any bad guy which writes into one of my returned strings, set the DebugModifications |
|
146 |
classVar to true. Then I will return ImmutableStrings which trap on writes. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
147 |
|
612 | 148 |
[author:] |
7649 | 149 |
Claus Gittinger |
145 | 150 |
" |
151 |
! |
|
152 |
||
153 |
examples |
|
154 |
" |
|
155 |
normally, resources are found in files named after their classes sourcefile |
|
156 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
157 |
For the examples below, we process resources from a constant string; |
|
8462 | 158 |
this is NOT representative. |
159 |
[exBegin] |
|
160 |
|stream res| |
|
145 | 161 |
|
8462 | 162 |
stream := ReadStream on:' |
145 | 163 |
foo ''the translation for foo'' |
3422 | 164 |
#if Language == #de |
145 | 165 |
bar ''die deutsche uebersetzung von bar'' |
166 |
baz ''baz hat den Wert %1'' |
|
167 |
#endif |
|
3422 | 168 |
#if Language == #fr |
145 | 169 |
bar ''bar en francaise'' |
170 |
baz ''%1, c''''est baz'' |
|
171 |
#endif |
|
172 |
||
173 |
'. |
|
174 |
||
8462 | 175 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 176 |
|
8462 | 177 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
178 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
179 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
180 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
181 |
[exEnd] |
|
145 | 182 |
set the Language to french: |
8462 | 183 |
[exBegin] |
184 |
Language := #fr |
|
185 |
[exEnd] |
|
145 | 186 |
and repeat the above. |
620 | 187 |
back to english: |
8462 | 188 |
[exBegin] |
189 |
Language := #en |
|
190 |
[exEnd] |
|
620 | 191 |
back to german: |
8462 | 192 |
[exBegin] |
193 |
Language := #de |
|
194 |
[exEnd] |
|
46 | 195 |
" |
196 |
! ! |
|
5 | 197 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
198 |
!ResourcePack class methodsFor:'initialization'! |
0 | 199 |
|
72 | 200 |
flushCachedResourcePacks |
24 | 201 |
"forget all cached resources - needed after a style change" |
202 |
||
203 |
Packs := nil. |
|
204 |
self initialize |
|
205 |
||
4093 | 206 |
" |
207 |
ResourcePack flushCachedResourcePacks |
|
208 |
" |
|
244 | 209 |
! |
210 |
||
211 |
initialize |
|
212 |
Packs isNil ifTrue:[ |
|
8462 | 213 |
Packs := WeakArray new:100. |
214 |
FailedToLoadPacks := Set new. |
|
244 | 215 |
]. |
216 |
||
4093 | 217 |
" |
218 |
ResourcePack initialize |
|
219 |
" |
|
4623 | 220 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
221 |
"Modified: / 28-09-2011 / 15:53:21 / cg" |
244 | 222 |
! ! |
223 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
224 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 225 |
|
226 |
for:aClass |
|
227 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
228 |
Also leave the resulting pack in the cache for faster access next time." |
|
229 |
||
4619 | 230 |
^ self for:aClass cached:false |
4030 | 231 |
|
232 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
233 |
ResourcePack for:TextView |
4030 | 234 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
235 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
236 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
237 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
238 |
ResourcePack for:NewLauncher |
6799 | 239 |
ResourcePack for:SmallSense::SettingsAppl |
4030 | 240 |
Workspace classResources |
241 |
" |
|
4619 | 242 |
|
243 |
"Modified: / 18-09-2006 / 19:02:57 / cg" |
|
4030 | 244 |
! |
245 |
||
246 |
for:aClass cached:cached |
|
247 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
248 |
Also leave the resulting pack in the cache for faster access next time." |
|
249 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
250 |
|nm pack rsrcDir baseName| |
244 | 251 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
252 |
nm := aClass resourcePackName. |
4030 | 253 |
cached ifTrue:[ |
6909 | 254 |
pack := self searchCacheFor:nm. |
255 |
pack notNil ifTrue:[^ pack]. |
|
4030 | 256 |
]. |
244 | 257 |
|
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
258 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
259 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
260 |
|
4148 | 261 |
"/ CHECK this |
262 |
"/ (rsrcDir notNil and:[rsrcDir suffix = 'rs']) ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
263 |
"/ baseName := (Smalltalk fileNameForClass: rsrcDir tail asFilename withoutSuffix pathName),'.rs'. |
4148 | 264 |
"/ rsrcDir := rsrcDir head asFilename. |
265 |
"/ ]. |
|
266 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
267 |
rsrcDir notNil ifTrue:[ |
6909 | 268 |
pack := self new. |
269 |
rsrcDir exists ifTrue:[ |
|
270 |
(rsrcDir construct:baseName) exists ifTrue:[ |
|
271 |
pack := self fromFile:baseName directory:(rsrcDir name) cached:cached. |
|
272 |
]. |
|
273 |
] |
|
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
274 |
] ifFalse:[ |
6909 | 275 |
pack := self fromFile:baseName directory:'resources' cached:cached. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
276 |
]. |
4619 | 277 |
aClass superclass notNil ifTrue:[ |
6919 | 278 |
pack superPack:(self for:(aClass superclass) cached:cached). |
244 | 279 |
]. |
4093 | 280 |
pack packsClassOrFileName:nm. |
4030 | 281 |
cached ifTrue:[ |
6909 | 282 |
self addToCache:pack. |
4030 | 283 |
]. |
6909 | 284 |
pack projectPack:(self forPackage:(aClass resourcePackage) cached:cached). |
244 | 285 |
^ pack |
286 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
287 |
" |
4656 | 288 |
ResourcePack forPackage:'bosch:dapasx' cached:true |
289 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
290 |
ResourcePack for:TextView |
244 | 291 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
292 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
293 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
294 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
295 |
ResourcePack for:NewLauncher |
244 | 296 |
Workspace classResources |
297 |
" |
|
4617 | 298 |
|
5642
494cea2296dc
comment/format in: #for:cached:
Claus Gittinger <cg@exept.de>
parents:
5603
diff
changeset
|
299 |
"Modified: / 01-11-2010 / 09:09:43 / cg" |
244 | 300 |
! |
301 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
302 |
forPackage:package |
4078 | 303 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
304 |
Also leave the resulting pack in the cache for faster access next time." |
|
305 |
||
306 |
^ self forPackage:package cached:true |
|
307 |
||
308 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
309 |
ResourcePack forPackage:'stx:libbasic' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
310 |
ResourcePack forPackage:'stx:libtool' |
4078 | 311 |
" |
4618 | 312 |
|
313 |
"Modified: / 18-09-2006 / 18:45:31 / cg" |
|
4078 | 314 |
! |
315 |
||
316 |
forPackage:package cached:cached |
|
317 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
318 |
Also optionally leave the resulting pack in the cache for faster access next time." |
|
319 |
||
4673 | 320 |
^ self forPackage:package resourceFileName:'resources.rs' cached:cached |
321 |
||
322 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
323 |
ResourcePack forPackage:'stx:libbasic' cached:false |
4673 | 324 |
" |
325 |
||
326 |
"Modified: / 19-10-2006 / 23:18:28 / cg" |
|
327 |
! |
|
328 |
||
329 |
forPackage:package resourceFileName:resourceFileName cached:cached |
|
330 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
331 |
Also optionally leave the resulting pack in the cache for faster access next time. |
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
332 |
Remember failed packs, to avoid retrying reading the file again and again" |
4673 | 333 |
|
4428 | 334 |
|fullName pack rsrcDir file| |
4078 | 335 |
|
8470 | 336 |
package isNil ifTrue:[^ nil]. |
4673 | 337 |
fullName := package , '/resources/',resourceFileName. |
4078 | 338 |
|
339 |
cached ifTrue:[ |
|
8462 | 340 |
pack := self searchCacheFor:fullName. |
341 |
pack notNil ifTrue:[^ pack]. |
|
342 |
(FailedToLoadPacks includes:fullName) ifTrue:[^ nil]. |
|
4078 | 343 |
]. |
344 |
||
345 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
|
4428 | 346 |
rsrcDir isNil ifTrue:[ |
8462 | 347 |
file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
348 |
file isNil ifTrue:[ |
|
349 |
FailedToLoadPacks add:fullName. |
|
350 |
^ nil |
|
351 |
]. |
|
352 |
rsrcDir := file asFilename directory. |
|
4428 | 353 |
] ifFalse:[ |
8462 | 354 |
rsrcDir := rsrcDir asFilename construct:'resources'. |
355 |
rsrcDir exists ifFalse:[ |
|
356 |
FailedToLoadPacks add:fullName. |
|
357 |
^ nil |
|
358 |
]. |
|
4428 | 359 |
]. |
4078 | 360 |
|
4673 | 361 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
4093 | 362 |
pack packsClassOrFileName:fullName. |
4078 | 363 |
^ pack |
364 |
||
365 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
366 |
ResourcePack forPackage:'stx:libbasic' resourceFileName:'resources.rs' cached:false |
4078 | 367 |
" |
4656 | 368 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
369 |
"Modified: / 28-09-2011 / 15:55:30 / cg" |
8470 | 370 |
"Modified: / 17-09-2018 / 12:55:54 / Claus Gittinger" |
4078 | 371 |
! |
372 |
||
244 | 373 |
fromFile:aFileName |
4611 | 374 |
"get the resource definitions from a file in the default directory." |
244 | 375 |
|
376 |
^ self fromFile:aFileName directory:'resources' |
|
377 |
||
378 |
" |
|
379 |
ResourcePack fromFile:'SBrowser.rs' |
|
380 |
ResourcePack fromFile:'FBrowser.rs' |
|
381 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 382 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 383 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 384 |
" |
385 |
! |
|
386 |
||
387 |
fromFile:aFileName directory:dirName |
|
4611 | 388 |
"get the resource definitions from a file in a directory." |
389 |
||
390 |
^ self fromFile:aFileName directory:dirName cached:false |
|
391 |
! |
|
392 |
||
393 |
fromFile:aFileName directory:dirName cached:cached |
|
244 | 394 |
"get the resource definitions from a file in a directory. |
395 |
Uncached low-level entry." |
|
396 |
||
8483 | 397 |
|cachedPack newPack fn| |
244 | 398 |
|
8483 | 399 |
fn := (dirName asFilename / aFileName) pathName. |
400 |
cachedPack := Packs detect:[:p | p notNil and:[p isInteger not and:[p packsFileName = fn]]] ifNone:nil. |
|
401 |
cachedPack notNil ifTrue:[ |
|
402 |
"/ Transcript showCR:'cached pack: ',fn asString. |
|
403 |
^ cachedPack |
|
404 |
]. |
|
405 |
||
244 | 406 |
newPack := self new. |
7388 | 407 |
KeepStatisticsOnUsedKeys == true ifTrue:[ |
408 |
newPack rememberUsedKeys. |
|
409 |
]. |
|
244 | 410 |
newPack readFromFile:aFileName directory:dirName. |
4611 | 411 |
cached ifTrue:[ |
7388 | 412 |
self addToCache:newPack. |
4611 | 413 |
]. |
244 | 414 |
^ newPack |
8483 | 415 |
|
416 |
"Modified: / 25-09-2018 / 09:57:42 / Claus Gittinger" |
|
0 | 417 |
! ! |
418 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
419 |
!ResourcePack class methodsFor:'private'! |
54 | 420 |
|
421 |
addToCache:aPack |
|
422 |
|idx| |
|
0 | 423 |
|
4084 | 424 |
Packs isNil ifTrue:[ |
8462 | 425 |
self initialize. |
4084 | 426 |
]. |
427 |
||
54 | 428 |
idx := Packs identityIndexOf:nil. |
429 |
idx == 0 ifTrue:[ |
|
8462 | 430 |
idx := Packs findFirst:[:slot | slot class == SmallInteger]. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
431 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
432 |
idx == 0 ifTrue:[ |
8462 | 433 |
" |
434 |
throw away oldest |
|
435 |
" |
|
436 |
idx := Packs size. |
|
437 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 438 |
]. |
5357 | 439 |
aPack at:'__language__' put:(UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 440 |
Packs at:idx put:aPack. |
441 |
||
442 |
"Modified: / 18-09-2006 / 19:12:12 / cg" |
|
54 | 443 |
! |
0 | 444 |
|
4093 | 445 |
searchCacheFor:aClassOrFileName |
4619 | 446 |
|sz "{ Class: SmallInteger }" lang| |
0 | 447 |
|
24 | 448 |
Packs isNil ifTrue:[ |
8462 | 449 |
self initialize. |
450 |
^ nil |
|
0 | 451 |
]. |
54 | 452 |
|
5357 | 453 |
lang := (UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 454 |
|
54 | 455 |
sz := Packs size. |
456 |
1 to:sz do:[:idx | |
|
8462 | 457 |
|aPack| |
54 | 458 |
|
8462 | 459 |
aPack := Packs at:idx. |
460 |
(aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
|
461 |
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
|
462 |
aClassOrFileName = aPack packsClassOrFileName ifTrue:[ |
|
463 |
" |
|
464 |
bring to front for LRU |
|
465 |
" |
|
466 |
idx ~~ 1 ifTrue:[ |
|
467 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
|
468 |
Packs at:1 put:aPack. |
|
469 |
]. |
|
470 |
^ aPack |
|
471 |
] |
|
472 |
] |
|
473 |
] |
|
0 | 474 |
]. |
54 | 475 |
^ nil |
123 | 476 |
|
477 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
478 |
ResourcePack searchCacheFor:'TextView' |
123 | 479 |
" |
4619 | 480 |
|
481 |
"Modified: / 18-09-2006 / 19:13:13 / cg" |
|
54 | 482 |
! ! |
483 |
||
4509 | 484 |
!ResourcePack class methodsFor:'utilities'! |
485 |
||
486 |
extractEncodingFromLine:lineString |
|
487 |
|rest encoding| |
|
488 |
||
489 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
490 |
||
491 |
rest := lineString copyFrom:9. |
|
492 |
rest := rest withoutSeparators. |
|
493 |
(rest startsWith:'#') ifTrue:[ |
|
8462 | 494 |
rest := rest copyFrom:2. |
4509 | 495 |
]. |
496 |
(rest startsWith:'''') ifTrue:[ |
|
8462 | 497 |
rest := rest copyFrom:2. |
498 |
(rest endsWith:'''') ifTrue:[ |
|
499 |
rest := rest copyButLast:1. |
|
500 |
]. |
|
4509 | 501 |
]. |
502 |
encoding := rest asSymbol. |
|
503 |
^ encoding. |
|
504 |
! |
|
505 |
||
506 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
507 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
508 |
||
4510 | 509 |
self |
8462 | 510 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
511 |
keepUselessTranslations:false. |
|
4510 | 512 |
! |
513 |
||
514 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
515 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
516 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
517 |
|name lineStream idx rest macroName value |
4670 | 518 |
conditional hasError decoder oldValue ignoreTranslation indirect| |
4509 | 519 |
|
6250 | 520 |
"/ Transcript showCR:lineString. |
4531 | 521 |
encodingSymbolOrEncoder notNil ifTrue:[ |
8462 | 522 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
523 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
|
524 |
decoder isNil ifTrue:[ decoder := CharacterEncoder nullEncoderInstance ]. |
|
525 |
] ifFalse:[ |
|
526 |
decoder := encodingSymbolOrEncoder |
|
527 |
]. |
|
4531 | 528 |
]. |
529 |
||
530 |
decoder notNil ifTrue:[ |
|
8462 | 531 |
lineStream := (decoder decodeString:lineString) readStream. |
4531 | 532 |
] ifFalse:[ |
8462 | 533 |
lineStream := lineString readStream. |
4531 | 534 |
]. |
4509 | 535 |
lineStream signalAtEnd:false. |
536 |
lineStream skipSeparators. |
|
5080 | 537 |
|
4509 | 538 |
lineStream peek == $# ifTrue:[ |
8462 | 539 |
name := Array |
540 |
readFrom:lineStream |
|
541 |
onError:[ |
|
542 |
printError value:('invalid line <' , lineString , '>'). |
|
543 |
nil |
|
544 |
]. |
|
4509 | 545 |
] ifFalse:[ |
8462 | 546 |
lineStream peek == $' ifTrue:[ |
547 |
name := String |
|
548 |
readSmalltalkStringFrom:lineStream |
|
549 |
onError:[ |
|
550 |
printError value:('invalid line <' , lineString , '>'). |
|
551 |
nil |
|
552 |
]. |
|
553 |
] ifFalse:[ |
|
554 |
name := lineStream upToSeparator. |
|
555 |
]. |
|
4509 | 556 |
]. |
557 |
||
4510 | 558 |
name isNil ifTrue:[^ self ]. |
559 |
||
560 |
ignoreTranslation := false. |
|
561 |
hasError := false. |
|
4509 | 562 |
|
4510 | 563 |
lineStream skipSeparators. |
6113 | 564 |
idx := lineStream position + 1 + 1. |
4510 | 565 |
|
566 |
lineStream peek == $< ifTrue:[ |
|
8462 | 567 |
" |
568 |
skip <type> if present |
|
569 |
" |
|
570 |
lineStream skipThrough:$>. |
|
571 |
lineStream skipSeparators. |
|
572 |
idx := lineStream position + 2. |
|
4510 | 573 |
]. |
4509 | 574 |
|
4670 | 575 |
conditional := indirect := false. |
4510 | 576 |
lineStream peek == $? ifTrue:[ |
8462 | 577 |
conditional := true. |
578 |
lineStream next. |
|
579 |
lineStream skipSeparators. |
|
4670 | 580 |
]. |
581 |
||
582 |
lineStream peek == $@ ifTrue:[ |
|
8462 | 583 |
indirect := true. |
584 |
lineStream next. |
|
585 |
lineStream skipSeparators. |
|
4510 | 586 |
]. |
4509 | 587 |
|
4510 | 588 |
lineStream peek == $= ifTrue:[ |
8462 | 589 |
lineStream next. |
4510 | 590 |
|
8462 | 591 |
macroName := lineStream nextAlphaNumericWord. |
592 |
[lineStream peek == $.] whileTrue:[ |
|
593 |
lineStream next. |
|
594 |
lineStream peek notNil ifTrue:[ |
|
595 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
|
596 |
] |
|
597 |
]. |
|
598 |
rest := lineStream upToEnd. |
|
599 |
value := aResourcePack at:macroName ifAbsent:nil. |
|
600 |
(value isNil) ifTrue:[ |
|
601 |
hasError := true. |
|
602 |
printError value:('bad (nil-valued) macro: ' , macroName). |
|
603 |
]. |
|
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
604 |
"/ value isBlock ifTrue:[ |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
605 |
"/ value := value value |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
606 |
"/ ]. |
8462 | 607 |
rest isBlank ifFalse:[ |
608 |
value := Compiler evaluate:('self ' , rest) |
|
609 |
receiver:value |
|
610 |
notifying:nil |
|
611 |
compile:false. |
|
612 |
(value == #Error) ifTrue:[ |
|
613 |
hasError := true. |
|
614 |
printError value:('error in: "self ' , rest , '"'). |
|
615 |
]. |
|
616 |
"/ 'self ' print. rest print. ' -> ' print. value printCR. |
|
617 |
] |
|
4510 | 618 |
] ifFalse:[ |
8462 | 619 |
lineStream peek == $' ifTrue:[ |
620 |
value := String |
|
621 |
readSmalltalkStringFrom:lineStream |
|
622 |
onError:[ |
|
623 |
printError value:('invalid line <' , lineString , '>'). |
|
624 |
nil |
|
625 |
]. |
|
626 |
"/ ' -> ' print. value printCR. |
|
627 |
] ifFalse:[ |
|
628 |
rest := lineStream upToEnd. |
|
629 |
[ |
|
630 |
value := Compiler evaluate:rest compile:"true" false. |
|
631 |
] on:Error do:[ |
|
8476 | 632 |
printError value:('invalid line <' , lineString , '>'). |
8462 | 633 |
"/ value := rest |
634 |
]. |
|
635 |
"/ rest print. ' -> ' print. value printCR. |
|
636 |
]. |
|
637 |
(value == #Error) ifTrue:[ |
|
638 |
hasError := true. |
|
639 |
printError value:('error in: "' , rest , '"'). |
|
640 |
] ifFalse:[ |
|
4531 | 641 |
"/ value isString ifTrue:[ |
642 |
"/ decoder notNil ifTrue:[ |
|
643 |
"/ value := decoder decodeString:value |
|
644 |
"/ ] |
|
645 |
"/ ] |
|
8462 | 646 |
] |
4510 | 647 |
]. |
648 |
||
5430
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
649 |
"/ Transcript show:name; show:' -> '; showCR:value. |
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
650 |
|
4510 | 651 |
hasError ifFalse:[ |
8462 | 652 |
(conditional not |
653 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
654 |
name = value ifTrue:[ |
|
655 |
keepUselessTranslations ifFalse:[ |
|
656 |
printError value:('useless resource: "' , name , '"'). |
|
657 |
ignoreTranslation := true |
|
658 |
]. |
|
659 |
]. |
|
660 |
ignoreTranslation ifFalse:[ |
|
661 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
662 |
oldValue notNil ifTrue:[ |
|
663 |
oldValue ~= value ifTrue:[ |
|
664 |
printError value:('conflicting resource: "' , name , '"'). |
|
665 |
printError value:('oldValue: ' , oldValue printString). |
|
666 |
printError value:('newValue: ' , value printString). |
|
667 |
] ifFalse:[ |
|
668 |
printError value:('duplicate resource: "' , name , '"'). |
|
669 |
]. |
|
670 |
]. |
|
671 |
indirect ifTrue:[ |
|
672 |
value := aResourcePack string:value. |
|
673 |
]. |
|
5431 | 674 |
|
8462 | 675 |
DebugModifications == true ifTrue:[ |
676 |
"/ for debugging only !! (not all primitive code is ready for immutableStrings) |
|
677 |
value class == String ifTrue:[ |
|
678 |
value := value asImmutableString. |
|
679 |
]. |
|
680 |
]. |
|
5431 | 681 |
|
8462 | 682 |
aResourcePack at:name put:value. |
683 |
] |
|
684 |
] |
|
4509 | 685 |
] |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
686 |
|
6250 | 687 |
"Modified: / 06-02-2014 / 15:33:03 / cg" |
8476 | 688 |
"Modified: / 20-09-2018 / 11:10:06 / Claus Gittinger" |
6661 | 689 |
! |
690 |
||
691 |
resourceFileEntryFor:keyString to:nationalString |
|
692 |
"generate a line for a translation file, which defines a translation |
|
693 |
from keyString to nationalString. |
|
694 |
Naivly, this could be a simple line containing the two storeStrings |
|
695 |
separated by a space. However, it is better to first cut of any leading |
|
696 |
and trailing spaces and special characters, such as ':*.,' etc." |
|
697 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
698 |
^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) |
6661 | 699 |
! |
700 |
||
701 |
resourceFileStringFor:aString |
|
702 |
"generate a key or value entry for a translation file, for aString. |
|
703 |
Naivly, this could be a simple the storeString. |
|
704 |
However, it is better to first cut of any leading |
|
705 |
and trailing spaces and special characters, sch as ':*.,' etc." |
|
706 |
||
707 |
^ (self shortenedKeyFor:aString) storeString |
|
708 |
||
709 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
710 |
self resourceFileStringFor:' foo: ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
711 |
self resourceFileStringFor:' foo bar: ' |
6661 | 712 |
" |
713 |
! |
|
714 |
||
715 |
shortenedKeyFor:aKey |
|
716 |
"if |
|
8462 | 717 |
aKey is '(...)', then return '...' |
718 |
if aKey is '[...]', then return '...' |
|
719 |
if aKey is '{...}', then return '...' |
|
720 |
if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it |
|
6661 | 721 |
|
722 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
723 |
things like |
8462 | 724 |
'search' |
725 |
'search:' |
|
726 |
'search...' |
|
6661 | 727 |
" |
728 |
||
729 |
|idx idx1 idx2 first last keySize| |
|
730 |
||
731 |
first := aKey first. |
|
732 |
last := aKey last. |
|
733 |
keySize := aKey size. |
|
734 |
||
735 |
((first == $( and:[last == $) ]) |
|
736 |
or:[ (first == $[ and:[last == $] ]) |
|
737 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
8462 | 738 |
^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1). |
6661 | 739 |
]. |
740 |
||
741 |
idx1 := aKey findFirst:[:ch | ch isSeparator not]. |
|
742 |
idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize. |
|
743 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 744 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 745 |
]. |
746 |
||
747 |
idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not]. |
|
748 |
idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize. |
|
749 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 750 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 751 |
]. |
752 |
||
753 |
"/ change duplicated &'s to single |
|
754 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
8462 | 755 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
756 |
^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1). |
|
757 |
]. |
|
6661 | 758 |
]. |
759 |
^ aKey. |
|
760 |
||
761 |
" |
|
762 |
'abcde' findFirst:[:ch | 'bcd' includes:ch] |
|
763 |
'abcde' indexOfAny:'bcd' |
|
764 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
765 |
self shortenedKeyFor:'abc' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
766 |
self shortenedKeyFor:' abc ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
767 |
self shortenedKeyFor:'(abc)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
768 |
self shortenedKeyFor:'abc...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
769 |
self shortenedKeyFor:'(abc...)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
770 |
self shortenedKeyFor:'abc:*' |
6661 | 771 |
" |
4509 | 772 |
! ! |
773 |
||
0 | 774 |
!ResourcePack methodsFor:'accessing'! |
775 |
||
244 | 776 |
array:anArray |
777 |
"translate a collection of strings" |
|
0 | 778 |
|
244 | 779 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
780 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
781 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
782 |
Launcher classResources array:#('file' 'classes') |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
783 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
784 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
785 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 786 |
! |
787 |
||
2 | 788 |
at:aKey |
123 | 789 |
"translate a string" |
790 |
||
72 | 791 |
^ self at:aKey ifAbsent:aKey |
0 | 792 |
! |
793 |
||
794 |
at:aKey default:default |
|
123 | 795 |
"translate a string" |
796 |
||
72 | 797 |
^ self at:aKey ifAbsent:default |
0 | 798 |
! |
799 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
800 |
at:aKey ifAbsent:defaultValue |
4617 | 801 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
802 |
||
803 |
|val pack projectPack alreadySearched| |
|
804 |
||
805 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
806 |
||
807 |
val := self localAt:aKey. |
|
808 |
val notNil ifTrue:[^ val]. |
|
809 |
||
8461 | 810 |
cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
811 |
(val := cache at:aKey ifAbsent:nil) notNil ifTrue:[ |
|
812 |
^ val |
|
813 |
]. |
|
814 |
||
4617 | 815 |
(projectPack := self projectPack) notNil ifTrue:[ |
8461 | 816 |
val := projectPack localAt:aKey. |
817 |
val notNil ifTrue:[ |
|
818 |
cache at:aKey put:val. |
|
819 |
^ val |
|
820 |
]. |
|
4617 | 821 |
]. |
8462 | 822 |
alreadySearched := IdentitySet new. |
4617 | 823 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
824 |
||
825 |
pack := self superPack. |
|
826 |
[ pack notNil ] whileTrue:[ |
|
8461 | 827 |
val := pack localAt:aKey. |
828 |
val notNil ifTrue:[ |
|
829 |
cache at:aKey put:val. |
|
830 |
^ val |
|
831 |
]. |
|
4617 | 832 |
|
8461 | 833 |
(projectPack := pack projectPack) notNil ifTrue:[ |
834 |
(alreadySearched includes:projectPack) ifFalse:[ |
|
835 |
val := projectPack localAt:aKey. |
|
836 |
val notNil ifTrue:[ |
|
837 |
cache at:aKey put:val. |
|
838 |
^ val |
|
839 |
]. |
|
840 |
alreadySearched add:projectPack. |
|
841 |
]. |
|
842 |
]. |
|
843 |
pack := pack superPack |
|
4617 | 844 |
]. |
845 |
||
4618 | 846 |
alreadySearched copy do:[:projectPack | |
8461 | 847 |
|p| |
4618 | 848 |
|
8461 | 849 |
p := projectPack superPack. |
850 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
851 |
val := p localAt:aKey. |
|
852 |
val notNil ifTrue:[ |
|
853 |
cache at:aKey put:val. |
|
854 |
^ val |
|
855 |
]. |
|
856 |
alreadySearched add:p. |
|
857 |
p := p superPack. |
|
858 |
]. |
|
4618 | 859 |
]. |
860 |
||
8461 | 861 |
val := defaultValue value. |
862 |
cache at:aKey put:val. |
|
863 |
^ val |
|
4617 | 864 |
|
4618 | 865 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
8461 | 866 |
"Modified: / 12-09-2018 / 18:32:57 / Claus Gittinger" |
4617 | 867 |
! |
868 |
||
869 |
localAt:aKey |
|
4035 | 870 |
"translate a string. |
871 |
Some special 'intelligence' has been added: |
|
8226 | 872 |
if no value for aKey is found, |
873 |
lookup aKey with first character caseChanged and change the results first characters case. |
|
874 |
or aKey is '(...)', then lookup ... wrap () around the result. |
|
875 |
or aKey is '[...]', then lookup ... wrap [] around the result. |
|
876 |
or aKey is '{...}', then lookup ... wrap {} around the result. |
|
877 |
or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
|
878 |
or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result. |
|
879 |
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
|
880 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
|
881 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
882 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
|
883 |
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
|
884 |
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
|
885 |
or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
|
886 |
or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result. |
|
887 |
or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
|
888 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
889 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
890 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 891 |
|
892 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
893 |
things like |
8226 | 894 |
'search' |
895 |
'search:' |
|
896 |
'search...' |
|
4035 | 897 |
" |
123 | 898 |
|
5573 | 899 |
|val alternativeKey usedKey idx first last| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
900 |
|
4617 | 901 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
902 |
val notNil ifTrue:[ |
8226 | 903 |
^ val value |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
904 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
905 |
|
4848 | 906 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
8226 | 907 |
first := aKey first. |
908 |
last := aKey last. |
|
5573 | 909 |
|
8226 | 910 |
"/ try with case-first swapped... |
911 |
first isLetter ifTrue:[ |
|
912 |
alternativeKey := first isUppercase |
|
913 |
ifTrue:[aKey asLowercaseFirst] |
|
914 |
ifFalse:[aKey asUppercaseFirst]. |
|
915 |
val := super at:alternativeKey ifAbsent:nil. |
|
916 |
val notNil ifTrue:[ |
|
917 |
first isUppercase ifTrue:[ |
|
918 |
^ val asUppercaseFirst |
|
919 |
]. |
|
920 |
^ val asLowercaseFirst. |
|
921 |
]. |
|
922 |
]. |
|
4617 | 923 |
|
8226 | 924 |
((first == $( and:[last == $) ]) |
925 |
or:[ (first == $[ and:[last == $] ]) |
|
926 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
927 |
usedKey := aKey copyFrom:2 to:aKey size-1. |
|
5593 | 928 |
|
8226 | 929 |
val := self localAt:usedKey. "/ recursion |
930 |
val notNil ifTrue:[^ first asString,val,last asString]. |
|
931 |
]. |
|
8498 | 932 |
last == $… ifTrue:[ |
933 |
usedKey := aKey copyButLast:1. |
|
5593 | 934 |
|
8498 | 935 |
val := self localAt:usedKey. "/ recursion |
936 |
val notNil ifTrue:[^ val , '…']. |
|
937 |
]. |
|
938 |
||
8226 | 939 |
last == $. ifTrue:[ |
940 |
(aKey endsWith:' ...') ifTrue:[ |
|
941 |
usedKey := aKey copyButLast:4. |
|
5573 | 942 |
|
8226 | 943 |
val := self localAt:usedKey. "/ recursion |
8498 | 944 |
val notNil ifTrue:[^ val , '...']. |
8226 | 945 |
]. |
946 |
(aKey endsWith:'...') ifTrue:[ |
|
947 |
usedKey := aKey copyButLast:3. |
|
5573 | 948 |
|
8226 | 949 |
val := self localAt:usedKey. "/ recursion |
950 |
val notNil ifTrue:[^ val , '...']. |
|
951 |
]. |
|
952 |
]. |
|
5573 | 953 |
|
8226 | 954 |
first isSeparator ifTrue:[ |
955 |
usedKey := aKey withoutLeadingSeparators. |
|
4634 | 956 |
|
8226 | 957 |
val := self localAt:usedKey. "/ recursion |
958 |
val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
|
959 |
]. |
|
960 |
last isSeparator ifTrue:[ |
|
961 |
usedKey := aKey withoutTrailingSeparators. |
|
4634 | 962 |
|
8226 | 963 |
val := self localAt:usedKey. "/ recursion |
964 |
val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
|
965 |
]. |
|
4634 | 966 |
|
8226 | 967 |
('*:=.?!!,-><\' includes:last) ifTrue:[ |
968 |
aKey size >= 2 ifTrue:[ |
|
969 |
usedKey := aKey copyButLast:1. |
|
4617 | 970 |
|
8226 | 971 |
val := self localAt:usedKey. "/ recursion |
972 |
val notNil ifTrue:[^ val copyWith:last]. |
|
973 |
]. |
|
974 |
]. |
|
975 |
('*:=.?!!-><\' includes:first) ifTrue:[ |
|
976 |
aKey size >= 2 ifTrue:[ |
|
977 |
usedKey := aKey copyButFirst:1. |
|
4634 | 978 |
|
8226 | 979 |
val := self localAt:usedKey. "/ recursion |
980 |
val notNil ifTrue:[^ first asString , val]. |
|
981 |
]. |
|
982 |
]. |
|
4028 | 983 |
|
8226 | 984 |
(first == $( and:[last == $)]) ifTrue:[ |
985 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
4028 | 986 |
|
8226 | 987 |
val := self localAt:usedKey. "/ recursion |
988 |
val notNil ifTrue:[^ '(' , val , ')']. |
|
989 |
]. |
|
4017 | 990 |
|
8226 | 991 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
992 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
993 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
994 |
val := self localAt:usedKey. "/ recursion |
|
995 |
val notNil ifTrue:[^ val]. |
|
996 |
]. |
|
997 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
998 |
]. |
4617 | 999 |
^ nil. |
4580 | 1000 |
|
4617 | 1001 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
5593 | 1002 |
"Modified: / 05-08-2010 / 16:52:32 / sr" |
8226 | 1003 |
"Modified: / 27-11-2017 / 15:33:48 / cg" |
2 | 1004 |
! |
1005 |
||
1006 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1007 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1008 |
Obsolete - use #string:default:" |
123 | 1009 |
|
4844 | 1010 |
<resource: #obsolete> |
1011 |
||
72 | 1012 |
^ self at:aKey ifAbsent:default |
2 | 1013 |
! |
1014 |
||
0 | 1015 |
string:s |
3097 | 1016 |
"translate (retrieve) a string - if not present, return s" |
123 | 1017 |
|
72 | 1018 |
^ self at:s ifAbsent:s |
3097 | 1019 |
|
1020 |
" |
|
1021 |
NewLauncher classResources |
|
8462 | 1022 |
string:'LICENCEFILE' |
3097 | 1023 |
" |
0 | 1024 |
! |
1025 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1026 |
string:s default:defaultString |
3097 | 1027 |
"translate (retrieve) a string - if not present, return defaultString" |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1028 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1029 |
^ self at:s ifAbsent:defaultString |
3097 | 1030 |
|
1031 |
" |
|
1032 |
NewLauncher classResources |
|
8462 | 1033 |
string:'fooBar' default:'Hello world' |
3097 | 1034 |
" |
1035 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1036 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1037 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1038 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1039 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1040 |
|
8445 | 1041 |
^ self string:s default:defaultString withArguments:(Array with:arg) |
3097 | 1042 |
|
1043 |
" |
|
1044 |
NewLauncher classResources |
|
8445 | 1045 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 1046 |
" |
1047 |
||
8445 | 1048 |
"Modified: / 09-08-2018 / 14:55:56 / Claus Gittinger" |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1049 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1050 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1051 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1052 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1053 |
|
8445 | 1054 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2) |
1055 |
||
1056 |
"Modified: / 09-08-2018 / 14:55:53 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1057 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1058 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1059 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1060 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1061 |
|
8445 | 1062 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2 with:arg3) |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1063 |
|
8445 | 1064 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1065 |
"Modified: / 09-08-2018 / 14:55:51 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1066 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1067 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1068 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 with:arg4 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1069 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1070 |
|
8445 | 1071 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1072 |
|
8445 | 1073 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1074 |
"Modified: / 09-08-2018 / 14:55:47 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1075 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1076 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1077 |
string:s default:defaultString withArgs:argArray |
8445 | 1078 |
<resource: #obsolete> |
1079 |
"translate and expand args" |
|
1080 |
||
1081 |
^ self string:s default:defaultString withArguments:argArray |
|
1082 |
||
1083 |
"Modified: / 09-08-2018 / 14:55:38 / Claus Gittinger" |
|
1084 |
! |
|
1085 |
||
1086 |
string:s default:defaultString withArguments:argArray |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1087 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1088 |
|
5070 | 1089 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1090 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1091 |
template := self at:s ifAbsent:defaultString. |
5070 | 1092 |
^ template expandPlaceholdersWith:argArray. |
8445 | 1093 |
|
1094 |
"Created: / 09-08-2018 / 14:55:29 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1095 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1096 |
|
0 | 1097 |
string:s with:arg |
123 | 1098 |
"translate and expand arg" |
1099 |
||
8445 | 1100 |
^ self string:s withArguments:(Array with:arg) |
1101 |
||
1102 |
"Modified: / 09-08-2018 / 14:56:02 / Claus Gittinger" |
|
0 | 1103 |
! |
1104 |
||
1105 |
string:s with:arg1 with:arg2 |
|
123 | 1106 |
"translate and expand args" |
1107 |
||
8445 | 1108 |
^ self string:s withArguments:(Array with:arg1 with:arg2) |
1109 |
||
1110 |
"Modified: / 09-08-2018 / 14:56:04 / Claus Gittinger" |
|
0 | 1111 |
! |
1112 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1113 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1114 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1115 |
|
8445 | 1116 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1117 |
|
8445 | 1118 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1119 |
"Modified: / 09-08-2018 / 14:56:06 / Claus Gittinger" |
|
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1120 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1121 |
|
1042 | 1122 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
1123 |
"translate and expand args" |
|
1124 |
||
8445 | 1125 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
1042 | 1126 |
|
8445 | 1127 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1128 |
"Modified: / 09-08-2018 / 14:56:09 / Claus Gittinger" |
|
1042 | 1129 |
! |
1130 |
||
3184 | 1131 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
1132 |
"translate and expand args" |
|
1133 |
||
8445 | 1134 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3184 | 1135 |
|
8445 | 1136 |
"Modified: / 09-08-2018 / 14:56:12 / Claus Gittinger" |
3184 | 1137 |
! |
1138 |
||
5652 | 1139 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
1140 |
"translate and expand args" |
|
1141 |
||
8445 | 1142 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1143 |
|
1144 |
"Created: / 13-11-2010 / 11:35:00 / cg" |
|
8445 | 1145 |
"Modified: / 09-08-2018 / 14:56:14 / Claus Gittinger" |
5652 | 1146 |
! |
1147 |
||
1148 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1149 |
"translate and expand args" |
|
1150 |
||
8445 | 1151 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1152 |
|
1153 |
"Created: / 13-11-2010 / 11:35:07 / cg" |
|
8445 | 1154 |
"Modified: / 09-08-2018 / 14:55:07 / Claus Gittinger" |
5652 | 1155 |
! |
1156 |
||
0 | 1157 |
string:s withArgs:argArray |
8445 | 1158 |
<resource: #obsolete> |
1159 |
"translate and expand args - allow text as arguments" |
|
1160 |
||
1161 |
^ self string:s withArguments:argArray |
|
1162 |
||
1163 |
"Modified: / 09-08-2018 / 14:54:54 / Claus Gittinger" |
|
1164 |
! |
|
1165 |
||
1166 |
string:s withArguments:argArray |
|
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1167 |
"translate and expand args - allow text as arguments" |
123 | 1168 |
|
5069 | 1169 |
|template| |
0 | 1170 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1171 |
template := self at:s ifAbsent:s. |
5069 | 1172 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1173 |
|
8445 | 1174 |
"Created: / 09-08-2018 / 14:54:43 / Claus Gittinger" |
3823 | 1175 |
! |
1176 |
||
4402 | 1177 |
stringWithCRs:s |
8459 | 1178 |
"translate (retrieve) a string - if not present, return s. |
1179 |
replaces \'s with CRs" |
|
4402 | 1180 |
|
8459 | 1181 |
(s startsWith:':c:') ifTrue:[ |
1182 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes |
|
1183 |
]. |
|
1184 |
(s startsWith:':st:') ifTrue:[ |
|
1185 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:nil |
|
1186 |
]. |
|
4402 | 1187 |
^ (self string:s) withCRs |
1188 |
||
1189 |
" |
|
1190 |
NewLauncher classResources |
|
8459 | 1191 |
stringWithCRs:'LICENCEFILE' |
4402 | 1192 |
" |
8459 | 1193 |
|
1194 |
"Modified: / 07-09-2018 / 12:43:00 / Claus Gittinger" |
|
4402 | 1195 |
! |
1196 |
||
3823 | 1197 |
stringWithCRs:s with:arg |
1198 |
"translate, replace \'s with CRs and finally expand arg. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1199 |
CR-replacement is donw before args are inserted |
3823 | 1200 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1201 |
||
8445 | 1202 |
^ self stringWithCRs:s withArguments:(Array with:arg) |
3823 | 1203 |
|
8445 | 1204 |
"Modified: / 21-03-2003 / 14:22:09 / cg" |
1205 |
"Modified: / 09-08-2018 / 14:56:21 / Claus Gittinger" |
|
3823 | 1206 |
! |
1207 |
||
1208 |
stringWithCRs:s with:arg1 with:arg2 |
|
1209 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1210 |
CR-replacement is donw before args are inserted |
3823 | 1211 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1212 |
||
8445 | 1213 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2) |
3823 | 1214 |
|
8445 | 1215 |
"Modified: / 21-03-2003 / 14:22:06 / cg" |
1216 |
"Modified: / 09-08-2018 / 14:56:25 / Claus Gittinger" |
|
3823 | 1217 |
! |
1218 |
||
1219 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
1220 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1221 |
CR-replacement is donw before args are inserted |
3823 | 1222 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1223 |
||
8445 | 1224 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
3823 | 1225 |
|
8445 | 1226 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1227 |
"Modified: / 09-08-2018 / 14:56:27 / Claus Gittinger" |
|
3823 | 1228 |
! |
1229 |
||
1230 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
1231 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1232 |
CR-replacement is donw before args are inserted |
3823 | 1233 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1234 |
||
8445 | 1235 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3823 | 1236 |
|
8445 | 1237 |
"Modified: / 21-03-2003 / 14:21:48 / cg" |
1238 |
"Modified: / 09-08-2018 / 14:56:30 / Claus Gittinger" |
|
3823 | 1239 |
! |
1240 |
||
1241 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1242 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1243 |
CR-replacement is donw before args are inserted |
3823 | 1244 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1245 |
||
8445 | 1246 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3823 | 1247 |
|
8445 | 1248 |
"Modified: / 21-03-2003 / 14:21:55 / cg" |
1249 |
"Modified: / 09-08-2018 / 14:56:32 / Claus Gittinger" |
|
3823 | 1250 |
! |
1251 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1252 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
5652 | 1253 |
"translate, replace \'s with CRs and finally expand args. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1254 |
CR-replacement is donw before args are inserted |
5652 | 1255 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1256 |
||
8445 | 1257 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1258 |
|
1259 |
"Created: / 13-11-2010 / 11:35:30 / cg" |
|
8445 | 1260 |
"Modified: / 09-08-2018 / 14:56:35 / Claus Gittinger" |
5652 | 1261 |
! |
1262 |
||
1263 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1264 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1265 |
CR-replacement is donw before args are inserted |
5652 | 1266 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1267 |
||
8445 | 1268 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1269 |
|
1270 |
"Created: / 13-11-2010 / 11:35:20 / cg" |
|
8445 | 1271 |
"Modified: / 09-08-2018 / 14:56:37 / Claus Gittinger" |
5652 | 1272 |
! |
1273 |
||
3823 | 1274 |
stringWithCRs:s withArgs:argArray |
8445 | 1275 |
<resource: #obsolete> |
1276 |
"translate, replace \'s with CRs and finally expand args. |
|
1277 |
CR-replacement is done before args are inserted |
|
1278 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
1279 |
||
1280 |
^ self stringWithCRs:s withArguments:argArray |
|
1281 |
||
1282 |
"Modified: / 09-08-2018 / 14:54:29 / Claus Gittinger" |
|
1283 |
! |
|
1284 |
||
1285 |
stringWithCRs:s withArguments:argArray |
|
3823 | 1286 |
"translate, replace \'s with CRs and finally expand args. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1287 |
CR-replacement is done before args are inserted |
3823 | 1288 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1289 |
||
5070 | 1290 |
|template| |
3823 | 1291 |
|
1292 |
template := self at:s ifAbsent:s. |
|
8459 | 1293 |
(s startsWith:':c:') ifTrue:[ |
1294 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes expandPlaceholdersWith:argArray |
|
1295 |
]. |
|
1296 |
(s startsWith:':st:') ifTrue:[ |
|
1297 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:argArray |
|
1298 |
]. |
|
5070 | 1299 |
^ template withCRs expandPlaceholdersWith:argArray. |
8445 | 1300 |
|
1301 |
"Created: / 09-08-2018 / 14:54:16 / Claus Gittinger" |
|
8459 | 1302 |
"Modified: / 07-09-2018 / 12:44:06 / Claus Gittinger" |
6174 | 1303 |
! |
1304 |
||
1305 |
whichPackIncludesKey:aKey |
|
1306 |
"for debugging: return the pack (alogn the super-pack chain), which |
|
1307 |
has a translation for a string" |
|
1308 |
||
1309 |
|val pack projectPack alreadySearched| |
|
1310 |
||
1311 |
aKey isNil ifTrue:[ ^ nil ]. |
|
1312 |
||
1313 |
val := self localAt:aKey. |
|
1314 |
val notNil ifTrue:[^ self]. |
|
1315 |
||
1316 |
(projectPack := self projectPack) notNil ifTrue:[ |
|
8462 | 1317 |
val := projectPack localAt:aKey. |
1318 |
val notNil ifTrue:[^ projectPack]. |
|
6174 | 1319 |
]. |
1320 |
alreadySearched := Set new. |
|
1321 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
1322 |
||
1323 |
pack := self superPack. |
|
1324 |
[ pack notNil ] whileTrue:[ |
|
8462 | 1325 |
val := pack localAt:aKey. |
1326 |
val notNil ifTrue:[^ pack]. |
|
6174 | 1327 |
|
8462 | 1328 |
(projectPack := pack projectPack) notNil ifTrue:[ |
1329 |
(alreadySearched includes:projectPack) ifFalse:[ |
|
1330 |
val := projectPack localAt:aKey. |
|
1331 |
val notNil ifTrue:[^ projectPack]. |
|
1332 |
alreadySearched add:projectPack. |
|
1333 |
]. |
|
1334 |
]. |
|
1335 |
pack := pack superPack |
|
6174 | 1336 |
]. |
1337 |
||
1338 |
alreadySearched copy do:[:projectPack | |
|
8462 | 1339 |
|p| |
6174 | 1340 |
|
8462 | 1341 |
p := projectPack superPack. |
1342 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
1343 |
val := p localAt:aKey. |
|
1344 |
val notNil ifTrue:[^ p]. |
|
1345 |
alreadySearched add:p. |
|
1346 |
p := p superPack. |
|
1347 |
]. |
|
6174 | 1348 |
]. |
1349 |
||
1350 |
^ nil |
|
0 | 1351 |
! ! |
1352 |
||
3317 | 1353 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1354 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1355 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1356 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1357 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1358 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1359 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1360 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1361 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1362 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1363 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1364 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1365 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1366 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1367 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1368 |
|
4093 | 1369 |
packsClassOrFileName |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1370 |
"old: should no longer be used to access the filename; see packsFileName" |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1371 |
|
4093 | 1372 |
^ packsClassName |
1373 |
! |
|
1374 |
||
1375 |
packsClassOrFileName:aString |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1376 |
"old: should no longer be used to access the filename; see packsFileName" |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1377 |
|
4093 | 1378 |
packsClassName := aString |
1379 |
! |
|
1380 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1381 |
packsFileName |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1382 |
^ packsFileName |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1383 |
! |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1384 |
|
4617 | 1385 |
projectPack |
1386 |
^ projectPack |
|
1387 |
||
1388 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1389 |
! |
|
1390 |
||
4085 | 1391 |
projectPack:anotherResourcePack |
1392 |
projectPack := anotherResourcePack |
|
1393 |
||
1394 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
|
1395 |
! |
|
1396 |
||
4617 | 1397 |
superPack |
8496 | 1398 |
"sr: dont know why and where but did happen |
1399 |
will end up in recursion loop. |
|
1400 |
I added an assert to the setter" |
|
1401 |
self == superPack ifTrue:[ |
|
1402 |
^ nil |
|
1403 |
]. |
|
1404 |
||
4617 | 1405 |
^ superPack |
1406 |
||
1407 |
"Created: / 18-09-2006 / 17:38:12 / cg" |
|
8496 | 1408 |
"Modified (comment): / 10-10-2018 / 14:14:44 / sr" |
4617 | 1409 |
! |
1410 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1411 |
superPack:anotherResourcePack |
8496 | 1412 |
"sr: dont know why and where but did happen. |
1413 |
will end up in recursion loop." |
|
1414 |
self assert:anotherResourcePack ~~ self. |
|
1415 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1416 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1417 |
|
8496 | 1418 |
"Created: / 29-01-1998 / 22:43:09 / cg" |
1419 |
"Modified (comment): / 10-10-2018 / 14:14:39 / sr" |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1420 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1421 |
|
0 | 1422 |
!ResourcePack methodsFor:'file reading'! |
1423 |
||
684 | 1424 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1425 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1426 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1427 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1428 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1429 |
|
687 | 1430 |
^ fileReadFailed ~~ false |
684 | 1431 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1432 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1433 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1434 |
! |
1435 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1436 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1437 |
"asked to read definitions for a non-existing file. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1438 |
Here, this is legal and ignored (typically using inherited resources). |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1439 |
However, subclasses (such as styleSheet) may flag it as an error." |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1440 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1441 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1442 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1443 |
"Created: 6.9.1997 / 11:38:53 / cg" |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1444 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1445 |
|
4332 | 1446 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1447 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1448 |
||
4509 | 1449 |
self class |
8462 | 1450 |
processResourceLine:lineString |
1451 |
encoding:encodingSymbolOrEncoder |
|
1452 |
file:fileName |
|
1453 |
printErrorWith:printError |
|
1454 |
for:self |
|
144 | 1455 |
! |
1456 |
||
244 | 1457 |
readFromFile:fileName directory:dirName |
1458 |
"read definitions from a file in a directory" |
|
1459 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1460 |
|triedFilename inStream ok| |
244 | 1461 |
|
686 | 1462 |
fileReadFailed := false. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1463 |
"/ need to catch errors here, as the handler might itself need resources. |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1464 |
"/ (happens when da.rs is not present in libbasic/resources.rs) |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1465 |
ExternalStream openErrorSignal handle:[:ex | |
8462 | 1466 |
Transcript showCR:'ResourcePack: failed to open file: ',fileName asString,' in ',dirName asString. |
1467 |
inStream := nil. |
|
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1468 |
] do:[ |
8462 | 1469 |
dirName = 'resources' ifTrue:[ |
1470 |
inStream := Smalltalk resourceFileStreamFor:fileName |
|
1471 |
] ifFalse:[ |
|
1472 |
inStream := Smalltalk systemFileStreamFor: |
|
1473 |
(dirName isNil |
|
1474 |
ifTrue:[fileName] |
|
1475 |
ifFalse:[dirName asFilename construct:fileName]). |
|
1476 |
]. |
|
244 | 1477 |
]. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1478 |
|
244 | 1479 |
inStream isNil ifTrue:[ |
8462 | 1480 |
" |
1481 |
an empty pack |
|
1482 |
" |
|
1483 |
^ self nonexistingFileRead |
|
244 | 1484 |
]. |
2996 | 1485 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1486 |
triedFilename := inStream pathName. |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1487 |
[ |
8462 | 1488 |
ok := self readFromResourceStream:inStream in:(triedFilename asFilename directoryName). |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1489 |
] ensure:[ |
8462 | 1490 |
inStream close. |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1491 |
]. |
686 | 1492 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1493 |
ok ifTrue:[ |
8462 | 1494 |
packsFileName := triedFilename |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1495 |
] ifFalse:[ |
8462 | 1496 |
fileReadFailed := true. |
684 | 1497 |
|
8462 | 1498 |
('ResourcePack [warning]: "' , triedFilename , '" contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1499 |
]. |
1500 |
||
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1501 |
"Modified: / 20-08-2011 / 17:10:02 / cg" |
244 | 1502 |
! |
1503 |
||
72 | 1504 |
readFromResourceStream:inStream in:dirName |
4848 | 1505 |
"read definitions from a stream. The dirName argument is required to |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1506 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1507 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1508 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1509 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1510 |
printError fileName pushedSkipValues| |
4058 | 1511 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1512 |
fileName := (inStream isFileStream |
6992 | 1513 |
ifTrue:[inStream pathName asFilename baseName] |
1514 |
ifFalse:['---']). |
|
4058 | 1515 |
|
1516 |
printError := [:message | |
|
6992 | 1517 |
'ResourcePack [warning]: ' errorPrint. |
1518 |
message errorPrint. |
|
1519 |
' in file:' errorPrint. |
|
1520 |
fileName errorPrint. |
|
1521 |
' line: ' errorPrint. |
|
1522 |
lineNumber errorPrintCR |
|
1523 |
]. |
|
4058 | 1524 |
|
1525 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1526 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1527 |
encoding := nil. |
0 | 1528 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1529 |
ok := true. |
0 | 1530 |
ifLevel := 0. |
1531 |
skipping := false. |
|
4058 | 1532 |
lineNumber := 0. |
4947 | 1533 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1534 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1535 |
errorHandler := [:ex | |
6992 | 1536 |
|con| |
4947 | 1537 |
|
6992 | 1538 |
Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". |
1539 |
Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". |
|
1540 |
con := ex suspendedContext. |
|
1541 |
Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". |
|
1542 |
con := con sender. |
|
1543 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1544 |
20 timesRepeat:[ |
|
1545 |
con notNil ifTrue:[ |
|
1546 |
con := con sender. |
|
1547 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1548 |
]. |
|
1549 |
]. |
|
1550 |
value := nil. |
|
1551 |
ok := false. |
|
1552 |
]. |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1553 |
|
0 | 1554 |
[inStream atEnd] whileFalse:[ |
6992 | 1555 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
1556 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
|
1557 |
lineString := lineString copyButLast:1. |
|
1558 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
|
1559 |
l notNil ifTrue:[ |
|
1560 |
lineString := lineString , l. |
|
1561 |
]. |
|
1562 |
]. |
|
177 | 1563 |
|
6992 | 1564 |
(lineString size > 0) ifTrue:[ |
1565 |
first := lineString at:1. |
|
1566 |
"/ |
|
1567 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
|
1568 |
"/ |
|
1569 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
|
1570 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
|
1571 |
"/ a directive |
|
1572 |
lineString := (lineString copyFrom:2) withoutSpaces. |
|
72 | 1573 |
|
6992 | 1574 |
(lineString startsWith:'if') ifTrue:[ |
1575 |
pushedSkipValues add:skipping. |
|
1576 |
skipping ifFalse:[ |
|
1577 |
rest := lineString copyFrom:3. |
|
1578 |
Error, UserInformation |
|
1579 |
handle:errorHandler |
|
1580 |
do:[ |
|
1581 |
value := Compiler evaluate:rest compile:false. |
|
1582 |
]. |
|
1583 |
(value == #Error) ifTrue:[ |
|
1584 |
printError value:('error in resource:' , lineString). |
|
1585 |
]. |
|
1586 |
(value == false) ifTrue:[ |
|
1587 |
skipping := true |
|
1588 |
] |
|
1589 |
]. |
|
1590 |
ifLevel := ifLevel + 1 |
|
1591 |
] ifFalse:[ |
|
1592 |
(lineString startsWith:'endif') ifTrue:[ |
|
1593 |
ifLevel == 0 ifTrue:[ |
|
1594 |
printError value:('if/endif nesting error'). |
|
1595 |
] ifFalse:[ |
|
1596 |
ifLevel := ifLevel - 1. |
|
1597 |
skipping := pushedSkipValues removeLast. |
|
1598 |
] |
|
1599 |
] ifFalse:[ |
|
1600 |
(lineString startsWith:'else') ifTrue:[ |
|
1601 |
(pushedSkipValues includes:true) ifFalse:[ |
|
1602 |
skipping := skipping not |
|
1603 |
] |
|
1604 |
] ifFalse:[ |
|
1605 |
skipping ifFalse:[ |
|
1606 |
(lineString startsWith:'superpack') ifTrue:[ |
|
1607 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1608 |
value := Compiler evaluate:rest compile:false. |
|
1609 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
8496 | 1610 |
self superPack:value. |
6992 | 1611 |
] |
1612 |
] ifFalse:[ |
|
1613 |
(lineString startsWith:'include') ifTrue:[ |
|
1614 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1615 |
"/ include those resources ... |
|
1616 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1617 |
value := Compiler evaluate:rest compile:false. |
|
1618 |
value isBehavior ifTrue:[ |
|
1619 |
pack := self class for:value. |
|
1620 |
pack notNil ifTrue:[ |
|
1621 |
self addAll:pack. |
|
1622 |
] |
|
1623 |
] |
|
1624 |
] ifFalse:[ |
|
1625 |
rest := lineString copyFrom:('include' size + 1). |
|
1626 |
value := Compiler evaluate:rest compile:false. |
|
1627 |
value isString ifFalse:[ |
|
1628 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1629 |
] ifTrue:[ |
|
1630 |
self readFromFile:value directory:dirName |
|
1631 |
] |
|
1632 |
] |
|
1633 |
] ifFalse:[ |
|
1634 |
(lineString startsWith:'encoding') ifTrue:[ |
|
4848 | 1635 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
6992 | 1636 |
encoding := self class extractEncodingFromLine:lineString. |
1637 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
1638 |
] |
|
1639 |
] |
|
1640 |
] |
|
1641 |
] |
|
1642 |
] |
|
1643 |
] |
|
1644 |
]. |
|
1645 |
] ifFalse:[ |
|
1646 |
skipping ifFalse:[ |
|
1647 |
Error, UserInformation |
|
1648 |
handle:errorHandler |
|
1649 |
do:[ |
|
1650 |
(lineString at:1) == $!! ifTrue:[ |
|
1651 |
"/ evaluate the rest |
|
1652 |
Compiler evaluate:(lineString copyFrom:2) |
|
1653 |
receiver:self |
|
1654 |
notifying:nil |
|
1655 |
compile:false. |
|
1656 |
] ifFalse:[ |
|
1657 |
"/ process as resource |
|
1658 |
self |
|
1659 |
processLine:lineString |
|
1660 |
encoding:decoder |
|
1661 |
file:(inStream isFileStream |
|
1662 |
ifTrue:[inStream pathName] |
|
1663 |
ifFalse:['---']) |
|
1664 |
printErrorWith:printError |
|
1665 |
]] |
|
1666 |
] |
|
1667 |
] |
|
1668 |
] |
|
1669 |
] |
|
0 | 1670 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1671 |
^ ok |
177 | 1672 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1673 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1674 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
8496 | 1675 |
"Modified: / 10-10-2018 / 14:14:00 / sr" |
0 | 1676 |
! ! |
1677 |
||
4093 | 1678 |
!ResourcePack methodsFor:'printing & storing'! |
1679 |
||
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1680 |
displayOn:aGCOrStream |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1681 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1682 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
7931 | 1683 |
"/ old ST80 means: draw-yourself on a GC. |
1684 |
(aGCOrStream isStream) ifFalse:[ |
|
1685 |
^ super displayOn:aGCOrStream |
|
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1686 |
]. |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1687 |
|
7931 | 1688 |
aGCOrStream nextPutAll:'ResourcePack for: '. |
1689 |
packsClassName printOn:aGCOrStream. |
|
1690 |
||
1691 |
"Modified: / 22-02-2017 / 17:00:31 / cg" |
|
4093 | 1692 |
! ! |
1693 |
||
8461 | 1694 |
!ResourcePack methodsFor:'statistics'! |
1695 |
||
1696 |
forgetUsedKeys |
|
1697 |
"stop keeping a statistic on which keys are actually used" |
|
1698 |
||
1699 |
usedKeys := nil. |
|
1700 |
||
1701 |
"Modified (comment): / 12-09-2018 / 18:23:27 / Claus Gittinger" |
|
1702 |
! |
|
1703 |
||
1704 |
rememberUsedKeys |
|
1705 |
"start keeping a statistic on which keys are actually used" |
|
1706 |
||
1707 |
usedKeys := Set new. |
|
1708 |
||
1709 |
"Modified (comment): / 12-09-2018 / 18:23:22 / Claus Gittinger" |
|
1710 |
! |
|
1711 |
||
1712 |
usedKeys |
|
1713 |
"get keys which were actually used. |
|
1714 |
(must call #rememberUsedKeys before)" |
|
1715 |
||
1716 |
^ usedKeys |
|
1717 |
||
1718 |
"Created: / 12-09-2018 / 18:24:26 / Claus Gittinger" |
|
1719 |
! ! |
|
1720 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1721 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1722 |
|
1723 |
version |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1724 |
^ '$Header$' |
5357 | 1725 |
! |
1726 |
||
1727 |
version_CVS |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1728 |
^ '$Header$' |
251 | 1729 |
! ! |
3769 | 1730 |
|
6051
f01078ce8c2c
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
5951
diff
changeset
|
1731 |
|
0 | 1732 |
ResourcePack initialize! |