Modifications on Language system, improve locales

This commit is contained in:
Diego Najar 2017-09-03 23:29:09 +02:00
parent a1fccbac14
commit 6e003f051e
15 changed files with 248 additions and 64 deletions

View File

@ -33,7 +33,7 @@ class dbJSON
$array = $this->unserialize($implode); $array = $this->unserialize($implode);
if(empty($array)) { if(empty($array)) {
Log::set(__METHOD__.LOG_SEP.'Invalid JSON file: '.$file.', cannot be decoded. Check the file content.'); //Log::set(__METHOD__.LOG_SEP.'Invalid JSON file: '.$file.', cannot be decoded. Check the file content.');
} }
else { else {
$this->db = $array; $this->db = $array;

View File

@ -10,7 +10,7 @@
<div class="uk-panel"> <div class="uk-panel">
<h4><a href="<?php echo HTML_PATH_ADMIN_ROOT.'pages' ?>"><i class="uk-icon-folder-o"></i> <?php $L->p('Manage content') ?></a></h4> <h4><a href="<?php echo HTML_PATH_ADMIN_ROOT.'pages' ?>"><i class="uk-icon-folder-o"></i> <?php $L->p('Manage content') ?></a></h4>
<p><?php $L->p('Edit or delete pages from your site') ?></p> <p><?php $L->p('Edit or delete content from your site') ?></p>
</div> </div>
</div> </div>
@ -19,7 +19,7 @@
<div class="uk-panel"> <div class="uk-panel">
<h4><a href="<?php echo HTML_PATH_ADMIN_ROOT.'new-category' ?>"><i class="uk-icon-file-text-o"></i> <?php $L->p('New category') ?></a></h4> <h4><a href="<?php echo HTML_PATH_ADMIN_ROOT.'new-category' ?>"><i class="uk-icon-file-text-o"></i> <?php $L->p('New category') ?></a></h4>
<p><?php $L->p('Create a new category to organize your pages') ?></p> <p><?php $L->p('Create a new category to organize your content') ?></p>
</div> </div>
<div class="uk-panel"> <div class="uk-panel">
@ -65,6 +65,17 @@
<h4 class="panel-title"><?php $L->p('Notifications') ?></h4> <h4 class="panel-title"><?php $L->p('Notifications') ?></h4>
<ul class="uk-list uk-list-line"> <ul class="uk-list uk-list-line">
<?php <?php
// Print New version if the plugin Version is installed
if (pluginEnabled('Version')) {
if ($plugins['all']['pluginVersion']->newVersion()) {
echo '<li>';
echo '<b>'.$L->g('New version available').'</b>';
echo '<br><a href="https://www.bludit.com" target="_black">Bludit.com</a>';
echo '</li>';
}
}
// Print Notifications
$logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT); $logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT);
foreach($logs as $log) { foreach($logs as $log) {
$dict = $L->g($log['dictionaryKey']); $dict = $L->g($log['dictionaryKey']);
@ -77,7 +88,6 @@
echo Date::format($log['date'], DB_DATE_FORMAT, NOTIFICATIONS_DATE_FORMAT); echo Date::format($log['date'], DB_DATE_FORMAT, NOTIFICATIONS_DATE_FORMAT);
echo ' - by '.$log['username']; echo ' - by '.$log['username'];
echo '</span>'; echo '</span>';
echo '</li>'; echo '</li>';
} }
?> ?>

View File

@ -13,3 +13,7 @@ printTable('Loaded extensions',get_loaded_extensions());
// Site object // Site object
printTable('$Site object database',$Site->db); printTable('$Site object database',$Site->db);
// Locales installed
exec('locale -a', $locales);
printTable('Locales installed', $locales);

View File

@ -154,7 +154,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'name'=>'date', 'name'=>'date',
'value'=>$page->dateRaw(), 'value'=>$page->dateRaw(),
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'tip'=>$L->g('To schedule the page just select the date and time'), 'tip'=>$L->g('To schedule the page select the date and time'),
'label'=>$L->g('Date') 'label'=>$L->g('Date')
)); ));
@ -203,7 +203,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'name'=>'slug', 'name'=>'slug',
'value'=>$page->slug(), 'value'=>$page->slug(),
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'tip'=>$L->g('you-can-modify-the-url-which-identifies'), 'tip'=>$L->g('URL associated with the page'),
'label'=>$L->g('Friendly URL') 'label'=>$L->g('Friendly URL')
)); ));

View File

@ -132,7 +132,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'name'=>'date', 'name'=>'date',
'value'=>Date::current(DB_DATE_FORMAT), 'value'=>Date::current(DB_DATE_FORMAT),
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'tip'=>$L->g('To schedule the page just select the date and time'), 'tip'=>$L->g('To schedule the page select the date and time'),
'label'=>$L->g('Date') 'label'=>$L->g('Date')
)); ));
@ -177,7 +177,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'name'=>'slug', 'name'=>'slug',
'value'=>'', 'value'=>'',
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'tip'=>$L->g('You can modify the URL which identifies a page...'), 'tip'=>$L->g('URL associated with the page'),
'label'=>$L->g('Friendly URL') 'label'=>$L->g('Friendly URL')
)); ));

View File

@ -48,7 +48,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'options'=>array('date'=>'Date','position'=>'Position'), 'options'=>array('date'=>'Date','position'=>'Position'),
'selected'=>$Site->orderBy(), 'selected'=>$Site->orderBy(),
'class'=>'uk-width-1-3 uk-form-medium', 'class'=>'uk-width-1-3 uk-form-medium',
'tip'=>$L->g('Order the content by date to build a Blog or order the content by position to build a Website.') 'tip'=>$L->g('Order the content by position to build a Website')
)); ));
HTML::legend(array('value'=>$L->g('Email account settings'))); HTML::legend(array('value'=>$L->g('Email account settings')));

View File

@ -63,8 +63,8 @@ HTML::formClose();
$(document).ready(function() { $(document).ready(function() {
$("#jslanguage").change(function () { $("#jslanguage").change(function () {
var locale = $("#jslanguage option:selected").val(); $("#jslocale").attr("value", "<?php $L->p('You can change this field when save the current changes') ?>");
$("#jslocale").attr("value",locale); $("#jslocale").attr("disabled", true);
}); });
}); });

View File

@ -111,7 +111,7 @@ define('CLI_STATUS', 'published');
define('CLI_USERNAME', 'admin'); define('CLI_USERNAME', 'admin');
// Filename // Filename
define('FILENAME', 'index.txt'); define('FILENAME', 'index.md');
// Database date format // Database date format
define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); define('DB_DATE_FORMAT', 'Y-m-d H:i:s');
@ -264,7 +264,7 @@ define('HTML_PATH_PLUGINS', HTML_PATH_ROOT.'bl-plugins/');
define('JQUERY', HTML_PATH_ROOT.'bl-kernel/js/jquery.min.js'); define('JQUERY', HTML_PATH_ROOT.'bl-kernel/js/jquery.min.js');
// --- Objects with dependency --- // --- Objects with dependency ---
$Language = new dbLanguage( $Site->locale() ); $Language = new dbLanguage( $Site->language() );
$Login = new Login( $dbUsers ); $Login = new Login( $dbUsers );
$Url->checkFilters( $Site->uriFilters() ); $Url->checkFilters( $Site->uriFilters() );

View File

@ -4,31 +4,30 @@ class dbLanguage extends dbJSON
{ {
public $data; public $data;
public $db; public $db;
public $currentLocale; public $currentLanguage;
function __construct($locale) function __construct($currentLanguage)
{ {
$this->data = array(); $this->data = array();
$this->db = array(); $this->db = array();
$this->currentLocale = 'en_US'; $this->currentLanguage = $currentLanguage;
// Default language en_US // Load default language
$filename = PATH_LANGUAGES.'en_US.json'; $filename = PATH_LANGUAGES.DEFAULT_LANGUAGE_FILE;
if( Sanitize::pathFile($filename) ) if (Sanitize::pathFile($filename)) {
{
$Tmp = new dbJSON($filename, false); $Tmp = new dbJSON($filename, false);
$this->db = array_merge($this->db, $Tmp->db); $this->db = array_merge($this->db, $Tmp->db);
} }
// User language // If the user defined a new language replace the content of the default language
$filename = PATH_LANGUAGES.$locale.'.json'; // If the new dictionary has missing keys this are going to take from the default language
if( Sanitize::pathFile($filename) && ($locale!=="en_US") ) $filename = PATH_LANGUAGES.$currentLanguage.'.json';
{ if (Sanitize::pathFile($filename) && (DEFAULT_LANGUAGE_FILE!==$currentLanguage.'.json')) {
$this->currentLocale = $locale;
$Tmp = new dbJSON($filename, false); $Tmp = new dbJSON($filename, false);
$this->db = array_merge($this->db, $Tmp->db); $this->db = array_merge($this->db, $Tmp->db);
} }
// Language-data
$this->data = $this->db['language-data']; $this->data = $this->db['language-data'];
unset($this->db['language-data']); unset($this->db['language-data']);
} }
@ -38,81 +37,79 @@ class dbLanguage extends dbJSON
return isset( $this->db[$key] ); return isset( $this->db[$key] );
} }
public function getCurrentLocale() public function locale()
{ {
return $this->currentLocale; if (isset($this->data['locale'])) {
return $this->data['locale'];
}
return $this->currentLanguage;
} }
// Return the translation, if the translation does'n exist then return the English translation. // Return the translation, if the translation doesn't exist returns the English translation
public function get($string) public function get($string)
{ {
$key = Text::lowercase($string); $key = Text::lowercase($string);
$key = Text::replace(' ', '-', $key); $key = Text::replace(' ', '-', $key);
#file_put_contents(DEBUG_FILE, $key.PHP_EOL, FILE_APPEND); //file_put_contents(DEBUG_FILE, $key.PHP_EOL, FILE_APPEND);
if(isset($this->db[$key])) { if (isset($this->db[$key])) {
return $this->db[$key]; return $this->db[$key];
} }
return 'NO AVAILABLE: '.$string;
return $string; return $string;
} }
// Returns translation. // Returns translation
public function g($string) public function g($string)
{ {
return $this->get($string); return $this->get($string);
} }
// Print translation. // Print translation
public function printMe($string) public function printMe($string)
{ {
echo $this->get($string); echo $this->get($string);
} }
// Print translation. // Print translation
public function p($string) public function p($string)
{ {
echo $this->get($string); echo $this->get($string);
} }
// Add more keys=>values to the current dicionary // Add keys=>values to the current dicionary
// Will be overwrite if exist the key with the new value // This method overwrite the key=>value
public function add($array) public function add($array)
{ {
$this->db = array_merge($array, $this->db); $this->db = array_merge($array, $this->db);
} }
// Returns the item from plugin-data. // Returns the item from language-data
public function getData($key) public function getData($key)
{ {
if(isset($this->data[$key])) { if (isset($this->data[$key])) {
return $this->data[$key]; return $this->data[$key];
} }
return ''; return false;
} }
// Returns an array with all dictionaries. // Returns an array with all dictionaries
public function getLanguageList() public function getLanguageList()
{ {
$files = Filesystem::listFiles(PATH_LANGUAGES, '*', 'json'); $files = Filesystem::listFiles(PATH_LANGUAGES, '*', 'json');
$tmp = array(); $tmp = array();
foreach($files as $file) {
foreach($files as $file)
{
$t = new dbJSON($file, false); $t = new dbJSON($file, false);
if (isset($t->db['language-data']['native'])) {
// Check if the JSON is complete.
if(isset($t->db['language-data']['native']))
{
$native = $t->db['language-data']['native']; $native = $t->db['language-data']['native'];
$locale = basename($file, '.json'); $locale = basename($file, '.json');
$tmp[$locale] = $native; $tmp[$locale] = $native;
} }
} }
return $tmp; return $tmp;
} }
} }

View File

@ -49,8 +49,8 @@ class dbSite extends dbJSON
public function set($args) public function set($args)
{ {
foreach($args as $field=>$value) { foreach ($args as $field=>$value) {
if( isset($this->dbFields[$field]) ) { if (isset($this->dbFields[$field])) {
$this->db[$field] = Sanitize::html($value); $this->db[$field] = Sanitize::html($value);
} }
} }
@ -290,18 +290,22 @@ class dbSite extends dbJSON
return $homepage; return $homepage;
} }
// Set the locale. // Set the locale, returns TRUE is success, FALSE otherwise
public function setLocale($locale) public function setLocale($locale)
{ {
if(setlocale(LC_ALL, $locale.'.UTF-8')!==false) { $localeList = explode(',', $locale);
return true; foreach ($localeList as $locale) {
$locale = trim($locale);
if (setlocale(LC_ALL, $locale.'.UTF-8')!==false) {
return true;
}
elseif (setlocale(LC_ALL, $locale)!==false) {
return true;
}
} }
if(setlocale(LC_ALL, $locale.'.UTF8')!==false) { // Not was possible to set a locale, using default locale
return true; return false;
}
return setlocale(LC_ALL, $locale);
} }
// Set the timezone. // Set the timezone.

View File

@ -498,6 +498,17 @@ function editSettings($args) {
global $Site; global $Site;
global $Syslog; global $Syslog;
if (isset($args['language'])) {
if ($args['language']!=$Site->language()) {
$tmp = new dbJSON(PATH_LANGUAGES.$args['language'].'.json', false);
if (isset($tmp->db['language-data']['locale'])) {
$args['locale'] = $tmp->db['language-data']['locale'];
} else {
$args['locale'] = $args['language'];
}
}
}
if( $Site->set($args) ) { if( $Site->set($args) ) {
// Add to syslog // Add to syslog
$Syslog->add(array( $Syslog->add(array(

151
bl-languages/en.json Normal file
View File

@ -0,0 +1,151 @@
{
"language-data":
{
"native": "English",
"english-name": "English",
"locale": "en, en_AU, en_CA, en_GB, en_IE, en_NZ, en_US",
"last-update": "2017-09-03",
"author": "Bludit",
"email": "",
"website": "https://www.bludit.com"
},
"dashboard": "Dashboard",
"manage-users": "Manage users",
"manage-categories": "Manage categories",
"general-settings": "General settings",
"advanced-settings": "Advanced settings",
"language": "Language",
"plugins": "Plugins",
"themes": "Themes",
"about": "About",
"url": "URL",
"fixed": "Fixed",
"welcome": "Welcome",
"logout": "Log out",
"website": "Website",
"publish": "Publish",
"manage": "Manage",
"content": "Content",
"category": "Category",
"categories": "Categories",
"users": "Users",
"settings": "Settings",
"general": "General",
"advanced": "Advanced",
"new-content": "New content",
"manage-content": "Manage content",
"add-new-content": "Add new content",
"new-category": "New category",
"add-a-new-user": "Add a new user",
"url-associated-with-the-page": "URL associated with the page.",
"language-and-timezone": "Language and timezone",
"change-your-language-and-region-settings": "Change your language and region settings.",
"notifications": "Notifications",
"plugin-installed": "Plugin installed",
"new-theme-configured": "New theme configured",
"changes-on-settings": "Changes on settings",
"plugin-configured": "Plugin configured",
"welcome-to-bludit": "Welcome to Bludit",
"statistics": "Statistics",
"pages": "Pages",
"drafts": "Drafts",
"title": "Title",
"save": "Save",
"save-as-draft": "Save as draft",
"cancel": "Cancel",
"description": "Description",
"this-field-can-help-describe-the-content": "This field can help describe the content in a few words. No more than 150 characters.",
"images": "Images",
"error": "Error",
"supported-image-file-types": "Supported image file types",
"cover-image": "Cover image",
"drag-and-drop-or-click-here": "Drag and drop or click here",
"there-are-no-images": "There are no images",
"upload-and-more-images": "Upload and more images",
"click-on-the-image-for-options": "Click on the image for options.",
"click-here-to-cancel": "Click here to cancel.",
"insert-image": "Insert image",
"set-as-cover-image": "Set as cover image",
"delete-image": "Delete image",
"tags": "Tags",
"add": "Add",
"status": "Status",
"published": "Published",
"draft": "Draft",
"date": "Date",
"external-cover-image": "External cover image",
"parent": "Parent",
"image-url": "Image URL",
"position": "Position",
"friendly-url": "Friendly URL",
"image-description": "Image description",
"add-a-new-category": "Add a new category",
"name": "Name",
"username": "Username",
"first-name": "First name",
"last-name": "Last name",
"to-schedule-the-page-select-the-date-and-time": "To schedule the page select the date and time.",
"email": "Email",
"role": "Role",
"registered": "Registered",
"site-information": "Site information",
"site-title": "Site title",
"use-this-field-to-name-your-site": "Use this field to name your site, it will appear at the top of every page of your site.",
"site-slogan": "Site slogan",
"use-this-field-to-add-a-catchy-phrase": "Use this field to add a catchy phrase on your site.",
"site-description": "Site description",
"you-can-add-a-site-description-to-provide": "You can add a site description to provide a short bio or description of your site.",
"footer-text": "Footer text",
"you-can-add-a-small-text-on-the-bottom": "You can add a small text on the bottom of every page. eg: copyright, owner, dates, etc.",
"social-networks-links": "Social networks links",
"site-url": "Site url",
"the-url-of-your-site": "The URL of your site.",
"default-home-page": "Default home page",
"email-account-settings": "Email account settings",
"sender-email": "Sender email",
"emails-will-be-sent-from-this-address": "Emails will be sent from this address.",
"url-filters": "URL filters",
"select-your-sites-language": "Select your site's language.",
"timezone": "Timezone",
"select-a-timezone-for-a-correct": "Select a timezone for a correct date\/time display on your site.",
"locale": "Locale",
"you-can-use-this-field-to-define-a-set-of": "You can use this field to define a set of parameters related to the language, country and special preferences.",
"date-and-time-formats": "Date and time formats",
"date-format": "Date format",
"current-format": "Current format",
"version": "Version",
"author": "Author",
"activate": "Activate",
"deactivate": "Deactivate",
"edit-category": "Edit category",
"delete": "Delete",
"password": "Password",
"confirm-password": "Confirm Password",
"editor": "Editor",
"administrator": "Administrator",
"edit-user": "Edit user",
"edit-content": "Edit content",
"profile": "Profile",
"change-password": "Change password",
"enabled": "Enabled",
"disable-the-user": "Disable the user",
"profile-picture": "Profile picture",
"edit-or-delete-your-categories": "Edit or delete your categories",
"create-a-new-page-for-your-site": "Create a new page for your site",
"create-a-new-category-to-organize-your-content": "Create a new category to organize your content",
"confirm-delete-this-action-cannot-be-undone": "Confirm delete, this action cannot be undone.",
"do-you-want-to-disable-the-user": "Do you want to disable the user ?",
"new-password": "New password",
"you-can-change-this-field-when-save-the-current-changes": "You can change this field when save the current changes.",
"items-per-page": "Items per page",
"invite-a-friend-to-collaborate-on-your-site": "Invite a friend to collaborate on your site",
"number-of-items-to-show-per-page": "Number of items to show per page",
"website-or-blog": "Website or Blog",
"scheduled-pages": "Scheduled pages",
"there-are-no-scheduled-pages": "There are no scheduled pages",
"there-are-no-draft-pages": "There are no draft pages",
"order-content-by": "Order content By",
"edit-or-delete-content-from-your-site": "Edit or delete content from your site",
"order-the-content-by-position-to-build-a-website": "Order the content by position to build a Website or order the content by date to build a Blog."
}

View File

@ -27,6 +27,7 @@ class pluginVersion extends Plugin {
public function adminBodyEnd() public function adminBodyEnd()
{ {
global $ADMIN_CONTROLLER; global $ADMIN_CONTROLLER;
global $Language;
$timeToCheck = Session::get('timeToCheck') + 10*60; $timeToCheck = Session::get('timeToCheck') + 10*60;
if( ($ADMIN_CONTROLLER=='dashboard') && ($timeToCheck<time()) ) { if( ($ADMIN_CONTROLLER=='dashboard') && ($timeToCheck<time()) ) {
@ -35,19 +36,24 @@ class pluginVersion extends Plugin {
Session::set('version', $versions['version']); Session::set('version', $versions['version']);
} }
if( version_compare(Session::get('version'), BLUDIT_VERSION, '>') ) { if ($this->newVersion()) {
$html = '<div id="plugin-version"><a href="https://www.bludit.com">New version available</a></div>'; $html = '<div id="plugin-version"><a href="https://www.bludit.com">'.$Language->get('New version available').'</a></div>';
} else { } else {
if(defined('BLUDIT_PRO')) { if(defined('BLUDIT_PRO')) {
$html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>'; $html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else { } else {
$html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="">Upgrade to Bludit PRO</a></div>'; $html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="https://pro.bludit.com">'.$Language->get('Upgrade to Bludit PRO').'</a></div>';
} }
} }
return $html; return $html;
} }
public function newVersion()
{
return version_compare(Session::get('version'), BLUDIT_VERSION, '>');
}
private function getVersion() private function getVersion()
{ {
$url = 'https://version.bludit.com'; $url = 'https://version.bludit.com';

View File

@ -1,5 +1,6 @@
<?php <?php
$GITHUB_BASE_URL = '__GITHUB_BASE_URL__'; $GITHUB_BASE_URL = '__GITHUB_BASE_URL__';
$HOW_TO_EDIT_LINK = '__HOW_TO_EDIT_LINK__';
if (!$Site->homepage()) { if (!$Site->homepage()) {
echo 'This theme need a home page defined, please select one page on <b>Admin panel->Settings->Advanced->Home page</b>'; echo 'This theme need a home page defined, please select one page on <b>Admin panel->Settings->Advanced->Home page</b>';

View File

@ -25,7 +25,7 @@
<div class="edit-this-page"> <div class="edit-this-page">
<?php <?php
echo '<a class="pure-button pure-button-primary" href="'.$GITHUB_BASE_URL.$Page->key().'/'.FILENAME.'"><i class="fa fa-pencil"></i> Edit this page</a>'; echo '<a class="pure-button pure-button-primary" href="'.$GITHUB_BASE_URL.$Page->key().'/'.FILENAME.'"><i class="fa fa-pencil"></i> Edit this page</a>';
echo '<a class="pure-button" href="'.$GITHUB_BASE_URL.$Page->key().'/'.FILENAME.'"><i class="fa fa-info-circle"></i> How to edit this page ?</a>'; echo '<a class="pure-button" href="'.$HOW_TO_EDIT_LINK.'"><i class="fa fa-info-circle"></i> How to edit this page ?</a>';
?> ?>
</div> </div>