<commit_before><?php
class ComLanguagesDatabaseBehaviorTranslatable extends KDatabaseBehaviorAbstract
{
    protected function _beforeTableSelect(KCommandContext $context)
    {
        $application = JFactory::getApplication();
        if($application->getCfg('multilanguage') && $context->query)
        {
            $languages = $application->getLanguages();
            $active    = $languages->getActive();
            $primary   = $languages->getPrimary();
            
            // Modify table in the query if active language is not the primary.
            if($active->iso_code != $primary->iso_code)
            {
                $query  = $context->query;
                $tables = $this->getService('com://admin/languages.model.tables')->enabled(true)->getList();
                
                $table = current($query->table);
                if(is_string($table) && in_array($table, $tables->name)) {
                    $context->query->table[key($query->table)] = strtolower($active->iso_code).'_'.$table;
                }
            }
        }
    }
    
    protected function _afterTableInsert(KCommandContext $context)
    {
        $application = JFactory::getApplication();
        if($application->getCfg('multilanguage') && $context->affected)
        {
            $tables = $this->getService('com://admin/languages.model.tables')->enabled(true)->getList();
            
            // Check if table is translatable.
            if(in_array($context->table, $tables->name))
            {
                $languages = $application->getLanguages();
                $active    = $languages->getActive();
                $primary   = $languages->getPrimary();
                
                $item = array(
                    'iso_code'   => $active->iso_code,
                    'table'      => $context->table,
                    'row'        => $context->data->id,
                    'status'     => ComLanguagesDatabaseRowItem::STATUS_COMPLETED,<commit_msg>Auto-join the translations table to get status of translation. re #215<commit_after><?php
class ComLanguagesDatabaseBehaviorTranslatable extends KDatabaseBehaviorAbstract
{
    protected function _beforeTableSelect(KCommandContext $context)
    {
        $application = $this->getService('application');
        if($application->getCfg('multilanguage') && $query = $context->query)
        {
            $tables = $this->getService('com://admin/languages.model.tables')
                ->enabled(true)
                ->getList();
            
            if(is_string(current($query->table)))
            {
                $table = $tables->find(array('name' => current($query->table)));
                
                if(count($table))
                {
                    $table = $table->top();
                    
                    // Join translation to add status to rows.
                    if(!$query->isCountQuery() && isset($context->options->state->translation))
                    {
                        $query->columns(array('translation' => 'translations.status'))
                            ->join(array('translations' => 'languages_translations'),
                                'translations.table = :translation_table AND translations.row = tbl.'.$table->unique_column)
                            ->bind(array('translation_table' => $table->name));
                        
                        if(!is_null($context->options->state->translation))
                        {
                            $query->where('translations.status IN :translation')
                                ->bind(array('translation_status' => (array) $context->options->state->translation));
                        }
                    }
                    
                    $languages = $application->getLanguages();
                    $active    = $languages->getActive();
                    $primary   = $languages->getPrimary();
                    
                    // Modify table in the query if active language is not the primary.
                    if($active->iso_code != $primary->iso_code) {
                        $context->query->table[key($query->table)] = strtolower($active->iso_code).'_'.$table->name;
                    }
                }
            }
        }
    }
    
    protected function _afterTableInsert(KCommandContext $context)
    {
        $application = JFactory::getApplication();
        if($application->getCfg('multilanguage') && $context->affected)
        {
            $tables = $this->getService('com://admin/languages.model.tables')->enabled(true)->getList();
            
            // Check if table is translatable.
            if(in_array($context->table, $tables->name))
            {
                $languages = $application->getLanguages();
                $active    = $languages->getActive();
                $primary   = $languages->getPrimary();
                
                $item = array(
                    'iso_code'   => $active->iso_code,
                    'table'      => $context->table,
                    'row'        => $context->data->id,
                    'status'     => ComLanguagesDatabaseRowItem::STATUS_COMPLETED,
{'fraction_non_alphanumeric': 0.13342266462480856, 'fraction_numerical': 0.0005742725880551302, 'mean_word_length': 1.5663064833005893, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3319435', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1238, 'n_words': 193}