Skip to content

Commit

Permalink
Revert addition of a simple Symphony class and move language storage …
Browse files Browse the repository at this point in the history
…from Symphony class to Lang.
  • Loading branch information
nilshoerrmann committed Oct 30, 2010
1 parent cd08d90 commit 4a8b6eb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 66 deletions.
45 changes: 15 additions & 30 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,31 @@ function __errorHandler($errno=NULL, $errstr, $errfile=NULL, $errline=NULL, $err
require_once(TOOLKIT . '/class.lang.php');
require_once(TOOLKIT . '/class.general.php');

/**
* Symphony Installation Class
*
* This is a simple Symphony class used as a placeholder for the main Symphony class
* which is not yet available during installation. This is needed for a consistent language management.
*/

Class Symphony {
// Initialize system language
function setLanguage() {
$lang = 'en';

private static $_lang;

public function lang(){
return self::$_lang;
// Fetch language requests
if(!empty($_REQUEST['lang'])){
$lang = preg_replace('/[^a-zA-Z\-]/', NULL, $_REQUEST['lang']);
}

public function setLanguage() {
self::$_lang = 'en';

if(!empty($_REQUEST['lang'])){
self::$_lang = preg_replace('/[^a-zA-Z\-]/', NULL, $_REQUEST['lang']);
}

try{
Lang::loadAll();
}
catch(Exception $s){
return NULL;
}

return self::$_lang;

// Set language
try{
Lang::set($lang);
}
catch(Exception $s){
return NULL;
}


return true;
}

/***********************
TESTS
************************/

// Check for PHP 5.2+

if(version_compare(phpversion(), '5.2', '<=')){

$code = '<?xml version="1.0" encoding="utf-8"?>
Expand Down
2 changes: 1 addition & 1 deletion symphony/content/content.login.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct(&$parent){

$this->Html->setElementStyle('html');
$this->Html->setDTD('<!DOCTYPE html>'); //PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"
$this->Html->setAttribute('lang', Symphony::lang());
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement('meta', NULL, array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8')), 0);
$this->addStylesheetToHead(URL . '/symphony/assets/login.css', 'screen', 40);

Expand Down
29 changes: 3 additions & 26 deletions symphony/lib/core/class.symphony.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
public static $Configuration;
public static $Database;
public static $Log;

private static $_lang;

public $Profiler;
public $Cookie;
Expand All @@ -52,12 +50,7 @@ protected function __construct(){
self::$Configuration->setArray($settings);

DateTimeObj::setDefaultTimezone(self::$Configuration->get('timezone', 'region'));

self::$_lang = (self::$Configuration->get('lang', 'symphony') ? self::$Configuration->get('lang', 'symphony') : 'en');

// Legacy support for __LANG__ constant
define_safe('__LANG__', self::lang());


define_safe('__SYM_DATE_FORMAT__', self::$Configuration->get('date_format', 'region'));
define_safe('__SYM_TIME_FORMAT__', self::$Configuration->get('time_format', 'region'));
define_safe('__SYM_DATETIME_FORMAT__', __SYM_DATE_FORMAT__ . ' ' . __SYM_TIME_FORMAT__);
Expand All @@ -75,14 +68,10 @@ protected function __construct(){
GenericExceptionHandler::$enabled = false;
}

Lang::loadAll();
Lang::set(self::$Configuration->get('lang', 'symphony'));

}

public function lang(){
return self::$_lang;
}

public function initialiseCookie(){

$cookie_path = @parse_url(URL, PHP_URL_PATH);
Expand Down Expand Up @@ -276,19 +265,7 @@ public function loginFromToken($token){
}

public function reloadLangFromAuthorPreference(){

$lang = $this->Author->get('language');
if($lang && $lang != self::lang()){
self::$_lang = $lang;
if($lang != 'en') {
Lang::loadAll();
}
else {
// As there is no English dictionary the default dictionary needs to be cleared
Lang::clear();
}
}

Lang::set($this->Author->get('language'));
}

public function resolvePageTitle($page_id) {
Expand Down
2 changes: 1 addition & 1 deletion symphony/lib/toolkit/class.administrationpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function build($context = NULL){
}

$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Symphony::lang());
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement('meta', NULL, array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8')), 0);
$this->addStylesheetToHead(URL . '/symphony/assets/symphony.duplicator.css', 'screen', 70);
$this->addScriptToHead(URL . '/symphony/assets/jquery.js', 50);
Expand Down
2 changes: 1 addition & 1 deletion symphony/lib/toolkit/class.devkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function buildIncludes() {

$this->Html->setElementStyle('html');
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', __LANG__);
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement(
'meta', null,
array(
Expand Down
42 changes: 35 additions & 7 deletions symphony/lib/toolkit/class.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function remove($string) {
*/
Class Lang {

private static $_lang;
private static $_dictionary;
private static $_transliterations;
private static $_dates;
Expand Down Expand Up @@ -142,6 +143,33 @@ public static function clear() {
self::$_dates = array();
}

/**
* Set system language
*
* @param string $lang language code
*/
public static function set($lang) {
if($lang && $lang != self::get()){
self::$_lang = $lang;

// Load dictionary
if($lang != 'en') {
self::loadAll();
}
else {
// As the English dictionary is the default, the dictionary just needs to be cleared
self::clear();
}
}
}

/**
* Get current language
*/
public static function get() {
return self::$_lang;
}

/**
* Load all language files (core and extensions)
*
Expand All @@ -151,22 +179,22 @@ public static function clear() {
public static function loadAll() {

// Load core localisations
$file = self::findLanguagePath(Symphony::lang()) . '/lang.%s.php';
$path = sprintf($file, Symphony::lang());
$file = self::findLanguagePath(self::get()) . '/lang.%s.php';
$path = sprintf($file, self::get());
if(file_exists($path)) {
self::load($file, Symphony::lang(), true);
self::load($file, self::get(), true);
}

// There is no need to load localisations for extensions during installation
// so check existence of Extension Manager first
if(class_exists(ExtensionManager)) {
$ExtensionManager = new ExtensionManager(Administration::instance());
$ExtensionManager = new ExtensionManager($this);

// Load extension localisations
foreach($ExtensionManager->listAll() as $handle => $e){
$path = $ExtensionManager->__getClassPath($handle) . '/lang/lang.%s.php';
if($e['status'] == EXTENSION_ENABLED && file_exists(sprintf($path, Symphony::lang()))){
self::load($path, Symphony::lang());
if($e['status'] == EXTENSION_ENABLED && file_exists(sprintf($path, self::get()))){
self::load($path, self::get());
}
}
}
Expand Down Expand Up @@ -355,7 +383,7 @@ public static function getLanguageCodes($path, $languages) {
* @return boolean
*/
public function isLocalized() {
return (Symphony::lang() != 'en');
return (self::get() != 'en');
}

/**
Expand Down

0 comments on commit 4a8b6eb

Please sign in to comment.