The translation helper should be exposed on the client side
We currently have a mechanism to translate strings in Model Processors and in the Handlebar templates, but we are lacking a mechanism to translate strings on the client side.
AEM handles this with the following client side function: CQ.I18n.getMessage('key'). The first invocation of this pulls the entire dictionary for the language associated with the page. This results in fast subsequent lookups, but the first lookup is slow and has a very large response. Additionally, you can't specify which dictionary you'd like to use.
I suggest the following:
- Exposing a translate function on the client side: Bl.translate() that accepts a key and, optionally, a language string indicating which dictionary should be used. If not language string is used, the language of the current page should be used.
- Instead of downloading the entire dictionary, the translate function should always make a call to the server which will only return the translation for the requested key. Compared to the AEM implementation, this will result in more, smaller server requests.
- Optionally, it might be beneficial to allow the translate function to behave similarly to the AEM implementation by downloading the entire dictionary on the first request. This would be useful in cases where the page is generated entirely on the client side, and many, many lookups will need to be done.
@aaron.harder , could you comment on the implementation suggestion above, and weigh in with your thoughts?