public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Search Repo:
cmsmadesimple-2-0 / admin / lang.php
100644 135 lines (121 sloc) 3.882 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
#Nice decent default
$current_language = isset($frontendlang) ? $frontendlang : 'en_US';
 
#Only do language stuff for admin pages
if (isset($CMS_ADMIN_PAGE) || isset($CMS_STYLESHEET))
{
  $nls = array();
  $lang = array();
 
  #Read in all current languages...
  $dir = dirname(__FILE__)."/lang";
 
  $handle = opendir($dir);
  while (false!==($file = readdir($handle))) {
    if (is_file("$dir/$file") && strpos($file, "nls.php") != 0) {
      include("$dir/$file");
    }
  }
  closedir($handle);
 
  #Check to see if there is already a language in use...
  if (isset($_POST["default_cms_lang"]))
  {
    $current_language = $_POST["default_cms_lang"];
    if ($current_language == '')
    {
      setcookie("cms_language", '', time() - 3600);
    }
    else
    {
      setcookie("cms_language", $_POST["change_cms_lang"]);
    }
  }
  else if (isset($_SESSION['login_cms_language']))
  {
    debug_buffer('Setting language to: ' . $_SESSION['login_cms_language']);
    $current_language = $_SESSION['login_cms_language'];
    setcookie('cms_language', $_SESSION['login_cms_language']);
    unset($_SESSION['login_cms_language']);
  }
  else if (isset($_COOKIE["cms_language"]))
  {
    $current_language = $_COOKIE["cms_language"];
  }
 
  if ($current_language == '')
  {
    if (isset($gCms->config['locale']) && $gCms->config['locale'] != '')
    {
      $current_language = $gCms->config['locale'];
    }
    else
    {
    
      #No, take a stab at figuring out the default language...
      #Figure out default language and set it if it exists
      if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
      {
        $alllang = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
        if (strpos($alllang, ";") !== FALSE)
          $alllang = substr($alllang,0,strpos($alllang, ";"));
        $langs = explode(",", $alllang);
 
        foreach ($langs as $onelang)
        {
          #Check to see if lang exists...
          if (isset($nls['language'][$onelang]))
          {
            $current_language = $onelang;
            setcookie("cms_language", $onelang);
            break;
          }
          #Check to see if alias exists...
          if (isset($nls['alias'][$onelang]))
          {
            $alias = $nls['alias'][$onelang];
            if (isset($nls['language'][$alias]))
            {
              $current_language = $alias;
              setcookie("cms_language", $alias);
              break;
            }
          }
        }
      }
    }
  }
 
  #First load the english one so that we have strings to fall back on
  @include(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . 'en_US' . DIRECTORY_SEPARATOR . "admin.inc.php");
  
  #Now load the real file
  if ($lang != 'en_US')
  {
   $file = dirname(__FILE__) . "/lang/ext/" . $current_language . "/admin.inc.php";
    if (!is_file($file))
    {
      $file = dirname(__FILE__) . "/lang/" . $current_language . "/admin.inc.php";
    }
 
   if (is_file($file) && strlen($current_language) == 5 && strpos($current_language, ".") === false)
   {
   include ($file);
   }
  }
  
  $nls['direction'] = (isset($nls['direction']) && $nls['direction'] == 'rtl') ? 'rtl' : 'ltr';
 
  global $gCms;
  $gCms->nls = $nls;
  $gCms->current_language = $current_language;
}
 
# vim:ts=4 sw=4 noet
?>