2

I managed to rewrite system plugin "Language Manager", so now it saves texts for different languages to Database (DB).

Now I do not know how to rewrite JText (that is present across all the application code) so it takes text for each languages directly from the DB and not from the local files. The same thing I need to do for "Language Manager" to take data from DB only.

I would appreciate your help! Thank you

2 Answers 2

3

Instead of overwriting or modifying the JText class why not just write a function call function in your model that retrieves your translation from the database and return the string?

Echo the string in your view after including your model:

//INCLUDE AT THE TOP OF THE LAYOUT FILE
$mymodel= JModelLegacy::getInstance('ViewName','MyComponentNameModel');

//ECHO OUT TRANSLATION WHERE YOU NEED IT
echo $mymodel->getTranslation('MY_TRANSLATION_STRING');

Put this in your model file:

public function getTranslation($string)
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $sql = "SELECT text FROM #__mycom_translations WHERE translation = '$string'";
    $db->setQuery($sql);
    $row = $db->getObject();
    return $row->text;
}
10
  • I thought to do so but there is also a built-in language manager interface in backoffice (admin area) that should retreive the text from DB and not from files. (It already saves to DB but not yeat read from it)
    – Alex Ros
    Jul 20, 2016 at 13:54
  • That is not how the language override feature works. The values are not store in the database. The language table in the database only stores a record of what langs are currently installed for your Joomla installation. When you add a language override all it does it write your constant and value to the language/overrides/en-GB.override.ini file in the root of your web folder.
    – Terry Carter
    Jul 20, 2016 at 18:34
  • Unless you are using some custom component that is handling language for you that is. The method I posted above should be the most efficient way to handle custom language strings stored in the database.
    – Terry Carter
    Jul 20, 2016 at 18:35
  • Thank you Terry Carter, This is only solves one part of problem: the UI output . But as I use multiples instances on AWS I can not save and output this into files.
    – Alex Ros
    Jul 21, 2016 at 22:15
  • Using my method there's no need for files, only a database table
    – Terry Carter
    Jul 22, 2016 at 1:19
1

I can´t give you a complete answer but maybe a couples of clues to help you solve it.

JText class is located here:

libraries\joomla\language\text.php

Maybe you can override the JText Class with your own and use DB instead of files in your version.

And load it before the core one so It won't be loaded at all.

see here:

http://www.informit.com/articles/article.aspx?p=1858258&seqNum=8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.