Created
May 9, 2013 08:35
-
-
Save adamtester/5546300 to your computer and use it in GitHub Desktop.
Extends the CI Parser class to allow for language files to be parsed. With this instead of using <?php echo $this->lang->line('lineoftext'); ?> You can now use an underscore in your view files like so: {_lineoftext}. Enjoy cleaner view files!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
****************************************************************************** | |
// Extends the CI Parser class to allow for language files to be parsed. | |
// With this instead of using <?php echo $this->lang->line('lineoftext'); ?> | |
// You can now use an underscore in your view files like so: {_lineoftext} | |
// Enjoy cleaner view files! | |
// Place this file in application/libraries/MY_Parser.php | |
****************************************************************************** | |
*/ | |
class MY_Parser extends CI_Parser { | |
const LANG_REPLACE_REGEXP = '!\{_\s*(?<key>[^\}]+)\}!'; | |
static $CI = null; | |
public function parse($template, $data, $return = FALSE) { | |
$this->CI = get_instance(); | |
$template = $this->CI->load->view($template, $data, TRUE); | |
$template = $this->replace_lang_keys($template); | |
return $this->_parse($template, $data, $return); | |
} | |
protected function replace_lang_keys($template) { | |
return preg_replace_callback(self::LANG_REPLACE_REGEXP, array($this, 'replace_lang_key'), $template); | |
} | |
protected function replace_lang_key($key) { | |
return $this->CI->lang->line($key[1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment