I am working on a html template and dissecting it (Suitecommerce Reference Impl to be more specific - an ERP solution which comes with webfront features).
Here's a snippet from the template.
<li>
<a href="#" data-touchpoint="customercenter" data-hashtag="#ordershistory">
<%= _('Order History').translate() %>
</a>
</li>
The % tag between normal html tags are written in backbonejs and underscorejs.
Since underscorejs functions take _.function() form, I don't get the purpse of _('string').
Any backbonejs/underscorejs developers out there?
When you call _(obj)
Underscore wraps the obj
argument. Then any Underscore methods can be called on the wrapped object without having to modify the prototype of obj
.
It appears that one of the libraries that you are using has added the translate()
method to the Underscore prototype and the _(string).translate()
is the way to call that method on your string.
Here is another example of extending Underscore in a similar manner:
_.mixin({
logToConsole: function(str) {
console.log(str)
}
})
_('text to log').logToConsole()
References: