User:NeilK/JavascriptMessagesDesign

Thoughts on JS messages.

passing jquery args in
Uncertain about mdale's jquery case.

Roan, Trevor and I think that jquery magic makes more sense after the fact, after the base HTML has been made. The problem there is identifying the buttons after you've made them, since you can't rely on the same order in all languages.

Mdale wants to pass in event-bound jquery objects to templates, when constructing links or buttons, and have the library do complex swapping about with HTML and contained text. This however, is slightly inaccurate since it is at least theoretically possible to want two different buttons, with different bindings, but keyed off the same parameter... Still perhaps that case is too pathological to consider.

other problems: context-awareness
Sometimes you want the text as text, escaped for attributes. Other times (the vast majority) you want the text to be valid HTML DOM (a la jQuery, to be appended into a structure).

It's annoying to have to remember this, can we do better?

idea: jQuery-ify our API
Instead of

$j( '#someId' ).html( gM( 'message-key', 10, 20 ) );

How about?

$j( '#someId' ).msg( 'message-key', 10, 20 );

Or even this -- this could be very useful for interfaces that change when the number of something changes?

$j( '#someId' ).msg( 'total-files-uploaded', 0, 0 );

$j( '#someId' ).msgArg( 1, 20 ); // Uploaded 1 file of 20...   $j( '#someId' ).msgArg( 2, 20 );  // Uploaded 2 files of 20...   $j( '#someId' ).msgArg( 3, 20 );  // Uploaded 3 files of 20...

// eliminate repeated args...  $j( '#someId' ).msgArg( { '$2': 20 } );  // Uploaded 0 files of 20...   $j( '#someId' ).msgArg( { '$1': 1 } );  // Uploaded 1 files of 20...   $j( '#someId' ).msgArg( { '$1': 2 } );  // Uploaded 2 files of 20...

What this means -- $j.msg is now handed a set of jQuery nodes. So it can pick what it wants to do, based on the node type. (Is this really helpful though? attrs aren't jquery nodes...)

$j( '#someid' ).attr( 'alt', gM( 'message-key' ) ); // context-unaware $j( '#someid' ).attr( 'alt', gMattr( 'message-key' ) ); // context-aware but you have to remember to use it  $j( '#someid' ).attrMsg( 'alt', 'message-key', 10, 20 ); // context-aware

As for messages that themselves generate jQuery subtrees, the situation is the same, it will default to building out a tree and then using .html on the nodes.

Parsing
How it works now, in PHP-land


 * an initial pass changes all $x arguments to their argument
 * then, you can parse for templates and so on XOR parse for magic. Why the distinction?
 * parse for templates and the usual thing
 * then, a 'parsemag' parses for "magic". Magic includes: PLURAL and other stuff like SITENAME