In Freemarker, how to translate each string in a list individually, then join the result -
my model contains list of two-letter language codes, eg (pseudo-code):
${info.languages} = [en, jp, mi] i have mark-up in template formats these semicolon-space-separated list:
<#if info.languages??> ${info.languages?join("; ", "")} </#if> which gives
en; jp; mi
i'd show english name each language code in semicolon-separated list instead. know can use locale#getdisplaylanguage lookup in java, i'm not worried actual translation part.
my question how tie template while still taking advantage of join built-in. guess ideally i'd want able chain operators so:
${info.languages?displaylanguage?join(", ", "")} but it appears ?xyz syntax reserved core built-ins.
tl;dr: there way combine custom function join built-in? or else useful i'm overlooking? or choice have custom function joining translation?
?join pretty exists convenience, address common case. in more generic cases should use #list. example:
<#list info.languages lang>${my.displaylanguage(lang)}<#sep>, <#/list> of course if on multiple places, should move snippet macro.
as of ?xyz thing (they called built-ins), yes, it's reserved template language.
Comments
Post a Comment