Forum Discussion

miikka's avatar
miikka
Maven
9 years ago

Functions in text keys

Hi,

we are using functions in a few text keys in our community, here's an example:

page.ForumTopicPage.replies-count.text             = {0} {0,choice,0#Replies|1#Reply|1<Replies}

This works mostly great and gives you the option to really fine-tune the copy text based on the reply count.

 

In the Russian language we would need to go one step further and decide the text to be shown based on the last digit of the reply count. 

 

I have not been able to find any documentation about this approach or how/which functions can be used in text keys so has anyone come across anything related?

 

Cheers,

.M

  • AndrewF's avatar
    AndrewF
    Khoros Oracle

    We utilize Java's MessageFormat API. The syntax documentation is a little bit hard to read, but it can be found here: MessageFormat

    According to the doc, these are all the options:

    • {0}
    • {0,number}
    • {0,number,integer}
    • {0,number,currency}
    • {0,number,percent}
    • {0,number,.......} according to the format defined by DecimalFormat
    • {0,date}
    • {0,date,short}
    • {0,date,medium}
    • {0,date,long}
    • {0,date,full}
    • {0,date,.......} according to the format defined by SimpleDateFormat
    • {0,time}
    • {0,time,short}
    • {0,time,medium}
    • {0,time,long}
    • {0,time,full}
    • {0,time,.......} according to the format defined by SimpleDateFormat
    • {0,choice,.......} according to the format defined by ChoiceFormat

     

    Unfortunately, ChoiceFormat is the most complex thing we can support today.

    I will make sure we are tracking this limitation for a potential future enhancement.

  • In the same boat as you, also looking for what "placeholder" functions are actually available for text keys, specifically looking for a way to pass in a boolean into a text key and display two alternative strings, e.g. something like this:

    # text key
    # custom.text.key.boolean = {0,choice,true#Text when true|false#Text when false}
    
    <#-- we then could do something like that: -->
    <#assign text = text.format('custom.text.key.boolean', <boolean_variable>?c) />
    
    

    this unfortunately doesn't work, but the workaround is as follows

    # text key
    # custom.text.key.boolean = {0,choice,0#Text when false|1#Text when true}
    
    <#-- then do that that: -->
    <#assign text = text.format('custom.text.key.boolean', <boolean_variable>?then(1, 0) />

    it works, but maybe the first variant would be more pretty.

    SuzieH can you point us to some documentation that explains/lists the functions available for text keys?

     

    • SuzieH's avatar
      SuzieH
      Khoros Alumni (Retired)

      Hi luk. I'm reaching out to a few people internally to see if they can help out.