Welcome Guest, Not a member yet? Register   Sign In
Mod to have language keys automatically recognized by the template parser
#4

[eluser]Yoglets[/eluser]
Well, the "_($key)" notation mimics the widely used short alias for PHP's gettext() function, so I figured it was already commonly known by anybody using multiple languages in PHP. If not, I can just add custom delimiters similar to the $l_delim and $r_delim that are already defined in the Parser class. For example:
Code:
var $l_lang_delim = '_(';
var $r_lang_delim = ')';
Then the added code simply becomes:
Code:
foreach ($CI->lang->language as $key => $val)
{
    $data[$this->l_lang_delim . $key . $this->r_lang_delim] = $val;
}
So if you don't like the _() notation, you can just change it to whatever you prefer.

Regarding the comment about only adding keys that actually get used in the template... aren't you (for the most part, at least) already going to have only the keys you actually need for that one particular view loaded? I.e., you shouldn't be loading keys you're not using.

Regardless, a failed str_replace() is much faster than a failed preg_match(), so looking through the template once for each key in an effort to remove the unused ones will be slower than just trying to replace those keys that don't exist. (Benchmarked with my particular view and language strings, trying to remove the unused keys before parsing the template actually makes the entire process 62% slower. Using strpos() instead of preg_match() is much better (10% slower), but still not better than simply doing nothing.)


Messages In This Thread
Mod to have language keys automatically recognized by the template parser - by El Forum - 07-16-2007, 07:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB