[stringtemplate-interest] ST4 Newbie - some basic questions around template complexity, localization
Udo Borkowski
ub at abego-software.de
Wed Aug 31 06:04:44 PDT 2011
Regarding the localization issue:
I cannot judge if this approach is applicable in your context, but here is how I would do it:
Per HTML file:
* create a template that renders exactly the given HTML
* identify the "variable parts" (not the "fixed strings (for localization)") and introduce parameters for those. When using HTML you probably would write things like "Dear $saluation$ $lastName$, …"
* build the infrastructure to generate the HTML, using the variables/parameters
Once all templates are created check if there is some "repeated stuff" and extract this into templates and template calls. This way we avoid repetition and simplify maintenance and translation. Typical templates could be things like general stuff like "$adress(…)$", "$greeting(…)$", but also common phrases using in multiple types of emails.
Once this is done create copies of the templates that contain text that needs localization, one copy per target and put them in one template group per language. The texter/translators will directly work on these templates (no extra tool required). They just need to ensure not to touch "the stuff between $…$".
Later when generating the HTML you just need to ensure the right set of templates (group) is selected.
Especially when the text to generate contains a lot of "fixed strings" this approach seems to be more practical than also passing in the "translated fixed strings" via parameters. And the translators have more context and may even be able to "rearrange" the parameters to better fit into their language.
BTW: the parameter values still need to be translated in Java ("your way" or something similar).
Udo
On 31.08.2011, at 11:46, Henning Verbeek wrote:
> Dear StringTemplate community,
>
> I have the wonderful task of enabling a new JEE6 web service to send
> out nice emails to subscribers. It seemed natural to me to try to
> separate three core concerns:
> - design, layout, pretty looks --> to be owned by graphics / marketing guys
> - localization --> involves texters and translators
> - model, controller, logic --> done by the engineer
>
> My desired approach was like this:
> 1) designer to draws up a pretty email with text elements, sample
> data; produces HTML file (and related artifacts)
> 2) engineer separates HTML file into template, fixed strings (for
> localization) and model/controller
> 3) the designer can still open up and edit the template (to a degree)
> to adapt / change it
>
> Not having had any experience in either Velocity, FreeMarker or
> StringTemplate, I followed recommendations of "simplicity" and "best
> separation of concerns" and started using ST4. So far, it's been a
> rocky start, unfortunately, and I am wondering what I'm doing wrong
> (or if it's supposed to be like this).
>
> Firstly, I have not noticed any specific support for localization. We
> are preferring GNU Gettext, because of its toolchain and workflow when
> involving external translators. So far, I've been filling fields in
> the template with st.add("someField", i18n.tr("Original string {0}",
> someVariable)). Works, but maybe there is a better approach?
>
> Secondly, and this is a *real* struggle for me: The syntax of the
> template files appears to me so complex that I cannot give this out to
> a graphics designer / marketing person! No CR/LF allowed, need to
> prefix a template with formal arguments, etc. I'm struggling with the
> statement 'templates, which are really just "documents with holes"' --
> to me it seems more like yet another DSL, which a graphics designer
> won't be able to understand.
> Looking at the documentation, it seems that maybe StringTemplate 3 is
> a better fit for me... could that be?
>
> Please allow me to apologize for this blunt email. A lot of people
> seem to be very happy with StringTemplate, and a lot of people seem to
> use it to generate HTML pages. I want to be one of them, at the moment
> I'm struggling with that!
>
> Thanks for your help!
> Cheers,
> Hank
>
> --
> http://www.pray4snow.de
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list