I'm presuming it's the Joomla Language Switcher module which you're using to switch languages.
In this case, this module has to generate the links which are behind the little flag symbols.
It does this by calling the getAssociations()
method of a HelperAssociation class for your component, as described at
https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_Associations#Front_End. The Language Switcher module looks to get back an associative array, the array key being the language code, and the array value being the url for the corresponding item in that language. It then outputs a little flag symbol associated with the language code, and puts a link to the associated url.
So inside your component source code directory create a (site) helpers
folder (if not already there), and inside a file called
association.php
put the code for your YourcomponentHelperAssociation
class and the getAssociations()
method.
I'm not totally sure what way your component data is set up, but I think you're saying that you use the same id for the same
item in different languages. So if that's the case, you'll want something like what's below. (Replace "yourcomponent", "yourviewname", "yourviewname" with appropriate strings).
<?php
defined('_JEXEC') or die;
JLoader::register('CategoryHelperAssociation', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/association.php');
abstract class YourcomponentHelperAssociation extends CategoryHelperAssociation
{
public static function getAssociations($id = 0, $view = null)
{
$input = JFactory::getApplication()->input;
$view = $view === null ? $input->get('view') : $view;
$id = empty($id) ? $input->getInt('id') : $id;
if ($view === 'yourviewname')
{
if ($id)
{
$languages = JLanguageHelper::getContentLanguages();
$return = array();
foreach ($languages as $language => $details)
{
$link = 'index.php?option=com_yourcomponent&view=yourviewname&id=' . $id . '&lang=' . $language;
$return[$language] = $link;
}
return $return;
}
}
if ($view === 'yourcategoryview')
{
return self::getCategoryAssociations($id, 'com_yourcomponent');
}
return array();
}
}
Otherwise, follow the example in the Joomla MVC tutorial.