[yast-devel] WebYaST: javascript per-plugin library
Hi! I'd like to share my observation: I needed to share my javascript code between two files (it was form validation for new and edit action + some more) I created webyast-users-ui/plugins/users/public/javascripts/users_edit.js and included it into my files with <%= javascript_include_tag "users_edit.js" %> It's important to use $pluginname as prefix to be unique in whole project! That's it ... Bye, Michal -- Best Regards, Michal Zugec Software developer --------------------------------------------------------------------- SuSE CR, s.r.o. e-mail: mzugec@suse.cz Lihovarska 1060/12 tel: +420 284 028 960 190 00 Praha 9 fax: +420 296 542 374 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On 26.02.2010 12:36, Michal Zugec wrote:
Hi! I'd like to share my observation: I needed to share my javascript code between two files (it was form validation for new and edit action + some more) I created webyast-users-ui/plugins/users/public/javascripts/users_edit.js
and included it into my files with <%= javascript_include_tag "users_edit.js" %>
It's important to use $pluginname as prefix to be unique in whole project!
That's it ...
Bye, Michal
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string? Bye, Michal -- Best Regards, Michal Zugec Software developer --------------------------------------------------------------------- SuSE CR, s.r.o. e-mail: mzugec@suse.cz Lihovarska 1060/12 tel: +420 284 028 960 190 00 Praha 9 fax: +420 296 542 374 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
* Michal Zugec <mzugec@suse.cz> [Feb 26. 2010 13:08]:
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string?
glesage@suse.de should know ;-) Klaus --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Michal Zugec write:
On 26.02.2010 12:36, Michal Zugec wrote:
Hi! I'd like to share my observation: I needed to share my javascript code between two files (it was form validation for new and edit action + some more) I created webyast-users-ui/plugins/users/public/javascripts/users_edit.js
and included it into my files with <%= javascript_include_tag "users_edit.js" %>
It's important to use $pluginname as prefix to be unique in whole project!
That's it ...
Bye, Michal
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string?
Bye, Michal
Reason is simple, you add javascript to public directory which is jsut served. I already look at this issue (not-supported browser js has same problem) and for me the best solution is to pass from view as parameter translated string as I don't see how we can use dynamic generated js elegant and clean. -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, parts of webyast -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On 26.02.2010 13:22, Josef Reidinger wrote:
Michal Zugec write:
On 26.02.2010 12:36, Michal Zugec wrote:
Hi! I'd like to share my observation: I needed to share my javascript code between two files (it was form validation for new and edit action + some more) I created webyast-users-ui/plugins/users/public/javascripts/users_edit.js
and included it into my files with <%= javascript_include_tag "users_edit.js" %>
It's important to use $pluginname as prefix to be unique in whole project!
That's it ...
Bye, Michal
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string?
Bye, Michal
Reason is simple, you add javascript to public directory which is jsut served. I already look at this issue (not-supported browser js has same problem) and for me the best solution is to pass from view as parameter translated string as I don't see how we can use dynamic generated js elegant and clean.
Put string as a parameter? No, this makes code really ugly! Just untested idea: what about rename file.js into file.js.rb (which is interpreted and strings are replaced) - is it valid to include script with .js.rb instead of .js? -- Best Regards, Michal Zugec Software developer --------------------------------------------------------------------- SuSE CR, s.r.o. e-mail: mzugec@suse.cz Lihovarska 1060/12 tel: +420 284 028 960 190 00 Praha 9 fax: +420 296 542 374 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Michal Zugec write:
On 26.02.2010 13:22, Josef Reidinger wrote:
Michal Zugec write:
On 26.02.2010 12:36, Michal Zugec wrote:
Hi! I'd like to share my observation: I needed to share my javascript code between two files (it was form validation for new and edit action + some more) I created webyast-users-ui/plugins/users/public/javascripts/users_edit.js
and included it into my files with <%= javascript_include_tag "users_edit.js" %>
It's important to use $pluginname as prefix to be unique in whole project!
That's it ...
Bye, Michal
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string?
Bye, Michal
Reason is simple, you add javascript to public directory which is jsut served. I already look at this issue (not-supported browser js has same problem) and for me the best solution is to pass from view as parameter translated string as I don't see how we can use dynamic generated js elegant and clean.
Put string as a parameter? No, this makes code really ugly! Just untested idea: what about rename file.js into file.js.rb (which is interpreted and strings are replaced) - is it valid to include script with .js.rb instead of .js?
It works if you place it at another place, because public is not executed. It is just served. But what do same work for you is partial. define your javascripts in partial and render that partial. It do what you need. Also consider if more modules could benefit from your javascripts. If so then place it in base and announce it so we do not need to do same thing again. -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, parts of webyast -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On 26.2.2010 13:07, Michal Zugec wrote: [...]
And jsuchome pointed me to one ugly fact : strings are not translatable. That's because .js file is not interpreted by rails (to apply translation into <%= _("sometext") %>), it's just send as it is. Any idea how to translate such string?
It depends on the JavaScript, e.g. jQuery validate plugin allows to define custom error messages (which can be translated by gettext). Example: $(document).ready(function(){ // set validation here... $.extend($.validator.messages, { required: "<%= _("This value cannot be empty.") -%>" }); }); But of course this approach is not generic, the JavaScript must allow such redefinition... -- Best Regards Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (4)
-
Josef Reidinger
-
Klaus Kaempf
-
Ladislav Slezak
-
Michal Zugec