Language implementations

This commit is contained in:
dignajar 2015-06-28 23:51:48 -03:00
parent e2326baded
commit 256773cc89
7 changed files with 76 additions and 232 deletions

View File

@ -113,9 +113,9 @@
Language Language
<select name="language" class="width-50"> <select name="language" class="width-50">
<?php <?php
$htmlOptions = array('English'=>'english'); $htmlOptions = $Language->getLanguageList();
foreach($htmlOptions as $text=>$value) { foreach($htmlOptions as $locale=>$nativeName) {
echo '<option value="'.$value.'"'.( ($Site->language()===$value)?' selected="selected"':'').'>'.$text.'</option>'; echo '<option value="'.$locale.'"'.( ($Site->language()===$locale)?' selected="selected"':'').'>'.$nativeName.'</option>';
} }
?> ?>
</select> </select>

View File

@ -3,13 +3,44 @@
class dbLanguage extends dbJSON class dbLanguage extends dbJSON
{ {
public $en_US; public $en_US;
private $data;
function __construct($language) function __construct($language)
{ {
parent::__construct(PATH_LANGUAGES.'en_US.json', false); $this->data = array();
$this->en_US = $this->db;
parent::__construct(PATH_LANGUAGES.$language.'.json', false); // Default language en_US
$filename = PATH_LANGUAGES.'en_US.json';
if(file_exists($filename))
{
parent::__construct($filename, false);
$this->en_US = $this->db;
}
// User language
$filename = PATH_LANGUAGES.$language.'.json';
if(file_exists($filename))
{
parent::__construct($filename, false);
$this->data = $this->db['language-data'];
}
}
public function getLanguageList()
{
$files = glob(PATH_LANGUAGES.'*.json');
$tmp = array();
foreach($files as $file)
{
$t = new dbJSON($file, false);
$native = $t->db['language-data']['native'];
$locale = basename($file, '.json');
$tmp[$locale] = $native;
}
return $tmp;
} }
// Return the translation, if the translation does'n exist then return the English translation. // Return the translation, if the translation does'n exist then return the English translation.

View File

@ -17,7 +17,7 @@ class dbSite extends dbJSON
'uriPage'=> array('inFile'=>false, 'value'=>'/'), 'uriPage'=> array('inFile'=>false, 'value'=>'/'),
'uriPost'=> array('inFile'=>false, 'value'=>'/post/'), 'uriPost'=> array('inFile'=>false, 'value'=>'/post/'),
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'), 'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
//'url'=> array('inFile'=>false, 'value'=>''), 'url'=> array('inFile'=>false, 'value'=>''),
'advancedOptions'=> array('inFile'=>false, 'value'=>'false') 'advancedOptions'=> array('inFile'=>false, 'value'=>'false')
); );

View File

@ -2,23 +2,21 @@
class Text { class Text {
// New public static function addSlashes($string, $begin=true, $end=true)
public static function addSlashes($text, $begin=true, $end=true)
{ {
if($begin) { if($begin) {
$text = '/' . ltrim($text, '/'); $string = '/' . ltrim($string, '/');
} }
if($end) { if($end) {
$text = rtrim($text, '/') . '/'; $string = rtrim($string, '/') . '/';
} }
if($text=='//') { if($string=='//') {
return '/'; return '/';
} }
return $text; return $string;
} }
public static function endsWith($string, $endsString) public static function endsWith($string, $endsString)
@ -54,25 +52,25 @@ class Text {
return $text; return $text;
} }
public static function cleanUrl($text, $separator='-') public static function cleanUrl($string, $separator='-')
{ {
// Delete characters // Delete characters
$text = str_replace(array("", "", "!", "*", "&#039;", "&quot;", "(", ")", ";", ":", "@", "&amp", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$text); $string = str_replace(array("", "", "!", "*", "&#039;", "&quot;", "(", ")", ";", ":", "@", "&amp", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$string);
$text = preg_replace('![^\\pL\d]+!u', $separator, $text); $string = preg_replace('![^\\pL\d]+!u', $separator, $string);
// Remove spaces // Remove spaces
$text = str_replace(' ',$separator, $text); $string = str_replace(' ',$separator, $string);
//remove any additional characters that might appear after translit //remove any additional characters that might appear after translit
//$text = preg_replace('![^-\w]+!', '', $text); //$string = preg_replace('![^-\w]+!', '', $string);
// Replace multiple dashes // Replace multiple dashes
$text = preg_replace('/-{2,}/', $separator, $text); $string = preg_replace('/-{2,}/', $separator, $string);
// Make a string lowercase // Make a string lowercase
$text = self::lowercase($text); $string = self::lowercase($string);
return $text; return $string;
} }
// Replace all occurrences of the search string with the replacement string. // Replace all occurrences of the search string with the replacement string.
@ -150,115 +148,9 @@ class Text {
return false; return false;
} }
// Old public static function isNotEmpty($string)
public static function unserialize($string)
{ {
parse_str($string, $data); return !self::isEmpty($string);
// Clean magic quotes if this enabled
if(get_magic_quotes_gpc())
{
$data = self::clean_magic_quotes($data);
}
return($data);
}
public static function ajax_header($tmp)
{
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
$xml .= '<ajax>';
$xml .= $tmp;
$xml .= '</ajax>';
return( $xml );
}
// Clean magic quotes
public static function clean_magic_quotes($args)
{
$tmp_array = array();
foreach($args as $key => $arg)
{
$tmp_array[$key] = stripslashes($arg);
}
return($tmp_array);
}
public static function cut_text($text, $maxlength)
{
return( substr($text,0,strrpos(substr($text,0,$maxlength)," ")) );
}
public static function cut_words($text, $count)
{
$explode = explode(" ", $text);
if(count($explode) > $count)
{
array_splice($explode, $count);
$text = implode(' ', $explode);
}
return($text);
}
// Strip spaces
// Strip spaces
public static function strip_spaces($string)
{
return( str_replace(' ','',$string) );
}
// Strip quotes ' and "
public static function strip_quotes($text)
{
$text = str_replace('\'', '', $text);
$text = str_replace('"', '', $text);
return( $text );
}
function clean_non_alphanumeric($string)
{
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
return $string;
}
// RETURN
// TRUE - si contiene el substring
// FALSE - caso contrario
public static function is_substring($string, $substring)
{
return( strpos($string, $substring) !== false );
}
// RETURN
// TRUE - is not empty
// FALSE - is empty
public static function not_empty($string)
{
return( !self::is_empty($string) );
}
public static function is_empty($string)
{
$string = self::strip_spaces($string);
return( empty($string) );
}
// Compara 2 cadenas
// Retorna TRUE si son iguales, FALSE caso contrario
public static function compare($value1, $value2)
{
return( strcmp($value1, $value2) == 0 );
}
public static function replace_assoc(array $replace, $text)
{
return str_replace(array_keys($replace), array_values($replace), $text);
} }
} }

View File

@ -1,100 +0,0 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Site extends DB_SERIALIZE
{
function __construct()
{
parent::__construct(PATH_DATABASES.'site.php');
// Set timezone
$this->setTimezone( $this->timezone() );
// Set locale
$this->setLocale( $this->locale() );
}
// Returns an array with site configuration.
function get()
{
return $this->vars;
}
// Returns an array with the filters for the url.
public function urlFilters()
{
return $this->vars['urlFilters'];
}
// Returns the site title.
public function title()
{
return $this->vars['title'];
}
// Returns the site slogan.
public function slogan()
{
return $this->vars['slogan'];
}
// Returns the site theme name.
public function theme()
{
return $this->vars['theme'];
}
// Returns the admin theme name.
public function adminTheme()
{
return $this->vars['adminTheme'];
}
// Returns the footer text.
public function footer()
{
return $this->vars['footer'];
}
// Returns the timezone.
public function timezone()
{
return $this->vars['timezone'];
}
// Returns the current language.
public function language()
{
return $this->vars['language'];
}
// Returns the current locale.
public function locale()
{
return $this->vars['locale'];
}
// Returns the current homepage.
public function homepage()
{
return $this->vars['homepage'];
}
// Set the locale.
public function setLocale($locale)
{
if(setlocale(LC_ALL, $locale.'.UTF-8')!==false)
return true;
if(setlocale(LC_ALL, $locale.'.UTF8')!==false)
return true;
return setlocale(LC_ALL, $locale);
}
// Set the timezone.
public function setTimezone($timezone)
{
return date_default_timezone_set($timezone);
}
}

View File

@ -1,4 +1,14 @@
{ {
"language-data":
{
"native": "English (United State)",
"english-name": "English",
"last-update": "2015-06-28",
"author": "Diego",
"email": "",
"website": ""
},
"name": "Name", "name": "Name",
"first-name": "First Name", "first-name": "First Name",
"posted-by": "Posted by" "posted-by": "Posted by"

View File

@ -1,4 +1,15 @@
{ {
"first-name": "Nombres", "language-data":
"last-name": "Apellido" {
"native": "Español (Argentina)",
"english-name": "Spanish",
"last-update": "2015-06-28",
"author": "Diego",
"email": "",
"website": ""
},
"name": "Name",
"first-name": "First Name",
"posted-by": "Posted by"
} }