better language library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: better language library (/showthread.php?tid=37390) |
better language library - El Forum - 01-07-2011 [eluser]Tom Vogt[/eluser] I've done a small extension to the language library, to allow for easier replacement strings. Namely, this allows you to do either of this: Code: echo $this->lang->line('teststring', array('first', 'second')); where the language file looks like this: Code: $lang['teststring'] = 'This is a teststring with two replacements: [1] and [2].'; I wanted this for two reasons: 1.) The %s replacement doesn't allow for re-ordering, but some languages have different sentence structures and would require that or awkword wordings. 2.) because it makes it easier for translators if there is a meaningful placeholder instead of a %s Note that the placeholder should NOT be translated, even in other language versions it must remain, in the above example, [one] and [two] Here's the code, it is really simple. Save this in system/application/libraries/MY_Language.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |