Location: PHPKode > scripts > LanguageSys > languagesys/doc/en/functions.htm
<html>
 <head>
  <link rel="stylesheet" href="inline.css" />
 </head>
 <body>
  <h1>Class functions:</h1>
  <div id="body">
   <h1>Instantiation</h1>
   <p>
    <span class="func">void LanguageSys( void )</span><br />
    To instantate you can create a simple object of LanguageSys.<br />
    Don't forget to bind the class!<br />
    <code>
<span style="color: #007700">include(</span><span style="color: #DD0000">'LanguageSys.class.php'</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span><br />
    </code>
   </p>
   <h2>LanguageSys::set_res_dir</h2>
   <p>
    <span class="func">bool set_res_dir( string dir )</span><br />
    This functions sets the directory which is searched for language files.<br />
    Returns TRUE on success, on error (eg the directory doesn't exist) it returns FALSE.<br />
    Before the first call of set_res_dir() the default directory which is set is ./lang, relative from the own directory.
    <code>
<span style="color: #007700">include(</span><span style="color: #DD0000">'LanguageSys.class.php'</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set_res_dir</span><span style="color: #007700">(</span><span style="color: #DD0000">'./foo/bar/'</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span><br />
    </code>
   </p>
   <h2>LanguageSys::get_aviable_languages</h2>
   <p>
    <span class="func">array get_aviable_languages([lsys_return_type type])</span><br />
    Returns a array based on the given resource type. Those can be a numeric array which contains all the language codes (LSYS_RTN_CODES), a numeric array which contains all the names of the languages like &quote;German (Germany)&quot; (LSYS_RTN_NAMES), an other possibility is a assisioative array build of the language code as descriptor an the language name as content (LSYS_RTN_MIXED).<br />
    Default is LSYS_RTN_CODES.<br />
    Example for LSYS_RTN_CODES:
    <code>
<span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$languages </span><span style="color: #007700">= </span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get_aviable_languages</span><span style="color: #007700">();<br />
&nbsp;&nbsp;</span><span style="color: #0000BB"><a href="http://php.net/print_r" title="Prints human-readable information about a variable: bool print_r(mixed var [, bool return])" target="blank">print_r</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$languages</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span><br />
    </code>
    Would print out something like:
    <cite>
     Array (<br />
     &nbsp;&nbsp;[0] =&gt; de_DE<br />
     &nbsp;&nbsp;[1] =&gt; en_EN<br />
     &nbsp;&nbsp;[2] =&gt; en_US<br />
     )<br />
    </cite>
    Example for LSYS_RTN_NAMES:
    <code>
<span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$languages </span><span style="color: #007700">= </span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get_aviable_languages</span><span style="color: #007700">(</span><span style="color: #0000BB">LSYS_RTN_NAMES</span><span style="color: #007700">);<br />
&nbsp;&nbsp;</span><span style="color: #0000BB"><a href="http://php.net/print_r" title="Prints human-readable information about a variable: bool print_r(mixed var [, bool return])" target="blank">print_r</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$languages</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span>
    </code>
    Would print out something like:
    <cite>
     Array (<br />
     &nbsp;&nbsp;[0] =&gt; German (Germany)<br />
     &nbsp;&nbsp;[1] =&gt; English<br />
     &nbsp;&nbsp;[2] =&gt; English (United States of America)<br />
     )<br />
    </cite>
    Example for LSYS_RTN_MIXED:
    <code>
<span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$languages </span><span style="color: #007700">= </span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get_aviable_languages</span><span style="color: #007700">(</span><span style="color: #0000BB">LSYS_RTN_MIXED</span><span style="color: #007700">);<br />
&nbsp;&nbsp;</span><span style="color: #0000BB"><a href="http://php.net/print_r" title="Prints human-readable information about a variable: bool print_r(mixed var [, bool return])" target="blank">print_r</a></span><span style="color: #007700">(</span><span style="color: #0000BB">$languages</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span><br />
    </code>
    Would print out something like:
    <cite>
     Array (<br />
     &nbsp;&nbsp;[de_DE] =&gt; German (Germany)<br />
     &nbsp;&nbsp;[en_EN] =&gt; English<br />
     &nbsp;&nbsp;[en_US] =&gt; English (United States of America)<br />
     )<br />
    </cite>
   </p>
   <h2>LanguageSys::load</h2>
   <p>
    <span class="func">bool load( string language_code )</span><br />
    The founction load() is used to load a language file. After loading the
    language file is aviable and the variables would be instantiated.<br />
    If there was a lnaguage file loaded before and you load a new language file
    the old variables wouldn't be deleted, just the variables are also given in
    the newly loaded file would be overwritten.<br />
    This is made so because of that eg a language file for a older version of
    your application was loaded. If you have loaded a other default language file
    before, the entries which are not aviable from the new loaded file are also
    avible in the default language.<br />
    On success this function returns TRUE, on error it returns FALSE. To handle
    the errors use the LanguageSys::last_error() function.
    <code>
<span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #FF8000">//Load the english language file.<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_EN'</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">//Print out the contents of "foo".<br />
</span><span style="color: #007700">print </span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">foo</span><span style="color: #007700">;</span><br />
    </code>
   </p>
   <h2>LanguageSys::compile</h2>
   <p>
    <span class="func">bool compile(string sourcefile, string destinationfile)</span><br />
    The compile-function is used to precompile a language file.<br />
    You have to give the full path of the source and destination file, because the resource directory wouldn't be used.<br />
    By precompiling the parsing mechanism can be highliy increased, so if it is possible you should use precompiled files.<br />
    For more information on precompiling see &quot;Precompiling&quot;<br />
    Example:
    <code>
<span style="color: #0000BB">$lang </span><span style="color: #007700">= new </span><span style="color: #0000BB">LanguageSys</span><span style="color: #007700">();<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">compile</span><span style="color: #007700">(</span><span style="color: #DD0000">'./uncompiled/en_EN.ini'</span><span style="color: #007700">, </span><span style="color: #DD0000">'./compiled/en_EN.lng'</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;...</span><br />
    </code>
   </p>
   <h2>LanguageSys::_parse</h2>
   <p>
    <span class="func">private mixed _parse( string &amp;code )</span><br />
    The method _parse is used intern by LanguageSys to get the datas out of precompiled language files.<br />
    Those method isn't made for normal use.
   </p>
   <h2>LanguageSys::_pparse</h2>
   <p>
    <span class="func">private mixed _pparse( array &amp;code )</span><br />
    The method _pparse is used intern by LanguageSys to get the datas out of the language files.<br />
    Those method isn't made for normal use.
   </p>
   <h2>LanguageSys::_error</h2>
   <p>
    <span class="func">private void _error(lsys_error_type type, string message [, int line])</span><br />
    Die Methode _error wird intern von LanguageSys verwendet um einen Fehler in den Fehlerpuffer zu schreiben.<br />
    Sie ist nicht für den normalen gebrauch gedacht. Kann aber sinnvol in abgeleiteten klassen eingesetzt werden.<br />
   </p>
   <h2>LanguageSys::last_error</h2>
   <p>
    <span class="func">string last_error( void )</span><br />
    Returns the last error happened.<br />
    If there wasn't a failure yet it will return FALSE.<br />
    Normaly last_error() is used in cooperation with load() oder compile().<br />
    Example:
    <code>
<span style="color: #007700">...<br />
if( !</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_EN'</span><span style="color: #007700">) )<br />
{<br />
&nbsp;&nbsp;die(</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">last_error</span><span style="color: #007700">());<br />
}<br />
...</span><br />
    </code>
   </p>
   <h2>LanguageSys::get_fileinfo</h2>
   <p>
    <span class="func">string get_fileinfo(string info)</span><br />
    Returns the value of a variable defined in the [info] section of the language file.<br />
    If the value wasn't given by the language file, it will return NULL.
    <code>
<span style="color: #007700">...<br />
if( !</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_EN'</span><span style="color: #007700">) )<br />
{<br />
&nbsp;&nbsp;die(</span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">last_error</span><span style="color: #007700">());<br />
}<br />
</span><span style="color: #FF8000">//Print out the translation informations..<br />
</span><span style="color: #007700">print </span><span style="color: #0000BB">$lang</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get_fileinfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'translation_info'</span><span style="color: #007700">);<br />
...</span><br />
    </code>
   </p>
   <h2>LanguageSys::get_author</h2>
   <p>
    <span class="func">string get_author( void )</span><br />
    Alias for LanguageSys::get_fileinfo('<i>author</i>')
   </p>
   <h2>LanguageSys::get_transinfo</h2>
   <p>
    <span class="func">string get_transinfo( void )</span><br />
    Alias for LanguageSys::get_fileinfo('<i>translation_info</i>')
   </p>
   <h2>LanguageSys::get_version</h2>
   <p>
    <span class="func">string get_version( void )</span><br />
    Alias for LanguageSys::get_fileinfo('<i>version</i>')
   </p>
   <h2>LanguageSys::get_application</h2>
   <p>
    <span class="func">string get_application( void )</span><br />
    Alias for LanguageSys::get_fileinfo('<i>application</i>')
   </p>
  </div>
 </body>
</html>
Return current item: LanguageSys