Text Size
Sunday, May 20, 2012
Get a look down
JavaScript >> Displaying items by tag: translate string
Displaying items by tag: translate string

Here's how you can make a string translatable in your javascript files loaded in Drupal.

1
2
3
4
5
6
7
8
// This little code will append a <div> to the body.
// The <div> contains a translatable string "Hello world!"
// You can translate this string easily in the Back office
// of your website by browsing this url : 
// http://you.website.here/admin/build/translate/search
// and search for Hello world!
// PS : it's a case sensitive input
$('<div>'+Drupal.t("Hello world!")+'</div>').appendTo('body');
Published in Code snippets
Usefull tricks