From 256773cc8973ca0242859d7a1e059bdba5960273 Mon Sep 17 00:00:00 2001 From: dignajar Date: Sun, 28 Jun 2015 23:51:48 -0300 Subject: [PATCH] Language implementations --- admin/views/settings.php | 6 +- kernel/dblanguage.class.php | 37 ++++++++- kernel/dbsite.class.php | 2 +- kernel/helpers/text.class.php | 138 ++++------------------------------ kernel/site.class.php | 100 ------------------------ languages/en_US.json | 10 +++ languages/es_ES.json | 15 +++- 7 files changed, 76 insertions(+), 232 deletions(-) delete mode 100644 kernel/site.class.php diff --git a/admin/views/settings.php b/admin/views/settings.php index d015b78e..cacdaa14 100644 --- a/admin/views/settings.php +++ b/admin/views/settings.php @@ -113,9 +113,9 @@ Language diff --git a/kernel/dblanguage.class.php b/kernel/dblanguage.class.php index 5585f4e7..35d3c2c7 100644 --- a/kernel/dblanguage.class.php +++ b/kernel/dblanguage.class.php @@ -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. diff --git a/kernel/dbsite.class.php b/kernel/dbsite.class.php index 31477db0..b5b8209c 100644 --- a/kernel/dbsite.class.php +++ b/kernel/dbsite.class.php @@ -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') ); diff --git a/kernel/helpers/text.class.php b/kernel/helpers/text.class.php index 047715ea..c6a7b1f5 100644 --- a/kernel/helpers/text.class.php +++ b/kernel/helpers/text.class.php @@ -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("“", "”", "!", "*", "'", """, "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$text); - $text = preg_replace('![^\\pL\d]+!u', $separator, $text); + $string = str_replace(array("“", "”", "!", "*", "'", """, "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$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 .= ''; - $xml .= $tmp; - $xml .= ''; - 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); } } diff --git a/kernel/site.class.php b/kernel/site.class.php deleted file mode 100644 index 3d38cff0..00000000 --- a/kernel/site.class.php +++ /dev/null @@ -1,100 +0,0 @@ -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); - } - -} diff --git a/languages/en_US.json b/languages/en_US.json index 0171d930..ef7506e0 100644 --- a/languages/en_US.json +++ b/languages/en_US.json @@ -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" diff --git a/languages/es_ES.json b/languages/es_ES.json index 6e0345cc..5ca49d05 100644 --- a/languages/es_ES.json +++ b/languages/es_ES.json @@ -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" } \ No newline at end of file