Forum


New Joomla Component - DeepL Machine Translations for Joomla

More
2 months 3 weeks ago #47461 by Vince Wooll

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #47477 by ssnobben
Interesting!

Can you use it for other Joomla components too? you need some plg or..?

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #47478 by Vince Wooll
Note, it's no longer a freebie, I'll update the links afterwards.

Short answer : Maybe!

Long answer : Probably not right now.

I wrote the component to work off plugins, currently supported are articles and categories. Because I haven't tested it to work with other components just yet, it's likely that some of the assumptions in the code (e.g. multilinguage association functionality) may well fail.

Here's the contents of the com_content.php plugin script :
 
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

class DeepL_Component_Com_Content 
{
	/**
	* Construct the component item's table data
	*/
	public function __construct(  ) {
		$this->tables['#__content'] = array  ( 
			"id_column" => 'id',
			"cat_table" => '#__categories',
			"cat_id_column" => 'catid',
			"cat_title_column" => 'title',
			'title_column' => 'title', // This is what's displayed in the content item list
			'language_column' => 'language', // Duh
			'edit_route' => JRoute::_('index.php?option=com_content&task=article.edit&id='),
			'trash_status' => '-2', // Items with this status will not be included when listing them
			'status_column' => 'state', // The column where the status is stored
			'create_associations' => true,
			'columns' => array ( // These are the columns that contain content that we want to display
				'title' => true,
				'alias' => true,
				'introtext' => true,
				'fulltext' => true,
				'metadata' => array( "model" => "serialized" , "elements" => array ()  ) // Any elements not in the array will be treated as un-translatable
			)/* ,
			'truish_columns' => array ( // Some columns have parameters that need to be translated, but the keys themselves need to be retained. Todo?
				'metadata'
			) */
		);
	}
	
	/**
	* xxxxx todo
	*/
	public function get_translatable_items( $model = '' , $elements = array() ) {
		if ( trim($model) == '' ) {
			throw new Exception("Error, model is empty ");
		}
		
		if ( !is_array($elements) ) {
			throw new Exception("Error, elements not an array ");
		}
	}
	
	/**
	* Save the content hash
	*/
	public function save_content_item($content) {

		$table = JTable::getInstance('Content', 'JTable', array());

		$data = array(
			'catid' => $content->catid,
			'title' => $content->title,
			'introtext' => $content->introtext,
			'fulltext' => $content->fulltext,
			'state' => 1,
			'language' => $content->language
		);

		// Bind data
		if (!$table->bind($data))
		{
			$this->setError($table->getError());
			return false;
		}

		// Check the data.
		if (!$table->check())
		{
			$this->setError($table->getError());
			return false;
		}

		// Store the data.
		if (!$table->store())
		{
			$this->setError($table->getError());
			return false;
		}
		return $table->id;
	}
	
	private function setError($error) 
	{
		JFactory::getApplication()->enqueueMessage($error, 'warning');
	}
	
	/*
	
	Move an article to a new category
	
	//	$DeepL_Components->change_category( 15 , 14 , $query_details['table'] );

	*/
	
	public function changeCategory ($articleId = 0 , $newCategoryId = 0 , $table = '' )
	{
		if ( (int)$articleId == 0 ) {
			throw new Exception("Error, articleId is empty ");
		}
		if ( (int)$newCategoryId == 0 ) {
			throw new Exception("Error, newCategoryId is empty ");
		}

		$db = JFactory::getDBO();
		$query = $db->getQuery(true)
				->update($db->quoteName($table))
				->set($this->tables [$table]['cat_id_column'] . ' = '. (int) $newCategoryId)
				->where('id = ' . (int)$articleId);
			$db->setQuery($query);
		try {
			$db->execute();
		}
		catch (RuntimeException $e) {
			$this->setError($e->getMessage());
			return false;
		}
		return true;
	}
}

Follow me on twitter
Do not send me PMs, if you need to contact me use the ticket system.
Read this before you customise Jomres files

Please Log in or Create an account to join the conversation.

ABOUT US

Vince portrait smallaladar

Developed and maintained by Vince Wooll and Aladar Barthi, Jomres was initially conceived in early 2005 as a Mambo based solution to a client’s hotel management needs. While it wasn't originally expected to be an online booking system it quickly morphed into one as users requested more and more features.

As the number of feature requests grew Vince knew that he would need to dedicate more time to the project and in July 2005 Jomres was formally released as a commercial project. Since then, Jomres has become one of Mambo’s, and now Joomla’s, longest running projects. It has survived various versions of Mambo, then Joomla 1.0, 1.5, 1.6, 1.7, 2.5 and 3.

Aladar joined the project in 2010 after using Jomres for his own projects. He was active on the forum, helping other members of the community and eventually Vince invited him to join the team. He has since become an integral part of the project and has contributed significantly to it's development over the years.

Whilst not formally part of the Jomres project, Rodrigo Rocco and the team have become firm friends. Rod is a freelancer who specialises in doing custom work for Jomres users and developing custom plugins for the system that take advantage of it's modular design. He has built many useful extensions including his fabulous new Valentina Template Package.

 

Jomres and the Jomres Logo is trademarked and can't be used without written consent from the owner.

www.jomres.net is not affiliated with or endorsed by the Joomla! Project, Open Source Matters or the WordPress project. The Joomla! & WordPress names and logos are used under a limited license granted by Open Source Matters and the WordPress Projects.

© Copyright 2005 - 2018 Woollyinwales IT.