The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Jun 19, 2012 2:27 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Jun 19, 2012 2:22 am
Posts: 1
I am building a php code to fill some metadata taking info from the same site db, this site is in english, french, and spanish. now i need to create 3 sentences in each language and there are some strings i take from the database that needs to be translated. is there a way i can use JText::_ to take the translation from the language files and set it to different variables of each language. ?

i mean something like

Code:
    $var_en = JText::_($cat_name) //store the category name in english
    $var_fr = JText::_($cat_name) //store the category name in french

how can i specify to JText in my code what language i want to use??

it can be complicated i know, i'll share to you my code for better understanding

Code:
function createmetadatainfo(){
        global $mtconf;
   
   //USE THIS IF SCRIPT EXECUTION TAKES TOO LONG
   //set_time_limit(300);

   //USE THE $app OBJECT TO CLOSE THE APPLICATION BEFORE JOOMLA RENDERS THE SITE
   $app      = JFactory::getApplication('admin');
        //DATABASE
        global $database;   
        $database       =& JFactory::getDBO();

            //CREATE AND UPDATE METADESC FOR CATEGORIES.
                $query = 'SELECT
                            `cat_id` , `cat_name` , `cat_links`
                          FROM
                            `#__mt_cats`
                          ORDER BY
                            `cat_id`';

                $database->setQuery($query);
                $metaCats = $database->loadAssocList();

                foreach ($metaCats as $value) {
                    //building metadescription sentences in different languages.
                    $meta_en = $value['cat_links']." listings on ".$value['cat_name']." category";
                    $meta_fr = $value['cat_links']." annonces sur ".$value['cat_name']." catégorie";
                    $meta_es = $value['cat_links']." listados en la categoría ".$value['cat_name'];
                    $cat_id = $value['cat_id'];
                    $query_cat_metadesc = "UPDATE `#__mt_cats` SET `metadesc` = '$meta_en' ,
                                                                `metadesc_fr` = '$meta_fr' ,
                                                                `metadesc_es` = '$meta_es'
                                                                 WHERE `cat_id` = '$cat_id'";
                    $database->setQuery($query_cat_metadesc);
                    $database->query();
                }
   
   //CLOSE the $app
   $app->close();
}


Please notice inside the foreach statement that i need to store inside $meta_en, $meta_fr and $meta_es the variable $value['cat_name'] in diferent languages


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 



Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group