JContentSubscription — Pay and Read Content Component
News Joomla Components arrow Tutorials arrow Development tips and tricks arrow Joomla 1.5 auto creation of Language file
Joomla 1.5 auto creation of Language file
Thursday, 18 January 2007

It is not very pleasant either keep entering new items in language file or later look through all the code and compile it to lang file. That is nice system to store languages in UTF8 in en-GB.com_mycomponent.ini file. I think that is smart enough and can make Joomla internalization simple. So as I am quite lazy so I thought of way of automatic language file creation.

First thing you will need to do is create your own text class. And it is actually the best development practice. Let's say

  1. <?php
  2. Class myText extends JText {
  3. function _($text)
  4. {
  5. return parent::_($text);
  6. }
  7. }
  8. ?>
 

Place it before you ever use JText::_(‘str'). Then do butch replace and replace all ‘JText::_(‘ to 'myText::_(' in all php files of your project. Also after that use only this class to display the text.

Now everything should work the same way. The only thing is that you now can process any text before it is displayed. I think that most of you already guessed what else is needed to be done. But I have still one suggestion. Do not process text exactly to en-GB.com_mycomponent.ini. Save it to lang.txt and later revise it and update en-GB.com_mycomponent.ini.

Here is the full code I use for that but you can develop better code. And if you do please, send it to me and I'll update it here.

  1. <?php
  2. class jcText extends JText {
  3. function _($text)
  4. {
  5. // get file contents into array
  6. $lines = file('lang.ini');
  7. // flip twice to delete double lines if occur
  8. $lines = array_flip($lines);
  9. $lines = array_flip($lines);
  10. // switch to caps
  11. $utext = strtoupper($text);
  12. // insert line
  13. if(!in_array($utext, $lines))
  14. {
  15. $lines[] = $utext;
  16. }
  17. // save file
  18. file_put_contents(
  19. 'lang.ini',
  20. str_replace("\n\n", "\n", implode("\n", $lines))
  21. );
  22. return parent::_($text);
  23. }
  24. }
  25. ?>
 
Comments (6)Add Comment
...
written by love, July 24, 2007
smilies/smiley.gif smilies/wink.gif smilies/wink.gif smilies/wink.gif smilies/smiley.gif smilies/smiley.gif smilies/smiley.gif
nice code.
written by love, July 24, 2007
Hello its very nice code...sample
dd
written by dd, August 30, 2007
ddfggggggggggggggggggggggggg
gfhjgh jfgh gh ghj f jfg
written by fghdfghdf, December 12, 2007
ghjfgj gfgjfhjfjg ghjf g g
...
written by fghdfghdf, December 12, 2007
gfh dfghdghfgdf gdfghdfgh
dfh dfghdfhdghfhdf dfgh dghdhdfgh
written by fghdfghdf, December 12, 2007
ugfy rt ertdgdfbg dfghdfgh dfghdfghd d dfgh dfghdfghdfh dfhgdfg df dfh

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

busy
Last Updated ( Friday, 16 March 2007 )
 
< Prev   Next >
Address: Joomla Equipment, Box 1951, Bishkek, 720000, Kyrgyzstan
Telephones: Office: +996 312 68-91-34, Mobile: +996 543 91-81-42
More contacts...