{"id":132,"date":"2010-09-22T09:38:58","date_gmt":"2010-09-22T07:38:58","guid":{"rendered":"http:\/\/www.4amics.com\/x.perez\/?p=132"},"modified":"2010-09-22T09:38:58","modified_gmt":"2010-09-22T07:38:58","slug":"language-improvements-codeigniter","status":"publish","type":"post","link":"https:\/\/www.4amics.com\/x.perez\/2010\/09\/language-improvements-codeigniter\/","title":{"rendered":"Language improvements Codeigniter"},"content":{"rendered":"<p>The language library in Codeigniter is very simple, and doesn&#8217;t\u00a0 support variable substitution, only partial or complete phrases.<\/p>\n<p>For this reason, I have made minor changes to allow the variable substitution, thus it&#8217;s not the same espelling in different idiomas.<\/p>\n<p><!--more-->For example:<\/p>\n<p>To show a price, every country have it&#8217;s own format, sometimes sig are before, sometimes after the number ( float or integer). My language helper solves it.<\/p>\n<p>In your language\/english directory, you will have your language file with this:<\/p>\n<blockquote><p>$lang[\u2018product_price\u2019]\u00a0  \u00a0  \u00a0 = \u2018$ %6.0d\u2019;<\/p><\/blockquote>\n<p>In your language\/spanish directory, you will have your kanguage file with this:<\/p>\n<blockquote><p>$lang[\u2018price\u2019]\u00a0  \u00a0  \u00a0 = \u2018%6.2f \u20ac\u2019;<\/p><\/blockquote>\n<p>Herem the language_helper.php file (must to be create with this name and in the helper appliation\/directory):<\/p>\n<blockquote><p>&lt;?php\u00a0 if (!defined(&#8216;BASEPATH&#8217;)) exit(&#8216;No direct script access allowed&#8217;);<br \/>\n\/**<br \/>\n* CodeIgniter<br \/>\n*<br \/>\n* An open source application development framework for PHP 4.3.2 or newer<br \/>\n*<br \/>\n* @package\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0CodeIgniter<br \/>\n* @author\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0ExpressionEngine Dev Team<br \/>\n* @copyright\u00a0\u00a0 \u00a0Copyright (c) 2008 &#8211; 2010, EllisLab, Inc.<br \/>\n* @license\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0http:\/\/codeigniter.com\/user_guide\/license.html<br \/>\n* @link\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0http:\/\/codeigniter.com<br \/>\n* @since\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0Version 1.0<br \/>\n* @filesource<br \/>\n*\/<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\/**<br \/>\n* CodeIgniter Language Helpers<br \/>\n*<br \/>\n* @package\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0CodeIgniter<br \/>\n* @subpackage\u00a0\u00a0 \u00a0Helpers<br \/>\n* @category\u00a0\u00a0 \u00a0Helpers<br \/>\n* @author\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0ExpressionEngine Dev Team<br \/>\n* @link\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0http:\/\/codeigniter.com\/user_guide\/helpers\/language_helper.html<br \/>\n*\/<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\/**<br \/>\n* Lang<br \/>\n*<br \/>\n* Fetches a language variable and optionally outputs a form label<br \/>\n*<br \/>\n* @access\u00a0\u00a0 \u00a0public<br \/>\n* @param\u00a0\u00a0 \u00a0string\u00a0\u00a0 \u00a0the language line<br \/>\n* @param\u00a0\u00a0 \u00a0string\u00a0\u00a0 \u00a0the id of the form element<br \/>\n* @return\u00a0\u00a0 \u00a0string<br \/>\n*\/<br \/>\nif ( ! function_exists(&#8216;lang&#8217;))<br \/>\n{<br \/>\nfunction lang($line, $id = &#8221;)<br \/>\n{<br \/>\n$CI =&amp; get_instance();<br \/>\n$line = $CI-&gt;lang-&gt;line($line);<\/p>\n<p>if ($id != &#8221;)<br \/>\n{<br \/>\n$line = &#8216;&lt;label for=&#8221;&#8216;.$id.'&#8221;&gt;&#8217;.$line.&#8221;&lt;\/label&gt;&#8221;;<br \/>\n}<\/p>\n<p>return $line;<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* SLang<br \/>\n*<br \/>\n* Fetches a language variable, optional substitution vars and optionally outputs a form label<br \/>\n*<br \/>\n* @author\u00a0\u00a0 \u00a0Xavier P\u00e9rez<br \/>\n* @version\u00a0\u00a0 \u00a01.0.1<br \/>\n* @access\u00a0\u00a0 \u00a0public<br \/>\n* @param\u00a0\u00a0 \u00a0string\u00a0\u00a0 \u00a0the language line<br \/>\n* @param\u00a0\u00a0 \u00a0mixed\u00a0\u00a0 \u00a0the substitution values (varchar, integer, or array)<br \/>\n* @param\u00a0\u00a0 \u00a0string\u00a0\u00a0 \u00a0the id of the form element<br \/>\n* @return\u00a0\u00a0 \u00a0string<br \/>\n*\/<\/p>\n<p>if ( ! function_exists(&#8216;slang&#8217;))<br \/>\n{<br \/>\nfunction slang($line, $values=&#8221;, $id = &#8221;)<br \/>\n{<br \/>\n$CI =&amp; get_instance();<br \/>\n$line = $CI-&gt;lang-&gt;line($line);<\/p>\n<p>if (is_array($values) &amp;&amp; count($values) &gt; 0)<br \/>\n$line = vsprintf($line,$values);<\/p>\n<p>if (!is_array($values) &amp;&amp; $values != &#8220;&#8221;)<br \/>\n$line = sprintf($line,$values);<\/p>\n<p>if ($id != &#8221;)<br \/>\n{<br \/>\n$line = &#8216;&lt;label for=&#8221;&#8216;.$id.'&#8221;&gt;&#8217;.$line.&#8221;&lt;\/label&gt;&#8221;;<br \/>\n}<\/p>\n<p>return $line;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n\/* End of file language_helper.php *\/<br \/>\n\/* Location: .\/system\/helpers\/language_helper.php *\/<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The language library in Codeigniter is very simple, and doesn&#8217;t\u00a0 support variable substitution, only partial or complete phrases. For this reason, I have made minor changes to allow the variable substitution, thus it&#8217;s not the same espelling in different idiomas.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3,4,11],"tags":[],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-codeigniter","category-developer","category-frameworks","category-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":2,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/132\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}