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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -