How to use text.format
Hello.
I'm working on a custom component and I'm trying to use text.format to localize the copy.
Here's the sentence that I need to localise:
<h4>${notification.target.actor.login} @mentioned you in his post "${subject}"</h4>
and here's the output:
Nicolas @mentioned you in his post "name of the post"
So, now that I need to localise the copy I was thinking of using text.format with some "placeholders".
I was searching and I found on the documentation something about the "text.format" parameters, so I changed my freemarker code into this:
<h4>${text.format( 'this_is_the_string_key_in_admin', notification.target.actor.login, subject )}</h4>
But I'm not really sure of how should the key in the Admin should looks like, so I tried:
this_is_the_string_key_in_admin = $1 @mentioned you in his post "$2"
but the output is not what I was thinking of:
[login: null] @mentioned you in his post "[subject: null]"
Does anybody know what I'm doing wrong or how the localization key should look like?
Thanks.
Nic
Hi nicgutierrez
you can definitely use placeholders in your text keys and pass appropriate variables when you use them
For example , if you defined custom-text-key = "My name is {0}"
Then what you can do is:
<#assign myName = "Slim Shady"> ${text.format("custom-text-key",myName)}
Or even having multiple placeholders and so on ...
Hope it helps!