[development] JavaScript translation and themeing

Andre Molnar mcsparkerton at yahoo.co.uk
Fri Jun 8 22:37:54 UTC 2007

This is great news.  A very welcome change indeed.  There was great
potential for duplicated code the old way.  Thank goodness for

Konstantin Käfer wrote:
> Hi all.
> Today, a patch went in that brings translation of JavaScript files and
> theming to Drupal. There are new JavaScript functions called Drupal.t(),
> Drupal.formatPlural() and Drupal.theme(). The usage of these functions
> is pretty much like their server side equivalent. Thus, you are now
> required to wrap your strings in JavaScript files in Drupal.t() calls,
> just like you wrap t() around them in PHP code.
> Drupal.theme() is a client-side themeing function for JavaScript. It is
> pretty simple (just several bytes), yet rather powerful. If you have to
> add HTML code to the page using JavaScript, you should create a theme
> function in the Drupal.theme.prototype namespace. Themes can override
> these default theme functions by adding a function to the Drupal.theme
> namespace. These theme functions can for example be placed in the
> script.js file in the modules root directory. This file is now
> automatically added to the page (if present), just like style.css.
> JavaScript theme functions can return about anything, a plain HTML
> string, an array of jQuery objects, a regular expression etc. It is
> advised to return an object (= array with indexes) of jQuery objects, so
> that the actual module code can easily determine which objects to modify.
> Thanks to Gábor who continuosly reviewed this patch and brought it to a
> rtbc state.
> Konstantin Käfer – http://kkaefer.com/

More information about the development mailing list