[Maypole] text string generation in Maypole

Dave Howorth dhoworth@mrc-lmb.cam.ac.uk
Thu, 03 Feb 2005 12:11:39 +0000


There's been another burst of discussion about text strings and as some 
will know, I have a bee in my bonnet about that! My views are recorded 
in the archive.

Now I've lately come to realize that there're some fairly simple changes 
that would improve things, so let me try to explain.

GOALS

Some of Maypole's attraction comes from the automatic generation of 
labels for display.

But philosophically, text belongs in the templates (or database, or
resource files) but NOT in the code.

There will always be exceptions to automatic generation (like, normally 
take the singular of a column, except for 'hips').

The clasic killer 'exception' is foreign language translation of labels.

REALITY

Label generation is spread over many methods in several modules, some
of which are not even part of Maypole, with several different authors,
so coordination is difficult and even locating a problem can be 
time-consuming. Well-known issues include plural and multi-word table or 
column names.

THOUGHTS

-1- Collect all the text generation algorithms in one place (like my
Mangle.pm does) so we can all see what we've got any time we want and 
developers can easily override any part they need to.

-2- Maypole uses context-sensitive names. E.g. classmetadata.moniker
returns one string in a class called Beer and a different string in a
class called Brewery. If we used absolute names. E.g.:

    tables.Beer.singular => 'Beer'
    tables.Brewery.singular => 'Brewery'

so we say [% tables.$class.singular %] in a template instead of
[% classmetadata.moniker %], then it becomes trivial to apply 
exceptions. We just have a text_exceptions.tt that is PROCESSed at the 
start of each template that can just contain things like:

    tables.Beer.singular => 'Bier'
    tables.Brewery.singular => 'Brauerei'

So web designers can easily override things without having to change any 
code. Note that these data structures need to be hashes, not objects, 
for this to work.

Cheers, Dave