Skip to content

Language Library Extension

Derek Jones edited this page Jul 5, 2012 · 4 revisions

Category:Core | Category:Core::Community | Category:Core::Language I created this language library extension for times when I might need to add a few parameters to a language line. This is most useful when you need to display a hash or some other non-language-specific value in your text.

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Language extends CI_Language
{
    function MY_Language()
    {
        parent::CI_Language();
    }
    
    function line_with_param($key, $params)
    {
        $line = $this->line($key);
        if($line !== false)
        {
            if(is_array($params))$line = vsprintf ($line, $params);
            else $line = sprintf ($line, $params);
        }
        return $line;
    }
}
//  ./system/application/libraries/MY_Language.php
?>

Use standard sprintf notation in your language files and call using either an array of parameters or a single parameter.

Clone this wiki locally