This class supports easy customization of smalltalk code (i.e. internationalization
and viewStyle adaption).
ResourcePacks are class specific, meaning that every subclass of View
and ApplicationModel has an instance of ResourcePack (instVar called 'resources')
which is created when the first instance of the view/app is created,
and cached in a class-instVar (so the file is only read once).
The resourcePack consists of a mapping from strings to values, which are
then used in labels, buttons, menus etc.
The resourcePack initializes itself from a file found in 'resources/<className>.rs',
where 'className' is built by the usual abbreviation mechanism (see abbrev-files).
Conditional mappings are possible, by including lines as:
#if <expression>
#endif
in the resourcefile. Example:
file 'foo.rs':
#if Language == #de
'abort' 'Abbruch'
#endif
#if Language == #fr
'abort' 'canceller'
#endif
the corresponding resource-strings are accessed (from methods within the class)
using:
resources string:'abort'
returning the mapped string (i.e. 'Abbruch' if the global Language is set
to #de)..
If no corresponding entry is found in the resources, the key is returned;
alternatively, use:
resources string:'foo' default:'bar'
which returns 'bar', if no resource definition for 'foo' is found.
Translations can also include arguments, such as:
resources string:'really delete %1' with:fileName
This scheme has the advantage, that you can write your programs using your
native language strings. Later, when new languages are to be supported,
simply create a resource file for the class and add translations for
all those strings. (find the keys by looking at users of resource or senders
of 'string:*').
Notice, that the grammar of different languages may imply a reordering,
so the above string becomes the german 'wollen Sie %1 wirklich löschen';
so using percent-placeholders is much better than simple concatenations of
arguments to the question.
More languages can be added later without any change in the code, or recompilation
or the like. Even by people without access to the source code (i.e. which only have the
applications binary).
Also, unsupported languages' strings are simply left unchanged - if you
write your application in (say) english, and only plan to use it in english,
no additional work is required (i.e you don't even need a resource file then).
Strings for unknown languages will come in english
(which is better than nothing or empty button labels ;-)
Notice, that you can also translate english to english, by providing an en.rs file.
This is sometimes useful to fix typing errors or bad syntax in the english,
as sometimes made by the programmer, without a need to recompile or to also adjust other
language translations.
Finally, this scheme is also compatible to a pure enum-key based translation mechanism,
as typically used in the C-world.
Simple use keys as argument, and provide translations for all languages (incl. english).
For example:
Button label:(resources string:#BTN_FOO_LABEL)
Summary:
in subclasses of View and ApplicationModel, instead of writing:
...
b := Button label:'press me'
...
always write:
...
b := Button label:(resources string:'press me')
...
if your class is not a subclass of one of the above, AND you need
resource translations, you won't inherit the resources variable
(which is automatically initialized).
In this case, you have to ask the ResourcePack class explicitely for
a corresponding package:
ResourcePack for:aClassName
or (even better):
ResourcePack forPackage:aPackageID
as an example, see how the Date class gets the national names of
week & monthnames.
Debugging:
in the past, it happened that strings as returned by me were modified by someone else
(replaceAll:with:) and then lead to invalid presentation in the future.
To detect any bad guy which writes into one of my returned strings, set the DebugModifications
classVar to true. Then I will return ImmutableStrings which trap on writes.

get the full resource definitions given a package id (such as stx:libbasic').
Also optionally leave the resulting pack in the cache for faster access next time.
Remember failed packs, to avoid retrying reading the file again and again

generate a line for a translation file, which defines a translation
from keyString to nationalString.
Naivly, this could be a simple line containing the two storeStrings
separated by a space. However, it is better to first cut of any leading
and trailing spaces and special characters, such as ':*.,' etc.

generate a key or value entry for a translation file, for aString.
Naivly, this could be a simple the storeString.
However, it is better to first cut of any leading
and trailing spaces and special characters, sch as ':*.,' etc.

translate a string.
Some special 'intelligence' has been added:
if no value for aKey is found,
lookup aKey with first character caseChanged and change the results first characters case.
or aKey is '(...)', then lookup ... wrap () around the result.
or aKey is '[...]', then lookup ... wrap [] around the result.
or aKey is '{...}', then lookup ... wrap {} around the result.
or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result.
or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result.
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result.
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result.
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result.
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result.
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result.
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result.
or aKey ends with a '!', then lookup aKey without '!' and append '!' to the result.
or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result.
or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result.
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result.
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result.
or aKey includes '&', then lookup aKey without '&'.

This means, that only a single translation is required to provide local translations for
things like
'search'
'search:'
'search...'

normally, resources are found in files named after their classes sourcefile
For example, the FileBrowsers resources are found in 'FBrowser.rs'.
For the examples below, we process resources from a constant string;
this is NOT representative.