Twitter
Mon
28
Apr
'08
PDF
Print
Send
 
Hits (6225) | Comments (6) | Favorited (0) | Votes (1)

Mighty Language (JSL) component is very powerful Joomla 1.5 native component development tool, that allows to easily create language files for components you develop.  Not only create core language file but also compare all translations and adding new indexed there. So you don’t anymore need to go manually through all the components files looking for all text and covering it into uppercase indexes and values in language file. Is in it boring? I hate this routine job. And this is why this component was created. To make us happy and concentrate on developing real features.

How it works

JSL Component looks through all your .php and .xml files except installation xml files and looks for strings that are needed to be included in the language file. In the PHP files it looks for all texts placed into JText class, and in the XML files it looks for tag attributes. They are:

  • label
  • description
  • group
  • and everything in the between of <option> and  </option> tags

When JSL parses the component it saves all the Found Strings in the _ROOT_/ administrator/languages/en-GB/ folder for the back-end and _ROOT_/languages/en-GB/ for fromtend with en-GB.component_name.ini (i.e en-GB.com_banners.ini) file name.

The language files for the Frontend and Backend are different. In the frontend language files are only strings that are found in the frontend folder of the component and in the backend language file only strings that are found in the backend folder of the component.

If en-GB language files existed before parse, JSL saves all indexes and its translations of old file except not found one. Those are deleted. That means if you had string

Echo JText::_(&lsquo;This is the test&rsquo;);

After first parse THIS IS THE TEST=This is the test line will be added to language file and if you delete this string from the code, THIS IS THE TEST=This is the test will be deleted on next parse.

On other hand if you changed THIS IS THE TEST=This is the test to THIS IS THE TEST=This is NOT a test, and do not delete Echo JText::_(‘This is the test’); from the code, index and its value will be kept on next parse.

If you want to add indexes that is not present in the code or simple is not found by JSL, they will be always deleted on each next parse. To solve this you should place those in CUSTOM ENTRIES section.

#**    CUSTOM ENTRIES    **#
CUSOMTEXT=Here is the custom text that you would like to be added and that JSL could not find
#**    CUSTOM ENTRIES    **#
#----------FOUND WORDS--------------
ABOUT=About
ACCESS=Access
ACCESS LEVEL=Access Level

JSL have few reasons not to find indexes.

  • When JText is called inside function of core Joomla classes. For example
    <?php echo JHTML::_('grid.sort',  'Access', 'groupname', 
        $this->lists['order_Dir'], $this->lists['order'] ); ?>
     

    Here Access is treated by Text inside JHTML::_() function.

  • When you have to put text into JText like variable

    <?php echo JText::_($text)?>


Those are cases when you can place those indexes into CUSTOM ENTRIES  section.

JSL saves en-GB language files in Joomla standard language folders. Joomla_root/languages/en-GB/ and Joomla_root/administrator/languages/en-GB/

Extending the Your Language Files

One of the most routine and hard job in translation is a maintains of already translated files. In particular to look indexes that is added in en-GB language file on new parse and add them in to other language file for passing it to translator for future editing. JSL can do this for you automatically.  

To enable this process you need to create folder names Language in component root as in front-end as in back-end. (i.e administrator/components/com_juser/languages and components/com_juser/languages) Put your language files other than English there accordingly. I mean translations for front-end to front-end component/languages folder and admin to back-end.  So when you parse the component, new indexed not found in  language file will be added with the empty values and already translated strings will remain untouched. You can have as many different files in languages folders as you want.

Development Suggestions

Here are few rules that you should follow for JSL component to work correctly.

Rule 1: Always Use JText class Functions.

When you are printing any kind of text to the browser except HTML tags make sure that you are using one of the JText class’s functions.
The functions are:

  • JText::_(“Your Text”);
  • JText::sprintf(“Your text  %s”, variables…);
  • JText::printf(“Your text  %d”, variables…);

The text can be taken in double quotes(“text”) or single quotes(‘text’). If text is not in the any of these functions then it will not be added in the language file.

Rule 2: Avoid using variables inside JText

When you put parameter into JText::_() function, avoid put it as variable.

Incorrect:

<?php
$var = &ldquo;Some String Here&rdquo;;
Echo JText::_($var);
?>

Correct:

<?php
Echo JText::_(&ldquo;Some string here&rdquo;);
?>

Correct 2:

<?php
$var = JText::_(&ldquo;Some String&rdquo;);
Echo $var;
?>

And for JText::printf() functions:

Incorrect:

<?php 
$placeholder = &ldquo;Your age is %d and your name is %s&rdquo;;
JText::printf($placeholder, $age, $name);
?>

Correct:

<?php 
JText::printf(&ldquo;Your age is %d and your name is %s&rdquo;, $age, $name);
?>

And for the JText::sprint() is the same:

Incorrect:

<?php 
$placeholder = &ldquo;Your age is %d and your name is %s&rdquo;;
JText::sprintf($placeholder, $age, $name);
?>

Correct:

<?php 
$output = JText::sprintf(&ldquo;Your age is %d and your name is %s&rdquo;, $age, $name);
Echo $output;
?>

Comments
HonzaAvatar
Quote
- -
Written by Honza VIP on 23 November 2008

Hi, sounds clear, but could you give us full example please?

Thanks a lot!

-
avatar
Quote
- -
Written by Fernando on 05 January 2009

It is very good the explaination done. Now i have the use of these functions very more clear. Thanks.

-
avatar
Quote
- -
Written by nobbe on 10 January 2009

Hi,

thanks for this really helpful extenstion.

However there is a small bug in Version 1.0 leading to empty language files for the frontend part of a component. In line 126 of controllers/components.php new words are added to the admin part instead to the frontend part.

The line should be changed to:

$this->_addFoundWord($m,'front');

-
nikitakvAvatar
Quote
- -
Written by nikitakv on 14 January 2009

Hi I am trying to view this article in FF3 and part of it (about 30px) on the right side is cut off... cannot finish reading sentances properly.

-
yodazAvatar
Quote
- -
Written by yodaz VIP on 27 May 2009

it also cutts off in chrome

-
avatar
Quote
- -
Written by david on 13 June 2009

how did the spammers get by the captcha?

-
Add New Comment
Name:
Email:
Comment:
Attachment
Hide Comment
Security code:
Enter text as you see on image
 
 
What is best way for Download/Installation MightyExtensions?
 


Member Area



Member Activity

We have 1137 guests and 8 members online


MightyTemplate - Professional Joomla Templates