Wednesday, 03 August 2011 04:10

Bringing "JText" translatable strings to Javascript in Joomla 1.5

Written by 

joomlaJoomla 1.6 (and now, 1.7) has advanced Joomla's codebase leaps and bounds beyond Joomla 1.5. However, for extension developers, supporting both at the same time can be difficult as keeping completely seperate codebases is sometimes necessarily to take advantage of new features. Developers are left with tough choices about which to support, and how to keep the codebase simple so that they can reach the broadest audience and not cause undue stress on either those adopting newer versions of Joomla, or those maintaining their older sites.

With Weever Apps we have the same issue, and are sharing a solution for bringing at least one feature from 1.6 back to 1.5: language support for Javascript.

In Joomla 1.6 and 1.7, it is currently very easy to add translatable strings to one's Javascript codebase. The code is fairly simple:

 Joomla.JText._("YOUR_STRING"); 

This needs to be preceded in a Joomla extension with an equivalent PHP method, that tells Joomla to prepare a particular language string for Javascript use, like this:

 JText::script("YOUR_STRING"); 

The support for this doesn't exist in the Joomla 1.5 core (and never will), which can create the urge to fork Javascript files into 1.5 and 1.6+ versions. However, we've added our latest open source code contribution, "jsJText" on GitHub for any Joomla extension developer out there looking to reduce the strain of code forking. It proves code for your project to use to add this functionality on 1.5 implmentations.

We hope this code is useful, but only useful for a while -- obviously no Joomla extension developers can yet afford to ignore 1.5. So for the time being, we will be glad if this helps someone looking to transition their extension to 1.6 with a little more ease.

jsJText on GitHub: https://github.com/rgeraldporter/jsJText

1 comment

  • Comment Link SEO Chennai Thursday, 12 April 2012 21:31 posted by SEO Chennai

    Sure this will help my developer team who are working on Joomla sites! Thanks for the article!

Leave a comment

A Quote for your Consideration:

"By selling a solar panel, you are
selling the idea of a better future."

Source: Viktor Tchernikov (a CartaNova client) at Solarnetix Inc.