~patrix-sbs/oraculum/git

« back to all changes in this revision

Viewing changes to library/components/locale.php

  • Committer: Patrick Kaminski
  • Date: 2009-09-02 02:33:07 UTC
  • Revision ID: git-v1:943803254fca67bfb4c0374422b1b836b14dc518
Tags: v0.1a
Sending Oraculum Framework v0.1 alpha

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Componente de Internacionalizacao
 
4
 *
 
5
 *
 
6
 *    @filesource
 
7
 *    @category       Components
 
8
 *    @package        oraculum
 
9
 *    @subpackage     oraculum.components.I18N
 
10
 */
 
11
class I18N
 
12
{
 
13
  public static function load($lang=null)
 
14
  {
 
15
        if (!is_null($lang)) {
 
16
        $langfile="./apps/".PROJECT."/models/locale/".$lang."/lang.php";
 
17
        $altlangfile="./models/locale/".$lang."/lang.php";
 
18
        } else {
 
19
            $langfile="./apps/".PROJECT."/models/locale/".LANG."/lang.php";
 
20
            $altlangfile="./models/locale/".LANG."/lang.php";
 
21
        }
 
22
    if (file_exists($langfile)) {
 
23
      include($langfile);
 
24
      return true;
 
25
    } else if (file_exists($altlangfile)) {
 
26
      include($altlangfile);
 
27
      return true;
 
28
    } else {
 
29
      // Se não houver o arquivo PHP de idiomas, e gerado um atraves de um arquivo CSV
 
30
      if (!is_null($lang)) {
 
31
              $csvlangfile="./apps/".PROJECT."/models/locale/".$lang."/lang.csv";
 
32
              $altcsvlangfile="./models/locale/".$lang."/lang.csv";
 
33
      } else {
 
34
              $csvlangfile="./apps/".PROJECT."/models/locale/".LANG."/lang.csv";
 
35
              $altcsvlangfile="./models/locale/".LANG."/lang.csv";
 
36
      }
 
37
      if (file_exists($csvlangfile)) {
 
38
        $handle=fopen($csvlangfile, "r");
 
39
      } else if (file_exists($altcsvlangfile)) {
 
40
        $handle=fopen($altcsvlangfile, "r");
 
41
      }
 
42
      if (isset($handle)) {
 
43
        $phplangfile="<?php\n";
 
44
        while (($linhas=(fgetcsv($handle, 1000, ",")))!==FALSE) {
 
45
          $num=(count($linhas)); // Número de campos
 
46
          if ($num>1) {
 
47
            for ($c=1;$c<$num;$c++) {
 
48
              $linhas[$c]=str_replace("\"", "", $linhas[$c]);
 
49
              $linhas[$c]=str_replace("\'", "", $linhas[$c]);
 
50
              if ($linhas[$c]!="") {
 
51
                $phplangfile.="  define(\"LANG_".strtoupper($linhas[$c])."\", \"";
 
52
                $phplangfile.=strtolower(htmlentities(utf8_decode($linhas[0])))."\");\n";
 
53
              }
 
54
            }
 
55
          }
 
56
        }
 
57
        fclose($handle);
 
58
        if ((is_writable($langfile))||(!file_exists($langfile))) {
 
59
          $file=fopen($langfile, 'w');
 
60
          fwrite($file, $phplangfile);
 
61
          I18N::load(); // Tenta recarregar o arquivo de Idioma (php) novamente
 
62
          fclose($file);
 
63
          if (DEBUG) {
 
64
            alert("Arquivo de idioma gerado atraves de um arquivo CSV<br /><u>".$langfile."</u>");
 
65
          }
 
66
          return true;
 
67
        } else {
 
68
          if (DEBUG) {
 
69
            alert("Sem permissao para gerar arquivo de idioma<br /><u>".$langfile."</u>");
 
70
          }
 
71
          return false;
 
72
        }
 
73
      } else {
 
74
        if (DEBUG) {
 
75
          alert("Arquivo referente ao idioma <u>".LANG."</u> nao encontrado!");
 
76
        }
 
77
        return false;
 
78
      }
 
79
    }
 
80
  }
 
81
}
 
82
//I18N::load();
 
 
b'\\ No newline at end of file'