Commit 222066eb authored by Tino Goratsch's avatar Tino Goratsch

- renamed the Lang class to Translator and moved it into its own namespace

- added the possibility to use replace placeholder using the Translator::t() method
parent bab0d1f2
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use Symfony\Component\DependencyInjection\Container;
/**
......@@ -34,7 +35,7 @@ class Breadcrumb
*/
protected $container;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -52,14 +53,14 @@ class Breadcrumb
/**
* @param \Symfony\Component\DependencyInjection\Container $container
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\Config $config
*/
public function __construct(
Container $container,
Lang $lang,
Translator $lang,
RequestInterface $request,
Router $router,
Config $config
......
......@@ -2,6 +2,8 @@
namespace ACP3\Core;
use ACP3\Core\I18n\Translator;
/**
* Class Date
* @package ACP3\Core
......@@ -26,7 +28,7 @@ class Date
protected $dateTimeZone;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -35,13 +37,13 @@ class Date
protected $config;
/**
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Config $config
* @param \ACP3\Core\User $user
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Config $config
*/
public function __construct(
User $user,
Lang $lang,
Translator $lang,
Config $config
)
{
......
......@@ -6,8 +6,7 @@ use ACP3\Core\Helpers\DataGrid\ColumnPriorityQueue;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\ColumnRendererInterface;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\MassActionColumnRenderer;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\OptionColumnRenderer;
use ACP3\Core\Lang;
use ACP3\Core\View;
use ACP3\Core\I18n\Translator;
/**
* Class DataGrid
......@@ -20,7 +19,7 @@ class DataGrid
*/
protected $acl;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -65,12 +64,12 @@ class DataGrid
protected $primaryKey = '';
/**
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\I18n\Translator $lang
*/
public function __construct(
ACL $acl,
Lang $lang
Translator $lang
)
{
$this->acl = $acl;
......
......@@ -3,7 +3,7 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\Event\CustomOptionEvent;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\OptionColumnRenderer\OptionRenderer;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Router;
use Symfony\Component\EventDispatcher\EventDispatcher;
......@@ -16,7 +16,7 @@ class OptionColumnRenderer extends AbstractColumnRenderer
const NAME = 'options';
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -29,12 +29,12 @@ class OptionColumnRenderer extends AbstractColumnRenderer
protected $optionRenderer;
/**
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Helpers\DataGrid\ColumnRenderer\OptionColumnRenderer\OptionRenderer $optionRenderer
* @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher
*/
public function __construct(
Lang $lang,
Translator $lang,
OptionRenderer $optionRenderer,
EventDispatcher $eventDispatcher
)
......
<?php
namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer\OptionColumnRenderer;
use ACP3\Core\Lang;
use ACP3\Core\Router;
/**
......
<?php
namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
/**
* Class TranslateColumnRenderer
......@@ -18,9 +19,9 @@ class TranslateColumnRenderer extends AbstractColumnRenderer
/**
* TranslateColumnRenderer constructor.
*
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
*/
public function __construct(Lang $lang)
public function __construct(Translator $lang)
{
$this->lang = $lang;
}
......
......@@ -2,7 +2,7 @@
namespace ACP3\Core\Helpers;
use ACP3\Core\Http\Request;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Validation\ValidationRules\DateValidationRule;
/**
......@@ -16,7 +16,7 @@ class Date
*/
protected $date;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -36,14 +36,14 @@ class Date
* Date constructor.
*
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Http\Request $request
* @param \ACP3\Core\Helpers\Forms $formsHelper
* @param \ACP3\Core\Validation\ValidationRules\DateValidationRule $dateValidationRule
*/
public function __construct(
\ACP3\Core\Date $date,
Lang $lang,
Translator $lang,
Request $request,
Forms $formsHelper,
DateValidationRule $dateValidationRule
......
......@@ -3,7 +3,7 @@ namespace ACP3\Core\Helpers\Formatter;
use ACP3\Core\Date;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
/**
* Class DateRange
......@@ -16,17 +16,17 @@ class DateRange
*/
protected $date;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\I18n\Translator $lang
*/
public function __construct(
Date $date,
Lang $lang
Translator $lang
)
{
$this->date = $date;
......@@ -48,7 +48,11 @@ class DateRange
if (empty($end)) {
$title = $this->date->format($start, $format);
} else {
$title = sprintf($this->lang->t('system', 'date_published_since'), $this->date->format($start, $format));
$title = $this->lang->t(
'system',
'date_published_since',
['%date%' => $this->date->format($start, $format)]
);
}
return $this->generateTimeTag($start, $format, $title);
} else {
......
<?php
namespace ACP3\Core\Helpers\Formatter;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
/**
* Class MarkEntries
......@@ -10,16 +10,16 @@ use ACP3\Core\Lang;
class MarkEntries
{
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
* MarkEntries constructor.
*
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
*/
public function __construct(Lang $lang)
public function __construct(Translator $lang)
{
$this->lang = $lang;
}
......
......@@ -3,7 +3,7 @@ namespace ACP3\Core\Helpers;
use ACP3\Core\Http\Request;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
/**
* Class Forms
......@@ -12,7 +12,7 @@ use ACP3\Core\Lang;
class Forms
{
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -21,11 +21,11 @@ class Forms
protected $request;
/**
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Http\RequestInterface $request
*/
public function __construct(
Lang $lang,
Translator $lang,
RequestInterface $request
)
{
......
......@@ -14,7 +14,7 @@ class TableOfContents
*/
protected $breadcrumb;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -42,7 +42,7 @@ class TableOfContents
* TableOfContents constructor.
*
* @param \ACP3\Core\Breadcrumb $breadcrumb
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\SEO $seo
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router $router
......@@ -51,7 +51,7 @@ class TableOfContents
*/
public function __construct(
Core\Breadcrumb $breadcrumb,
Core\Lang $lang,
Core\I18n\Translator $lang,
Core\SEO $seo,
Core\Http\RequestInterface $request,
Core\Router $router,
......@@ -163,10 +163,12 @@ class TableOfContents
{
if ($titlesFromDb === false && is_array($page) === false) {
$attributes = $this->_getHtmlAttributes($page);
return !empty($attributes['title']) ? $attributes['title'] : sprintf($this->lang->t('system', 'toc_page'), $pageNumber);
return !empty($attributes['title']) ? $attributes['title'] : $this->lang->t('system', 'toc_page',
['%page%' => $pageNumber]);
}
return !empty($page['title']) ? $page['title'] : sprintf($this->lang->t('system', 'toc_page'), $pageNumber);
return !empty($page['title']) ? $page['title'] : $this->lang->t('system', 'toc_page',
['%page%' => $pageNumber]);
}
/**
......
......@@ -14,7 +14,7 @@ class CheckAccess
*/
protected $acl;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -27,14 +27,14 @@ class CheckAccess
protected $view;
/**
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\View $view
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\View $view
*/
public function __construct(
Core\ACL $acl,
Core\Lang $lang,
Core\I18n\Translator $lang,
Core\Router $router,
Core\View $view
)
......
<?php
namespace ACP3\Core\Http\Request;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
use Symfony\Component\HttpFoundation\ServerBag;
/**
......@@ -70,7 +70,7 @@ class UserAgent
// Über die Sprachen iterieren und das passende Sprachpaket auswählen
foreach ($languages as $lang => $val) {
if (Lang::languagePackExists($lang) === true) {
if (Translator::languagePackExists($lang) === true) {
return $lang;
}
}
......
<?php
namespace ACP3\Core\Lang;
namespace ACP3\Core\I18n;
use ACP3\Core\Cache;
use ACP3\Core\Modules\Vendors;
/**
* Class Cache
* @package ACP3\Core\Lang
* @package ACP3\Core\I18n
*/
class Cache
class DictionaryCache
{
/**
* @var \ACP3\Core\Cache
* @var Cache
*/
protected $cache;
/**
......@@ -18,11 +20,13 @@ class Cache
protected $vendors;
/**
* DictionaryCache constructor.
*
* @param \ACP3\Core\Cache $cache
* @param \ACP3\Core\Modules\Vendors $vendors
*/
public function __construct(
\ACP3\Core\Cache $cache,
Cache $cache,
Vendors $vendors
)
{
......@@ -71,7 +75,7 @@ class Cache
// Iterate over all language keys
foreach ($xml->keys->item as $item) {
$data['keys'][strtolower($module)][(string)$item['key']] = trim((string)$item);
$data['keys'][strtolower($module . (string)$item['key'])] = trim((string)$item);
}
}
}
......
<?php
namespace ACP3\Core;
namespace ACP3\Core\I18n;
use ACP3\Core\Lang\Cache as LanguageCache;
use ACP3\Core\Config;
use ACP3\Core\I18n\DictionaryCache as LanguageCache;
use ACP3\Core\User;
/**
* Class Lang
* @package ACP3\Core
* Class Translator
* @package ACP3\Core\I18n
*/
class Lang
class Translator
{
/**
* @var \ACP3\Core\User
*/
protected $user;
/**
* @var \ACP3\Core\Lang\Cache
* @var \ACP3\Core\I18n\DictionaryCache
*/
protected $cache;
/**
......@@ -41,9 +43,9 @@ class Lang
protected $buffer = [];
/**
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang\Cache $cache
* @param \ACP3\Core\Config $config
* @param \ACP3\Core\User $user
* @param \ACP3\Core\I18n\DictionaryCache $cache
* @param \ACP3\Core\Config $config
*/
public function __construct(
User $user,
......@@ -126,16 +128,21 @@ class Lang
*
* @param string $module
* @param string $key
* @param array $arguments
*
* @return string
*/
public function t($module, $key)
public function t($module, $key, array $arguments = [])
{
if (isset($this->buffer[$this->getLanguage()]) === false) {
$this->buffer[$this->getLanguage()] = $this->cache->getLanguageCache($this->getLanguage());
}
return isset($this->buffer[$this->getLanguage()]['keys'][$module][$key]) ? $this->buffer[$this->getLanguage()]['keys'][$module][$key] : strtoupper('{' . $module . '_' . $key . '}');
if (isset($this->buffer[$this->getLanguage()]['keys'][$module . $key])) {
return strtr($this->buffer[$this->getLanguage()]['keys'][$module . $key], $arguments);
}
return strtoupper('{' . $module . '_' . $key . '}');
}
/**
......
......@@ -28,7 +28,7 @@ abstract class Controller implements ControllerInterface
*/
protected $container;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......
......@@ -4,7 +4,7 @@ namespace ACP3\Core\Modules\Controller;
use ACP3\Core\ACL;
use ACP3\Core\Config;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Modules;
use ACP3\Core\Router;
use ACP3\Core\User;
......@@ -31,7 +31,7 @@ class Context
*/
protected $user;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -65,7 +65,7 @@ class Context
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router $router
......@@ -77,7 +77,7 @@ class Context
EventDispatcherInterface $eventDispatcher,
ACL $acl,
User $user,
Lang $lang,
Translator $lang,
Modules $modules,
RequestInterface $request,
Router $router,
......@@ -123,7 +123,7 @@ class Context
}
/**
* @return \ACP3\Core\Lang
* @return \ACP3\Core\I18n\Translator
*/
public function getLang()
{
......
......@@ -11,7 +11,7 @@ use ACP3\Core\Modules\FrontendController;
class Action
{
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -36,7 +36,7 @@ class Action
protected $redirectMessages;
/**
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\View $view
......@@ -44,7 +44,7 @@ class Action
* @param \ACP3\Core\Helpers\RedirectMessages $redirectMessages
*/
public function __construct(
Core\Lang $lang,
Core\I18n\Translator $lang,
Core\Http\RequestInterface $request,
Core\Router $router,
Core\View $view,
......
......@@ -3,7 +3,7 @@ namespace ACP3\Core\Modules;
use ACP3\Core\Cache;
use ACP3\Core\Filesystem;
use ACP3\Core\Lang;
use ACP3\Core\I18n\Translator;
use ACP3\Core\XML;
use ACP3\Modules\ACP3\System\Model\ModuleRepository;
......@@ -18,7 +18,7 @@ class ModuleInfoCache
*/
protected $cache;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -36,14 +36,14 @@ class ModuleInfoCache
/**
* @param \ACP3\Core\Cache $cache
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Modules\Vendors $vendors
* @param \ACP3\Core\XML $xml
* @param \ACP3\Modules\ACP3\System\Model\ModuleRepository $systemModuleRepository
*/
public function __construct(
Cache $cache,
Lang $lang,
Translator $lang,
Vendors $vendors,
XML $xml,
ModuleRepository $systemModuleRepository
......
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Validation\Rules\Misc;
/**
......@@ -19,7 +20,7 @@ class Pagination
*/
protected $breadcrumb;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -78,7 +79,7 @@ class Pagination
/**
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Breadcrumb $breadcrumb
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\SEO $seo
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router $router
......@@ -87,7 +88,7 @@ class Pagination
public function __construct(
User $user,
Breadcrumb $breadcrumb,
Lang $lang,
Translator $lang,
SEO $seo,
RequestInterface $request,
Router $router,
......@@ -201,7 +202,7 @@ class Pagination
private function setMetaStatements($link)
{
if ($this->currentPage > 1) {
$postfix = sprintf($this->lang->t('system', 'page_x'), $this->currentPage);
$postfix = $this->lang->t('system', 'page_x', ['%page%' => $this->currentPage]);
$this->breadcrumb->setTitlePostfix($postfix);
}
......@@ -209,7 +210,7 @@ class Pagination
if ($this->request->getArea() !== 'admin') {
if ($this->currentPage - 1 > 0) {
// Seitenangabe in der Seitenbeschreibung ab Seite 2 angeben
$this->seo->setDescriptionPostfix(sprintf($this->lang->t('system', 'page_x'), $this->currentPage));
$this->seo->setDescriptionPostfix($this->lang->t('system', 'page_x', ['%page%' => $this->currentPage]));
$this->seo->setPreviousPage($link . 'page_' . ($this->currentPage - 1) . '/');
}
if ($this->currentPage + 1 <= $this->totalPages) {
......
......@@ -3,6 +3,7 @@ namespace ACP3\Core;
use ACP3\Core\Helpers\Forms;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Router\Aliases;
use ACP3\Modules\ACP3\Seo\Cache as SeoCache;
use ACP3\Modules\ACP3\Seo\Model\SeoRepository as seoRepository;
......@@ -18,7 +19,7 @@ class SEO
*/
protected $aliases;
/**
* @var \ACP3\Core\Lang
* @var \ACP3\Core\I18n\Translator
*/
protected $lang;
/**
......@@ -64,7 +65,7 @@ class SEO
protected $metaDescriptionPostfix = '';
/**
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\I18n\Translator $lang
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router\Aliases $aliases
* @param \ACP3\Core\Helpers\Forms $formsHelper
......@@ -73,7 +74,7 @@ class SEO
* @param \ACP3\Modules\ACP3\Seo\Model\SeoRepository $seoRepository
*/
public function __construct(
Lang $lang,
Translator $lang,
RequestInterface $request,
Aliases $aliases,
Forms $formsHelper,
......@@ -319,7 +320,7 @@ class SEO
}
$langRobots = [
sprintf($this->lang->t('seo', 'robots_use_system_default'), $this->getRobotsSetting()),
$this->lang->t('seo', 'robots_use_system_default', ['%default%' => $this->getRobotsSetting()]),
$this->lang->t('seo', 'robots_index_follow'),
$this->lang->t('seo', 'robots_index_nofollow'),
$this->lang->t('seo', 'robots_noindex_follow'),
......