CodeIgniter Forums
Placeholders in language lines - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Placeholders in language lines (/showthread.php?tid=70858)



Placeholders in language lines - glorsh66 - 06-10-2018

How to use placeholders in 
$this->lang->line('misc_key', FALSE);

It is used in standard libraries  (e.g. from validation), but how to use it in my own libs and models?

Code:
echo sprintf($this->lang->line('somekey'),'XYZ');//load language library before use
Is this the best way?


RE: Placeholders in language lines - InsiteFX - 06-10-2018

Maybe this will help, you can use it in any library Class.


PHP Code:
// Your lang file - Created under language folder language-name
<<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$lang['your key'] = "Your Message.";

// End of lang file


// Your Class
class Your_Class
{
 
   /**
     * @var  CI_Controller - The CI Super Object
     */
 
   protected $CI;

 
   /**
     * constructor.
     * -------------------------------------------------------------------
     *
     */
 
   public function __construct()
 
   {
 
       $this->CI =& get_instance();

 
       $this->CI->lang->load('your lang file''english');
 
   }

 
   /**
     * Your Method.
     * -------------------------------------------------------------------
     *
     */
 
   public function test()
 
   {
 
       show_error($this->CI->lang->line('your message'));
 
       
        
// or

 
       echo $this->CI->lang->line('your message');
 
   }


 
When working outside of a controller you need to get the CodeIgniter Super Object.

Also SEE: The CodeIgniter Documentation on Language files etc;