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
<select name="language" class="width-50">
<?php
$htmlOptions = array('English'=>'english');
foreach($htmlOptions as $text=>$value) {
echo '<option value="'.$value.'"'.( ($Site->language()===$value)?' selected="selected"':'').'>'.$text.'</option>';
$htmlOptions = $Language->getLanguageList();
foreach($htmlOptions as $locale=>$nativeName) {
echo '<option value="'.$locale.'"'.( ($Site->language()===$locale)?' selected="selected"':'').'>'.$nativeName.'</option>';
}
?>
</select>

View File

@ -3,13 +3,44 @@
class dbLanguage extends dbJSON
{
public $en_US;
private $data;
function __construct($language)
{
parent::__construct(PATH_LANGUAGES.'en_US.json', false);
$this->en_US = $this->db;
$this->data = array();
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.

View File

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

View File

@ -2,23 +2,21 @@
class Text {
// New
public static function addSlashes($text, $begin=true, $end=true)
public static function addSlashes($string, $begin=true, $end=true)
{
if($begin) {
$text = '/' . ltrim($text, '/');
$string = '/' . ltrim($string, '/');
}
if($end) {
$text = rtrim($text, '/') . '/';
$string = rtrim($string, '/') . '/';
}
if($text=='//') {
if($string=='//') {
return '/';
}
return $text;
return $string;
}
public static function endsWith($string, $endsString)
@ -54,25 +52,25 @@ class Text {
return $text;
}
public static function cleanUrl($text, $separator='-')
public static function cleanUrl($string, $separator='-')
{
// Delete characters
$text = str_replace(array("", "", "!", "*", "&#039;", "&quot;", "(", ")", ";", ":", "@", "&amp", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$text);
$text = preg_replace('![^\\pL\d]+!u', $separator, $text);
$string = str_replace(array("", "", "!", "*", "&#039;", "&quot;", "(", ")", ";", ":", "@", "&amp", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$string);
$string = preg_replace('![^\\pL\d]+!u', $separator, $string);
// Remove spaces
$text = str_replace(' ',$separator, $text);
$string = str_replace(' ',$separator, $string);
//remove any additional characters that might appear after translit
//$text = preg_replace('![^-\w]+!', '', $text);
//$string = preg_replace('![^-\w]+!', '', $string);
// Replace multiple dashes
$text = preg_replace('/-{2,}/', $separator, $text);
$string = preg_replace('/-{2,}/', $separator, $string);
// 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.
@ -150,115 +148,9 @@ class Text {
return false;
}
// Old
public static function unserialize($string)
public static function isNotEmpty($string)
{
parse_str($string, $data);
// 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);
return !self::isEmpty($string);
}
}

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",
"first-name": "First Name",
"posted-by": "Posted by"

View File

@ -1,4 +1,15 @@
{
"first-name": "Nombres",
"last-name": "Apellido"
"language-data":
{
"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"
}