Keyword

How translate items in k2

More
12 years 2 months ago #101102 by Max
How translate items in k2 was created by Max
Hello

I've bought a template at templatemoster.com (well my cliente do it :dry: ) when I install the joomla provider (2.5.6), I have to install sample data, and when I finish k2 is just installed.

After I installed joomfish to translate, version 2.5.0 (Tarw), one that works with k2.

Well k2 not appears in joomfish, and I google for information, but the way , maybe because is for older version doesn't works.

I would like someone could tell me one way to translate items, it could be with joomfish or the a diferente way. But I need to it somehow.

thanks in advance !

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

More
12 years 2 months ago #101103 by william white
Replied by william white on topic Re: How translate items in k2
I havent used joomfish, but since when installing k2 (all versions) there is an error/warning after installation, that says something like "while installing k2 we did not find joomfish"
I assume that if it found it it would add or do something else in the install routines, May want to try installing in steps and putting joomfish first before k2

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

More
12 years 2 months ago #101104 by Max
Replied by Max on topic Re: How translate items in k2
I copy all XML files from contentelement to libraries\joomfish\contentelement\contentelements and I can translate items, but first in joomfish translate does's appear categories, and then the most important, In k2 item list do not appear the item translate.

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

More
12 years 2 months ago #101105 by Max
Replied by Max on topic Re: How translate items in k2
Hi,

I put the relation between items in joomfish database, and I get item ID by SQL.

But now I need somethig, that I can get with default joomla functions. What I need is get the URL of an item by its ID.

I have item ID, I need the function that K2 use to get the URL.

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

More
12 years 2 months ago #101106 by Max
Replied by Max on topic Re: How translate items in k2
Well, Now I resolve in a way. Joomfish future, the pre version before the realise do not work to me with k2. So I fill table #__js_traslationmap to make realtionship to items in differents languages.

Then I override the method rerouteCurrentUrl in class JFRoute (libraries/joomfish/route/jfroute.php

This is the new code (there is part I am not sure).



public function rerouteCurrentUrl($code=null)
{

$vars = $this->getSafeVariablesFromRoutedRequest();
/* Take care of this if, I am not really sure */
if($vars == 'item' && ($vars==$vars) && $vars = 'com_k2'){

$id = preg_replace("/[^0-9]/","",$vars);



if($vars==$code){

return urldecode(JRoute::_(K2HelperRoute::getItemRoute($vars)));
}else{
/* nl because is my default site language, if you know how to get this value, please tell me */
if($code!='nl' && $vars!='nl'){
$query = "SELECT T.translation_id as k2_id,K.alias as alias FROM #__jf_translationmap T ".
"INNER JOIN #__k2_items K ON (K.id = T.translation_id) ".
"WHERE T.reference_id = (SELECT TM.reference_id FROM #__jf_translationmap TM WHERE TM.translation_id = $id) ".
"AND (SUBSTR(T.LANGUAGE,1,2) = '$code') AND (T.reference_table = 'k2_items') ";

}else if($vars!='nl'){
$query = "SELECT T.reference_id as k2_id,K.alias as alias FROM #__jf_translationmap T ".
"INNER JOIN #__k2_items K ON (K.id = T.reference_id) ".
"WHERE (T.reference_table = 'k2_items') AND (T.translation_id = $id)";
}else{
$query = "SELECT T.translation_id as k2_id,K.alias as alias FROM #__jf_translationmap T ".
"INNER JOIN #__k2_items K ON (K.id = T.translation_id) ".
"WHERE (T.reference_table = 'k2_items') AND (T.reference_id = $id) AND (SUBSTR(T.LANGUAGE,1,2) = '$code')";
}
}

if(!empty($query)){
$db = JFactory::getDBO();
$db->setQuery($query);
$result = $db->loadObject();

if($result){
$url = urldecode(JRoute::_(K2HelperRoute::getItemRoute($result->k2_id.':'.urlencode($result->alias))));
$url = str_ireplace('/'.$vars.'/', '/'.$code.'/', $url);
return $url;
}
}
}

// @Todo if this is not default language this vars might be wrong due to translated path!

$router = JFactory::getApplication()->getRouter();
$uri = JURI::getInstance();

/////// 1. save current lang codes for later ///////////////////////////////////////////
$currentlang = isset($vars) ? $vars : null;
$currentJoomlaLang = $this->_conf->get('language');

/////// 2. set lang code in router and JURI vars to $code, push it to the router
$vars = $code;
$uri->setVar('lang', $code);
$router->setVars($vars, false);


/////// 3. swap menu values with translated ones ////////////////////////////////////////

// switch active translation language
$this->switchJFLanguageShortcode($code, true);

JFactory::$language = null; // reset language instance as JFDatabase->setLanguage uses JFactory::getLanguage()

// get translated menu
$menu = JFactory::getApplication()->getMenu();
$menu->__construct(); // force re-loading of the menu

// fix item routes for this item as routing is based on active menu $item->route
// and translated query doesn't change menu routes
//
not needed as it is done in menu override for all items
/*$itemid = $vars ? $vars : JRequest::getInt('Itemid');
$menuitems = & $menu->getMenu();
$this->fixMenuItemRoutes($menuitems, $itemid);*/

/////// 4. route vars //////////////////////////////////////////////////////////////////
$varstring = 'index.php?'.$uri->buildQuery($vars);
//$varstring = 'index.php?lang=nl&option=com_k2&view=item&id=92';
//$currenturl= $uri->toString(array('path', 'query'));
$absolute = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$routedurl = $absolute . JRoute::_($varstring, true, $uri->isSSL());

/////// 5. reset everything to the previous state so we don't affect anything //////////
$vars = $currentlang;
$uri->setVar('lang', $currentlang);
$router->setVars($vars, false);
$this->switchJFLanguageShortcode($currentlang, false);
$this->switchJoomlaLanguageLongcode($currentJoomlaLang);
JFactory::$language = null;
$menu->__construct();

// fix url if we are using sef domains
$this->prefixToHost($routedurl);



return $routedurl;

}


P.S. I have problems with captcha in this forum, sometimes it's really dificut, Captcha yes, but easier please.

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


Powered by Kunena Forum