A while back, I posted an article that discussed a mechanism for customising the client-side i18n mechanism in the play framework.

I received a comment on that article earlier that reinforced some issues I had with this approach. In retrospect, I would have done it very differently, and this is the approach I’ll be taking in the future, albeit with better tag and controller names.

Tag: myI18n.html

${controllers.MyI18n.get(_key)}

Controller: controllers.MyI18n

public class MyI18nContrller extends Controller
{
    public static String get(String key)
    {
        // make a call to the db, static properties file, dynamic text, whatever, here
    }
}

Usage in a template:

#{myI18n key:’foo’}

The tag could of course be expanded to include parameters.

This is a much cleaner and more efficient way of doing what I suggested in the earlier post.

Thanks to Stephen for his comment that prompted this post.

Leave a Reply

Your email address will not be published. Required fields are marked *