[stringtemplate-interest] ST & I18N

Terence Parr parrt at cs.usfca.edu
Fri Nov 4 09:40:45 PST 2005


On Nov 1, 2005, at 11:30 AM, FrankHarper.10118606 at bloglines.com wrote:

> Hi STers,
>
> I haven't been able to find support in ST for I18N.

Do you mean that the templates cannot contain unicode or that the  
error messages from the tool are english only and hardcoded?

> My web app generates URLs on the fly based on user
> input, which can contain non ascii characters. Sometimes I display  
> the user
> input in a page, and sometimes the same information is used to  
> create links.
> In this case the the user input has to be url encoded.
>
> The only solution
> I've come up with so far is to create two ST attributes with the  
> same information,
> one url encoded and one not.

Can you add a renderer mapping from a special URL object so that any  
object that is plain string just displays and then any URL gets encoded?

> Then of course there's another whole can of
> worms that will appear when I actually want to translate the web  
> page contents.
> I guess this will require creating an attribute for each string  
> that needs
> I18Ning.

I use a StringTemplateGroup to good effect for this.  All error  
messages in new ANTLR v3 are in a group for english, one for french,  
etc...  I have a switch based upon the locale that loads the  
appropriate group and then I use a key like GRAMMAR_NONDETERMINISM  
which is or could be mapped to the template name to load.  The tool  
knows nothing of the contents...can be unicode or whatever.

> I would like to hear from anyone who has ideas or experience on
> using ST in an I18Ned app, especially if you've come up with more  
> elegant
> solutions than the ones I've mentioned.

We should come up with a standard recommendation for this...I can add  
stuff to the tool to make it work better if need be.

Ter


More information about the stringtemplate-interest mailing list