Fwd: inject i18 text in javascript variables (jQuery)
-- Forwarded message -- From: Sergueï Cambour Date: Thu, Dec 22, 2011 at 3:37 PM Subject: Re: inject i18 text in javascript variables (jQuery) To: "Thiago H. de Paula Figueiredo" Thanks for your help. I have some more questions: 1. Did you miss ';' in the expression(highlighted red): @BeginRender void addJsLibs() { renderSupport.addScript("loadPass('%s', '%s','%s', '%s', '%s');", messages.get("js.error.password.not_given"), messages.get("js.error.no_confirmed_password"), messages.get("js.error.password_not_matched"), messages.get("js.error.email.not_given"), messages.get("js.error.email.wrong")); } 2. Do I need to add in the top of the class definition the include of js library like that: @IncludeJavaScriptLibrary(value={"context:/static/javascript/password.js"}) public class ForgottenPassword { ... } Thank you. On Thu, Dec 22, 2011 at 2:24 PM, Thiago H. de Paula Figueiredo < thiag...@gmail.com> wrote: > On Thu, 22 Dec 2011 10:35:13 -0200, Sergueï Cambour > wrote: > > Taking in account that the number of classes to modify, I think I'll >> choose the first solution, - using RenderSupport. In this case, I should >> remove >> all the calls to the same js function from all the pages, right? Because >> it's up to Tapestry to inject the same call in the bottom of the page, >> right? >> > > Yep. In addition, Tapestry or not, using inline JavaScript is not a good > thing. > > -- > Thiago H. de Paula Figueiredo > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, > and instructor > Owner, Ars Machina Tecnologia da Informação Ltda. > http://www.arsmachina.com.br >
Re: inject i18 text in javascript variables (jQuery)
Thanks a lot for your replies. It is not so clear for me for the moment. I'm on Tapestry 5.1. In all the 'tml' pages there are calls to some js functions which all are in separate js files, like that, for example: - script type="text/javascript"> loadSomeJSFunction(); - In all those js files all the messages are hard-coded. The question is how to translate them? I believde that there was a way to pass a translates variable or parameter to the js function, smth like that: - script type="text/javascript"> var msgStrings = { msg1 : '${message:js.error.password.not_given}', msg2 : '${js.error.no_confirmed_password}', msg3 : '${js.error.password_not_matched}', msg4 : '${js.error.email.not_given}', msg5 : '${js.error.email.wrong}' }; loadSomeJSFunction(msgStrings); - And then in the js file just use them: - function loadSomeJSFunction(msgStrings) { jQuery('#forgottenPassLink').click(function(event){ event.preventDefault(); var error = false; var email = jQuery('#email'); var emailVal = email.val(); var emailError = jQuery('#email-error'); if (!emailVal) { error = true; email.addClass('error'); emailError.html(msgStrings.msg4); emailError.show(); } } ... loadSomeJSFunction(msgStrings); Not sure it will work. On Thu, Dec 22, 2011 at 12:52 PM, Christian Köberl < tapestry.christian.koeb...@gmail.com> wrote: > 2011-12-22 12:31, Sergueï Cambour: > > Is it possible to translate some javascript popup mesages by injection > the > > translated values from a 'tml' page into javascript function which is in > a > > separate js file? > > There are two options to localize your JavaScript: > 1. add messages in the initializer call > this is what Tapestry's DateField does - look in DateFieldStack > 2. create separate asset for localized part and @Import it > so, you'll have mylibloc.js and mylibloc_de.js and in your > component class you do @Import(library={"mylib.js", "mylibloc.js"}) > > > Thanks > You're welcome :) > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >
Re: inject i18 text in javascript variables (jQuery)
Thansk for the reply. I've already seen that code. The problem is that in that example a class Confirm was created in a javascript file: var Confirm = Class.create(); But as far as I know it is valid only for prototype and for jQuery as it's in my case. The js file uses jQuery. Any other idea? Thks On Thu, Dec 22, 2011 at 12:46 PM, Paulo Ricardo Ribeiro < paulo.rica...@gmail.com> wrote: > Hello > > I Have something like this: > > Delete > > > > So, i guess that, the same way I'm able to get the username, it's maybe > possible to get a i18n message, and pass it to the javascript. > > > (The mixin code is here: > http://wiki.apache.org/tapestry/Tapestry5AndJavaScriptExplained) > > > > > > > > On Thu, Dec 22, 2011 at 11:31 AM, Sergueï Cambour >wrote: > > > Is it possible to translate some javascript popup mesages by injection > the > > translated values from a 'tml' page into javascript function which is in > a > > separate js file? > > > > Thanks > > >
inject i18 text in javascript variables (jQuery)
Is it possible to translate some javascript popup mesages by injection the translated values from a 'tml' page into javascript function which is in a separate js file? Thanks
How to remove a locale prefix from url
I can't figure out how to remove the locale prefix from the url on Tapestry 5.1. Every time when switching the locale, the url changed as follows: my_host/en/home or my_host/fr/home I fond that it is possible to add the following in the AppModule class: public static void contributeApplicationDefaults(MappedConfiguration configuration) { configuration.add(SymbolConstants.ENCODE_LOCALE_INTO_PATH, "false"); } coupled with LinkCreationListener2 (in the same AppModule class): public LinkCreationListener2 buildLinkCreationListener(LinkCreationHub hub) { LinkCreationListener2 listener = new AppLinkCreationListenerImpl(); hub.addListener(listener); return listener; } But how should I use AppLinkCreationListenerImpl ? I found on the net an example but it does nothing, my local does not switch any more: public class AppLinkCreationListenerImpl implements LinkCreationListener2 { public void createdComponentEventLink(Link link, ComponentEventRequestParameters params) { link.addParameter("locale", String.valueOf(System.currentTimeMillis())); } public void createdPageRenderLink(Link link, PageRenderRequestParameters params) { link.addParameter("locale", String.valueOf(System.currentTimeMillis())); } } Before that, I used PersistentLocale technic: //in my Header class @Inject private PersistentLocale persistentLocale; @Inject private Locale currentLocale; @Persist private String localeLabel; public String getLocaleLabel() { if (localeLabel == null) { if (currentLocale.equals(Locale.FRENCH)) { localeLabel = new Locale("en").getDisplayName(Locale.ENGLISH); } else { localeLabel = new Locale("fr").getDisplayName(Locale.FRENCH); } } return localeLabel; } @OnEvent(component = "switchlocale") void changeLocale() { localeLabel = currentLocale.getDisplayName(currentLocale); if (currentLocale.equals(Locale.FRENCH)) { persistentLocale.set(Locale.ENGLISH); } else { persistentLocale.set(Locale.FRENCH); } } Any idea? Thanks.