Get the category id in another language Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
marcovisual
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed May 05, 2021 10:21 am

Get the category id in another language

Post by marcovisual » Wed May 05, 2021 10:31 am

HI,
In my code i get the category from number id:

Code: Select all

$categories->get(27); // Italian category ID
I need to get the category in other language EN.
Like this:

Code: Select all

if(lang == "IT")
   $categories->get(27);
else
  $associationId = ???
  $categories->get($associationId);
I can't figure out how to use:

Code: Select all

use Joomla\CMS\Association\AssociationExtensionHelper;
Can someone help me?
Thanks
Marco
Last edited by imanickam on Wed May 05, 2021 2:35 pm, edited 1 time in total.
Reason: Moved the topic from the forum General Questions/New to Joomla! 3.x to the forum Joomla! 3.x Coding

illovo
Joomla! Intern
Joomla! Intern
Posts: 88
Joined: Sun Jan 13, 2013 9:30 am
Contact:

Re: Get the category id in another language

Post by illovo » Sat May 08, 2021 11:14 pm

Joomla 3:

Code: Select all

JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
$associations = CategoriesHelper::getAssociations($id, $extension);

// e.g. $associations = CategoriesHelper::getAssociations(27, 'com_content');
Not tested.

marcovisual
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed May 05, 2021 10:21 am

Re: Get the category id in another language

Post by marcovisual » Mon May 10, 2021 8:24 am

Thanks. I resolved with this:

Code: Select all

$assocId = 27;

if($langTag != "it-IT"){

	$user             = JFactory::getUser();
	$groups           = implode(',', $user->getAuthorisedViewLevels());

	$langAssociations = JLanguageAssociations::getAssociations('com_content', '#__categories', 'com_categories.item', $assocId, 'id', 'alias', '');

	foreach ($langAssociations as $langAssociation)
	{
		$arrId    = explode(':', $langAssociation->id);
		$assocId  = $arrId[0];
	}
	
}

$categoryNodes = $categories->get($assocId);
Regards
Marco


Locked

Return to “Joomla! 3.x Coding”