Add Internationalization
- Add Utils/L10n class - Add translator functions to PHP Renderer - Refactor web controllers to prevent duplicated code - Add locale middleware - Add translation file loading - Add i18n settings
This commit is contained in:
parent
13a2068a8b
commit
5b7bb030de
21 changed files with 537 additions and 245 deletions
|
|
@ -9,22 +9,10 @@ class Search extends BaseRoute
|
|||
{
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
|
||||
{
|
||||
if ($request->getAttribute('negotiation')->getMediaType() == 'application/json') {
|
||||
$controller = new \Friendica\Directory\Controllers\Api\Search(
|
||||
$this->container->atlas,
|
||||
$this->container->get('\Friendica\Directory\Models\Profile'),
|
||||
$this->container->l10n
|
||||
);
|
||||
} else {
|
||||
$controller = new \Friendica\Directory\Controllers\Web\Search(
|
||||
$this->container->atlas,
|
||||
$this->container->get('\Friendica\Directory\Models\Profile'),
|
||||
$this->container->get('\Friendica\Directory\Views\Widget\AccountTypeTabs'),
|
||||
$this->container->renderer,
|
||||
$this->container->l10n
|
||||
);
|
||||
}
|
||||
|
||||
return $controller->render($request, $response, $args);
|
||||
return (new \Friendica\Directory\Controllers\Api\Search(
|
||||
$this->container->atlas,
|
||||
$this->container->get('\Friendica\Directory\Models\Profile'),
|
||||
$this->container->l10n
|
||||
))->render($request, $response, $args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Http;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class Servers extends BaseRoute
|
||||
{
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
|
||||
{
|
||||
return (new \Friendica\Directory\Controllers\Web\Servers(
|
||||
$this->container->atlas,
|
||||
$this->container->renderer,
|
||||
$this->container->l10n,
|
||||
$this->container->simplecache)
|
||||
)->render($request, $response);
|
||||
}
|
||||
}
|
||||
44
src/classes/Routes/Web/BaseRoute.php
Normal file
44
src/classes/Routes/Web/BaseRoute.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Web;
|
||||
|
||||
use Friendica\Directory\Controllers\Web\BaseController;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
abstract class BaseRoute
|
||||
{
|
||||
/**
|
||||
* @var \Slim\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var BaseController
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
|
||||
{
|
||||
$defaults = [
|
||||
'languages' => $this->container->settings['i18n']['locales'],
|
||||
'lang' => $request->getAttribute('locale'),
|
||||
'baseUrl' => $request->getUri()->getBaseUrl(),
|
||||
'content' => '',
|
||||
'noNavSearch' => false
|
||||
];
|
||||
|
||||
$values = $this->controller->render($request, $response, $args);
|
||||
|
||||
$values = $values + $defaults;
|
||||
|
||||
// Render index view
|
||||
return $this->container->renderer->render($response, 'layout.phtml', $values);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Http;
|
||||
namespace Friendica\Directory\Routes\Web;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class Directory extends BaseRoute
|
||||
{
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
return (new \Friendica\Directory\Controllers\Web\Directory(
|
||||
parent::__construct($container);
|
||||
|
||||
$this->controller = new \Friendica\Directory\Controllers\Web\Directory(
|
||||
$this->container->atlas,
|
||||
$this->container->get('\Friendica\Directory\Models\Profile'),
|
||||
$this->container->get('\Friendica\Directory\Views\Widget\AccountTypeTabs'),
|
||||
$this->container->renderer,
|
||||
$this->container->l10n)
|
||||
)->render($request, $response, $args);
|
||||
$this->container->l10n
|
||||
);
|
||||
}
|
||||
}
|
||||
22
src/classes/Routes/Web/Search.php
Normal file
22
src/classes/Routes/Web/Search.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Web;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class Search extends BaseRoute
|
||||
{
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$this->controller = new \Friendica\Directory\Controllers\Web\Search(
|
||||
$this->container->atlas,
|
||||
$this->container->get('\Friendica\Directory\Models\Profile'),
|
||||
$this->container->get('\Friendica\Directory\Views\Widget\AccountTypeTabs'),
|
||||
$this->container->renderer,
|
||||
$this->container->l10n
|
||||
);
|
||||
}
|
||||
}
|
||||
21
src/classes/Routes/Web/Servers.php
Normal file
21
src/classes/Routes/Web/Servers.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Web;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class Servers extends BaseRoute
|
||||
{
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$this->controller = new \Friendica\Directory\Controllers\Web\Servers(
|
||||
$this->container->atlas,
|
||||
$this->container->renderer,
|
||||
$this->container->l10n,
|
||||
$this->container->simplecache
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue