We are using OOTB CQ.i18n.getMessage for localized JQuery Messages. everything is working as expected on Auhor instances but on Publish , it is throwing CQ is not Defined, CQ.i18n is not defined JAVA SCRIPT Errors.
Do we need to enable any extra JS call or include any JS file into the clientlibs? Any pointers to this would be apreciated.
In author, you are running "inside of the CQ environment", and then the client libraries that defines and communicates with the CQ instance in initiated. On publish, you are running the scripts on the client machine. That environment has no idea about CQ.i18n, since that call does not generate a REST call to the server. It is different execution envrionments.
Solution: Have a block in the server side generated code that fills a js object with the correct translations or create a REST/JSON representation of the i18n-nodes.
Taking Alex and Vinzenz perfect answer from the Google Group (https://groups.google.com/forum/?fromgroups=#!topic/day-communique/EZxBdGUwcQU).
Disclaimer for CQ5.4
In CQ 5.4 the i18n utility class was not yet part of the clientlib "cq.shared" but of "cq.widgets". You would have to load latter but this is not recommended on a publish instance since it is rather big (containing all the widgets required for page authoring and admin consoles). You probably would have to extract the i18n part and for example add it to "cq.shared" manually.
Message was edited by: Ove Lindström Excelent answer.