includes/lang.php
author Dan
Sat, 19 Jan 2008 00:32:41 -0500
changeset 356 9f8fca26ddb9
parent 355 d15e4411ef65
child 371 dc6026376919
permissions -rw-r--r--
Localized Admin:COPPA
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     1
<?php
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     2
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     3
/*
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     5
 * Version 1.1.1
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     7
 *
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    10
 *
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    13
 */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    14
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    15
/**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    16
 * Language class - processes, stores, and retrieves language strings.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    17
 * @package Enano
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    18
 * @subpackage Localization
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    19
 * @copyright 2007 Dan Fuhry
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    20
 * @license GNU General Public License
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    21
 */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    22
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    23
class Language
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    24
{
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    25
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    26
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    27
   * The numerical ID of the loaded language.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    28
   * @var int
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    29
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    30
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    31
  var $lang_id;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    32
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    33
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    34
   * The ISO-639-3 code for the loaded language. This should be grabbed directly from the database.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    35
   * @var string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    36
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    37
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    38
  var $lang_code;
210
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    39
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    40
  /**
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    41
   * Used to track when a language was last changed, to allow browsers to cache language data
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    42
   * @var int
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    43
   */
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    44
  
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    45
  var $lang_timestamp;
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    46
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    47
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    48
   * Will be an object that holds an instance of the class configured with the site's default language. Only instanciated when needed.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    49
   * @var object
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    50
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    51
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    52
  var $default;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    53
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    54
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    55
   * The list of loaded strings.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    56
   * @var array
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    57
   * @access private
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    58
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    59
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    60
  var $strings = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    61
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    62
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    63
   * Constructor.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    64
   * @param int|string Language ID or code to load.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    65
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    66
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    67
  function __construct($lang)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    68
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    69
    global $db, $session, $paths, $template, $plugins; // Common objects
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    70
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    71
    if ( defined('IN_ENANO_INSTALL') )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    72
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    73
      // special case for the Enano installer: it will load its own strings from a JSON file and just use this API for fetching and templatizing them.
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
    74
      $this->lang_id   = 1;
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
    75
      $this->lang_code = $lang;
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    76
      return true;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    77
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    78
    if ( is_string($lang) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    79
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    80
      $sql_col = 'lang_code="' . $db->escape($lang) . '"';
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    81
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    82
    else if ( is_int($lang) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    83
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    84
      $sql_col = 'lang_id=' . $lang . '';
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    85
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    86
    else
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    87
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    88
      $db->_die('lang.php - attempting to pass invalid value to constructor');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    89
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    90
    
239
0f1b353570a7 Fix a comparison logic SQL error in lang.php; fix attempt to call mysql_real_escape_string() in install without a working DB connection
Dan
parents: 215
diff changeset
    91
    $lang_default = ( $x = getConfig('default_language') ) ? intval($x) : '\'def\'';
210
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
    92
    $q = $db->sql_query("SELECT lang_id, lang_code, last_changed, ( lang_id = $lang_default ) AS is_default FROM " . table_prefix . "language WHERE $sql_col OR lang_id = $lang_default ORDER BY is_default DESC LIMIT 1;");
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    93
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    94
    if ( !$q )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    95
      $db->_die('lang.php - main select query');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    96
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    97
    if ( $db->numrows() < 1 )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    98
      $db->_die('lang.php - There are no languages installed');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
    99
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   100
    $row = $db->fetchrow();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   101
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   102
    $this->lang_id   = intval( $row['lang_id'] );
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   103
    $this->lang_code = $row['lang_code'];
210
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   104
    $this->lang_timestamp = $row['last_changed'];
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   105
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   106
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   107
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   108
   * Fetches language strings from the database, or a cache file if it's available.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   109
   * @param bool If true (default), allows the cache to be used.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   110
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   111
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   112
  function fetch($allow_cache = true)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   113
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   114
    global $db, $session, $paths, $template, $plugins; // Common objects
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   115
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   116
    $lang_file = ENANO_ROOT . "/cache/lang_{$this->lang_id}.php";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   117
    // Attempt to load the strings from a cache file
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   118
    if ( file_exists($lang_file) && $allow_cache )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   119
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   120
      // Yay! found it
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   121
      $this->load_cache_file($lang_file);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   122
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   123
    else
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   124
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   125
      // No cache file - select and retrieve from the database
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   126
      $q = $db->sql_unbuffered_query("SELECT string_category, string_name, string_content FROM " . table_prefix . "language_strings WHERE lang_id = {$this->lang_id};");
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   127
      if ( !$q )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   128
        $db->_die('lang.php - selecting language string data');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   129
      if ( $row = $db->fetchrow() )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   130
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   131
        $strings = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   132
        do
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   133
        {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   134
          $cat =& $row['string_category'];
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   135
          if ( !is_array($strings[$cat]) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   136
          {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   137
            $strings[$cat] = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   138
          }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   139
          $strings[$cat][ $row['string_name'] ] = $row['string_content'];
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   140
        }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   141
        while ( $row = $db->fetchrow() );
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   142
        // all done fetching
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   143
        $this->merge($strings);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   144
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   145
      else
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   146
      {
241
c671f3bb8aed Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents: 239
diff changeset
   147
        if ( !defined('ENANO_ALLOW_LOAD_NOLANG') )
c671f3bb8aed Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents: 239
diff changeset
   148
          $db->_die('lang.php - No strings for language ' . $this->lang_code);
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   149
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   150
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   151
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   152
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   153
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   154
   * Loads a file from the disk cache (treated as PHP) and merges it into RAM.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   155
   * @param string File to load
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   156
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   157
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   158
  function load_cache_file($file)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   159
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   160
    global $db, $session, $paths, $template, $plugins; // Common objects
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   161
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   162
    // We're using eval() here because it makes handling scope easier.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   163
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   164
    if ( !file_exists($file) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   165
      $db->_die('lang.php - requested cache file doesn\'t exist');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   166
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   167
    $contents = file_get_contents($file);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   168
    $contents = preg_replace('/([\s]*)<\?php/', '', $contents);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   169
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   170
    @eval($contents);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   171
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   172
    if ( !isset($lang_cache) || ( isset($lang_cache) && !is_array($lang_cache) ) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   173
      $db->_die('lang.php - the cache file is invalid (didn\'t set $lang_cache as an array)');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   174
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   175
    $this->merge($lang_cache);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   176
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   177
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   178
  /**
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   179
   * Loads a JSON language file and parses the strings into RAM. Will use the cache if possible, but stays far away from the database,
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   180
   * which we assume doesn't exist yet.
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   181
   */
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   182
  
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   183
  function load_file($file)
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   184
  {
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   185
    global $db, $session, $paths, $template, $plugins; // Common objects
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   186
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   187
    if ( !file_exists($file) )
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   188
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   189
      if ( defined('IN_ENANO_INSTALL') )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   190
      {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   191
        die('lang.php - requested JSON file (' . htmlspecialchars($file) . ') doesn\'t exist');
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   192
      }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   193
      else
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   194
      {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   195
        $db->_die('lang.php - requested JSON file doesn\'t exist');
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   196
      }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   197
    }
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   198
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   199
    $contents = trim(@file_get_contents($file));
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   200
    if ( empty($contents) )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   201
      $db->_die('lang.php - empty language file...');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   202
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   203
    // Trim off all text before and after the starting and ending braces
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   204
    $contents = preg_replace('/^([^{]+)\{/', '{', $contents);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   205
    $contents = preg_replace('/\}([^}]+)$/', '}', $contents);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   206
    $contents = trim($contents);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   207
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   208
    if ( empty($contents) )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   209
      $db->_die('lang.php - no meat to the language file...');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   210
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   211
    $checksum = md5($contents);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   212
    if ( file_exists("./cache/lang_json_{$checksum}.php") )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   213
    {
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   214
      $this->load_cache_file("./cache/lang_json_{$checksum}.php");
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   215
    }
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   216
    else
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   217
    {
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   218
      // Correct syntax to be nice to the json parser
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   219
    
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   220
      // eliminate comments
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   221
      $contents = preg_replace(array(
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   222
              // eliminate single line comments in '// ...' form
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   223
              '#^\s*//(.+)$#m',
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   224
              // eliminate multi-line comments in '/* ... */' form, at start of string
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   225
              '#^\s*/\*(.+)\*/#Us',
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   226
              // eliminate multi-line comments in '/* ... */' form, at end of string
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   227
              '#/\*(.+)\*/\s*$#Us'
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   228
            ), '', $contents);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   229
      
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   230
      $contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   231
      
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   232
      try
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   233
      {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   234
        $langdata = enano_json_decode($contents);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   235
      }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   236
      catch(Zend_Json_Exception $e)
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   237
      {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   238
        $db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>');
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   239
        exit;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 345
diff changeset
   240
      }
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   241
    
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   242
      if ( !is_array($langdata) )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   243
        $db->_die('lang.php - invalid language file');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   244
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   245
      if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   246
        $db->_die('lang.php - language file does not contain the proper items');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   247
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   248
      $this->merge($langdata['strings']);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   249
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   250
      $lang_file = "./cache/lang_json_{$checksum}.php";
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   251
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   252
      $handle = @fopen($lang_file, 'w');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   253
      if ( !$handle )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   254
        // Couldn't open the file. Silently fail and let the strings come from RAM.
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   255
        return false;
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   256
        
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   257
      // The file's open, that means we should be good.
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   258
      fwrite($handle, '<?php
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   259
// This file was generated automatically by Enano. You should not edit this file because any changes you make
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   260
// to it will not be visible in the ACP and all changes will be lost upon any changes to strings in the admin panel.
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   261
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   262
$lang_cache = ');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   263
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   264
      $exported = $this->var_export_string($this->strings);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   265
      if ( empty($exported) )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   266
        // Ehh, that's not good
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   267
        $db->_die('lang.php - load_file(): var_export_string() failed');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   268
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   269
      fwrite($handle, $exported . '; ?>');
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   270
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   271
      // Clean up
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   272
      unset($exported, $langdata);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   273
      
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   274
      // Done =)
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   275
      fclose($handle);
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   276
    }
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   277
  }
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   278
  
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   279
  /**
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   280
   * Merges a standard language assoc array ($arr[cat][stringid]) with the master in RAM.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   281
   * @param array
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   282
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   283
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   284
  function merge($strings)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   285
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   286
    // This is stupidly simple.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   287
    foreach ( $strings as $cat_id => $contents )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   288
    {
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   289
      if ( !isset($this->strings[$cat_id]) || ( isset($this->strings[$cat_id]) && !is_array($this->strings[$cat_id]) ) )
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   290
        $this->strings[$cat_id] = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   291
      foreach ( $contents as $string_id => $string )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   292
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   293
        $this->strings[$cat_id][$string_id] = $string;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   294
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   295
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   296
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   297
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   298
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   299
   * Imports a JSON-format language file into the database and merges with current strings.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   300
   * @param string Path to the JSON file to load
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   301
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   302
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   303
  function import($file)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   304
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   305
    global $db, $session, $paths, $template, $plugins; // Common objects
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   306
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   307
    if ( !file_exists($file) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   308
      $db->_die('lang.php - can\'t import language file: string file doesn\'t exist');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   309
    
241
c671f3bb8aed Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents: 239
diff changeset
   310
    if ( $this->lang_id == 0 )
c671f3bb8aed Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents: 239
diff changeset
   311
      $db->_die('lang.php - BUG: trying to perform import when $lang->lang_id == 0');
c671f3bb8aed Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents: 239
diff changeset
   312
    
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   313
    $contents = trim(@file_get_contents($file));
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   314
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   315
    if ( empty($contents) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   316
      $db->_die('lang.php - can\'t load the contents of the language file');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   317
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   318
    // Trim off all text before and after the starting and ending braces
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   319
    $contents = preg_replace('/^([^{]+)\{/', '{', $contents);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   320
    $contents = preg_replace('/\}([^}]+)$/', '}', $contents);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   321
    
334
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   322
    // Correct syntax to be nice to the json parser
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   323
    
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   324
    // eliminate comments
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   325
    $contents = preg_replace(array(
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   326
            // eliminate single line comments in '// ...' form
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   327
            '#^\s*//(.+)$#m',
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   328
            // eliminate multi-line comments in '/* ... */' form, at start of string
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   329
            '#^\s*/\*(.+)\*/#Us',
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   330
            // eliminate multi-line comments in '/* ... */' form, at end of string
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   331
            '#/\*(.+)\*/\s*$#Us'
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   332
          ), '', $contents);
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   333
    
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   334
    $contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents);
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   335
    
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   336
    try
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   337
    {
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   338
      $langdata = enano_json_decode($contents);
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   339
    }
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   340
    catch(Zend_Json_Exception $e)
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   341
    {
335
67bd3121a12e Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents: 334
diff changeset
   342
      $db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>');
334
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   343
      exit;
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   344
    }
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   345
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   346
    if ( !is_array($langdata) )
334
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   347
    {
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   348
      $db->_die('lang.php - invalid or non-well-formed language file');
c72b545f1304 More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents: 243
diff changeset
   349
    }
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   350
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   351
    if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   352
      $db->_die('lang.php - language file does not contain the proper items');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   353
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   354
    $insert_list = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   355
    $delete_list = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   356
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   357
    foreach ( $langdata['categories'] as $category )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   358
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   359
      if ( isset($langdata['strings'][$category]) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   360
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   361
        foreach ( $langdata['strings'][$category] as $string_name => $string_value )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   362
        {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   363
          $string_name = $db->escape($string_name);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   364
          $string_value = $db->escape($string_value);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   365
          $category_name = $db->escape($category);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   366
          $insert_list[] = "({$this->lang_id}, '$category_name', '$string_name', '$string_value')";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   367
          $delete_list[] = "( lang_id = {$this->lang_id} AND string_category = '$category_name' AND string_name = '$string_name' )";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   368
        }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   369
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   370
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   371
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   372
    $delete_list = implode(" OR\n  ", $delete_list);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   373
    $sql = "DELETE FROM " . table_prefix . "language_strings WHERE $delete_list;";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   374
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   375
    // Free some memory
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   376
    unset($delete_list);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   377
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   378
    // Run the query
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   379
    $q = $db->sql_query($sql);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   380
    if ( !$q )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   381
      $db->_die('lang.php - couldn\'t kill off them old strings');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   382
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   383
    $insert_list = implode(",\n  ", $insert_list);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   384
    $sql = "INSERT INTO " . table_prefix . "language_strings(lang_id, string_category, string_name, string_content) VALUES\n  $insert_list;";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   385
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   386
    // Free some memory
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   387
    unset($insert_list);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   388
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   389
    // Run the query
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   390
    $q = $db->sql_query($sql);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   391
    if ( !$q )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   392
      $db->_die('lang.php - couldn\'t insert strings in import()');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   393
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   394
    // YAY! done!
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   395
    // This will regenerate the cache file if possible.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   396
    $this->regen_caches();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   397
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   398
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   399
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   400
   * Refetches the strings and writes out the cache file.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   401
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   402
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   403
  function regen_caches()
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   404
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   405
    global $db, $session, $paths, $template, $plugins; // Common objects
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   406
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   407
    $lang_file = ENANO_ROOT . "/cache/lang_{$this->lang_id}.php";
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   408
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   409
    // Refresh the strings in RAM to the latest copies in the DB
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   410
    $this->fetch(false);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   411
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   412
    $handle = @fopen($lang_file, 'w');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   413
    if ( !$handle )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   414
      // Couldn't open the file. Silently fail and let the strings come from the database.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   415
      return false;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   416
      
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   417
    // The file's open, that means we should be good.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   418
    fwrite($handle, '<?php
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   419
// This file was generated automatically by Enano. You should not edit this file because any changes you make
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   420
// to it will not be visible in the ACP and all changes will be lost upon any changes to strings in the admin panel.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   421
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   422
$lang_cache = ');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   423
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   424
    $exported = $this->var_export_string($this->strings);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   425
    if ( empty($exported) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   426
      // Ehh, that's not good
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   427
      $db->_die('lang.php - var_export_string() failed');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   428
    
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   429
    fwrite($handle, $exported . '; ?>');
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   430
    
210
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   431
    // Update timestamp in database
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   432
    $q = $db->sql_query('UPDATE ' . table_prefix . 'language SET last_changed = ' . time() . ' WHERE lang_id = ' . $this->lang_id . ';');
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   433
    if ( !$q )
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   434
      $db->_die('lang.php - updating timestamp on language');
2b283402e4e4 Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents: 209
diff changeset
   435
    
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   436
    // Done =)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   437
    fclose($handle);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   438
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   439
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   440
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   441
   * Calls var_export() on whatever, and returns the function's output.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   442
   * @param mixed Whatever you want var_exported. Usually an array.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   443
   * @return string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   444
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   445
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   446
  function var_export_string($val)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   447
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   448
    ob_start();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   449
    var_export($val);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   450
    $contents = ob_get_contents();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   451
    ob_end_clean();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   452
    return $contents;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   453
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   454
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   455
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   456
   * Fetches a language string from the cache in RAM. If it isn't there, it will call fetch() again and then try. If it still can't find it, it will ask for the string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   457
   * in the default language. If even then the string can't be found, this function will return what was passed to it.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   458
   *
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   459
   * This will also templatize strings. If a string contains variables in the format %foo%, you may specify the second parameter as an associative array in the format
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   460
   * of 'foo' => 'foo substitute'.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   461
   *
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   462
   * @param string ID of the string to fetch. This will always be in the format of category_stringid.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   463
   * @param array Optional. Associative array of substitutions.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   464
   * @return string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   465
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   466
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   467
  function get($string_id, $substitutions = false)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   468
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   469
    // Extract the category and string ID
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   470
    $category = substr($string_id, 0, ( strpos($string_id, '_') ));
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   471
    $string_name = substr($string_id, ( strpos($string_id, '_') + 1 ));
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   472
    $found = false;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   473
    if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   474
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   475
      $found = true;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   476
      $string = $this->strings[$category][$string_name];
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   477
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   478
    if ( !$found )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   479
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   480
      // Ehh, the string wasn't found. Rerun fetch() and try again.
243
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   481
      if ( defined('IN_ENANO_INSTALL') )
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   482
      {
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   483
        return $string_id;
a7d0f2711df1 Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents: 241
diff changeset
   484
      }
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   485
      $this->fetch();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   486
      if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   487
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   488
        $found = true;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   489
        $string = $this->strings[$category][$string_name];
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   490
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   491
      if ( !$found )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   492
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   493
        // STILL not found. Check the default language.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   494
        $lang_default = ( $x = getConfig('default_language') ) ? intval($x) : $this->lang_id;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   495
        if ( $lang_default != $this->lang_id )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   496
        {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   497
          if ( !is_object($this->default) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   498
            $this->default = new Language($lang_default);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   499
          return $this->default->get($string_id, $substitutions);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   500
        }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   501
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   502
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   503
    if ( !$found )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   504
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   505
      // Alright, it's nowhere. Return the input, grumble grumble...
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   506
      return $string_id;
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   507
    }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   508
    // Found it!
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   509
    // Perform substitutions.
209
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   510
    // if ( is_array($substitutions) )
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   511
    //   die('<pre>' . print_r($substitutions, true) . '</pre>');
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   512
    if ( !is_array($substitutions) )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   513
      $substitutions = array();
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   514
    return $this->substitute($string, $substitutions);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   515
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   516
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   517
  /**
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   518
   * Processes substitutions.
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   519
   * @param string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   520
   * @param array
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   521
   * @return string
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   522
   */
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   523
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   524
  function substitute($string, $subs)
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   525
  {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   526
    preg_match_all('/%this\.([a-z0-9_]+)%/', $string, $matches);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   527
    if ( count($matches[0]) > 0 )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   528
    {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   529
      foreach ( $matches[1] as $i => $string_id )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   530
      {
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   531
        $result = $this->get($string_id);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   532
        $string = str_replace($matches[0][$i], $result, $string);
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   533
      }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   534
    }
209
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   535
    preg_match_all('/%config\.([a-z0-9_]+)%/', $string, $matches);
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   536
    if ( count($matches[0]) > 0 )
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   537
    {
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   538
      foreach ( $matches[1] as $i => $string_id )
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   539
      {
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   540
        $result = getConfig($string_id);
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   541
        $string = str_replace($matches[0][$i], $result, $string);
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   542
      }
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   543
    }
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   544
    foreach ( $subs as $key => $value )
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   545
    {
209
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   546
      $subs[$key] = strval($value);
8a00247d1dee Login page mostly localized
Dan
parents: 205
diff changeset
   547
      $string = str_replace("%{$key}%", "{$subs[$key]}", $string);
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   548
    }
355
d15e4411ef65 Fixed a coupla minor bugs with the template_nodb class wrongly referencing $lang
Dan
parents: 348
diff changeset
   549
    return $string . '*';
205
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   550
  }
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   551
  
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   552
} // class Language
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   553
c4542792db2b Localization low-level framework added
Dan
parents:
diff changeset
   554
?>