Skip to content

Commit

Permalink
Merge pull request #851 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
Improve the Request and Language System, introduce the Support\Facades\Language
  • Loading branch information
daveismynamecom committed May 20, 2016
2 parents 8624644 + 203c35f commit 8f8f020
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 178 deletions.
4 changes: 2 additions & 2 deletions app/Config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
Config::set('classAliases', array(
'Config' => '\Core\Config',
'Errors' => '\Core\Error',
'Language' => '\Core\Language',
'Request' => '\Core\Request',
'Response' => '\Core\Response',
'Redirect' => '\Core\Redirect',
'Mail' => '\Helpers\Mailer',
Expand All @@ -161,7 +161,6 @@
'Paginator' => '\Helpers\Paginator',
'Password' => '\Helpers\Password',
'RainCaptcha' => '\Helpers\RainCaptcha',
'Request' => '\Helpers\Request',
'ReservedWords' => '\Helpers\ReservedWords',
'Session' => '\Helpers\Session',
'SimpleCurl' => '\Helpers\SimpleCurl',
Expand All @@ -172,6 +171,7 @@
'Auth' => '\Auth\Auth',
'DB' => '\Support\Facades\Database',
'Event' => '\Support\Facades\Event',
'Language' => '\Support\Facades\Language',
'Validator' => '\Support\Facades\Validator',
// The Legacy Mailer
'Helpers\PhpMailer\Mail' => '\Helpers\Mailer',
Expand Down
4 changes: 2 additions & 2 deletions app/Language/Ro/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// Metoda 'index'
'welcomeText' => 'Bun venit',
'welcomeMessage' => '
Bună, bun venit la controlerul <code>welcome</code>! <br/>
Bună, bun venit la controlerul <code>Welcome</code>! <br/>
Acest conținut poate fi modificat în <code>/app/Views/Welcome/Welcome.php</code>
',
// Metoda 'subpage'
'subpageText' => 'Subpagina',
'subpageMessage' => '
Bună, bun venit la controlerul <code>welcome</code> și metoda <code>subpage</code>! <br/>
Bună, bun venit la controlerul <code>Welcome</code> și metoda <code>subPage</code>! <br/>
Acest conținut poate fi modificat în <code>/app/Views/Welcome/SubPage.php</code>
',
// Butoane
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

use Core\Controller;
use Core\Redirect;
use Core\Request;
use Core\View;
use Helpers\Csrf;
use Helpers\Request;
use Helpers\Password;
use Helpers\Url;
use Auth;
Expand Down
25 changes: 16 additions & 9 deletions app/Templates/Default/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
* Default Layout - a Layout similar with the classic Header and Footer files.
*/

// Generate the Language Changer menu.
$language = Language::code();

$languages = Config::get('languages');

//
$html = '';

foreach ($languages as $code => $info) {
// Make bold the name of curent Language
$linkName = ($language == $code) ? '<b>' .$info['name'] .'</b>' : $info['name'];

$html .= '<a href="' .site_url('language/' .$code) .'">' .$linkName .'</a> | ' .PHP_EOL;
}

$langMenu = rtrim(trim($html), ' |') .PHP_EOL;
?>
<!DOCTYPE html>
<html lang="<?php echo LANGUAGE_CODE; ?>">
Expand All @@ -28,15 +43,7 @@

<div class="container">
<p class="pull-right">
<?php
$html = '';

foreach ($languages as $code => $info) {
$html .= '<a href="' .site_url('language/' .$code) .'">' .$info['name'] .'</a> | ' .PHP_EOL;
}

echo rtrim(trim($html), ' |') .PHP_EOL;
?>
<?= $langMenu; ?>
</p>
<div class="clearfix"></div>
<p>
Expand Down
25 changes: 16 additions & 9 deletions app/Templates/Default/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
* Default Header.
*/

// Generate the Language Changer menu.
$language = Language::code();

$languages = Config::get('languages');

//
$html = '';

foreach ($languages as $code => $info) {
// Make bold the name of curent Language
$linkName = ($language == $code) ? '<b>' .$info['name'] .'</b>' : $info['name'];

$html .= '<a href="' .site_url('language/' .$code) .'">' .$linkName .'</a> | ' .PHP_EOL;
}

$langMenu = rtrim(trim($html), ' |') .PHP_EOL;
?>
<!DOCTYPE html>
<html lang="<?php echo LANGUAGE_CODE; ?>">
Expand All @@ -28,15 +43,7 @@
<div class="container">

<p class="pull-right">
<?php
$html = '';

foreach ($languages as $code => $info) {
$html .= '<a href="' .site_url('language/' .$code) .'">' .$info['name'] .'</a> | ' .PHP_EOL;
}

echo rtrim(trim($html), ' |') .PHP_EOL;
?>
<?= $langMenu; ?>
</p>
<div class="clearfix"></div>

Expand Down
2 changes: 1 addition & 1 deletion system/Core/ClassicRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace Core;

use Core\Base\Router as BaseRouter;
use Core\Request;
use Core\Response;
use Core\Route;
use Helpers\Inflector;
use Helpers\Request;
use Helpers\Url;

/**
Expand Down
40 changes: 17 additions & 23 deletions system/Core/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,13 @@ public function messages()
}

/**
* Get the direction of current Language
* Get the current direction
*
* @param string $code Optional custom language code.
* @return string rtl or ltr
*/
public static function direction($code = LANGUAGE_CODE)
public function direction()
{
$code = self::getCurrentLanguage($code);

$languages = Config::get('languages');

if (isset($languages[$code])) {
$info = $languages[$code];

return $info['dir'];
}

return 'ltr';
return $this->direction;
}

/**
Expand Down Expand Up @@ -270,9 +259,17 @@ public function load($name, $code = LANGUAGE_CODE)
$file = APPDIR .'Language' .DS .ucfirst($code) .DS .$name .'.php';

// Check if it is readable.
if (is_readable($file)) {
// Require the file.
$this->legacyMessages[$code] = include $file;
if (! is_readable($file)) {
return;
}

// Require the file.
$messages = include $file;

if(isset($this->legacyMessages[$code]) && is_array($this->legacyMessages[$code])) {
$this->legacyMessages[$code] = array_merge($this->legacyMessages[$code], $messages);
} else {
$this->legacyMessages[$code] = $messages;
}
}

Expand Down Expand Up @@ -305,14 +302,11 @@ public function get($value, $code = LANGUAGE_CODE)
*
* @return string
*/
public static function show($value, $name, $code = LANGUAGE_CODE)
public function show($value, $name, $code = LANGUAGE_CODE)
{
// Use a fake Domain 'legacy', to avoid the standard Messages loading.
$instance = static::getInstance('legacy', $code);

// Load the specified Language file.
$instance->load($name, $code);
$this->load($name, $code);

return $instance->get($value, $code);
return $this->get($value, $code);
}
}
Loading

0 comments on commit 8f8f020

Please sign in to comment.