Support translations for the UI, fixes #1

This commit is contained in:
Stéphane Goetz
2017-10-19 22:18:46 +02:00
parent ef36a953b4
commit a1a65bb9f0
10 changed files with 113 additions and 38 deletions

View File

@ -71,7 +71,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
}
} else {
$entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
$entry_page['__VIEW_DOCUMENTATION__'] = $params['base_page'] . $params['entry_page']->getUrl();
}
}
@ -103,7 +103,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
$context = ['page' => $page, 'params' => $params];
$template = new Template($params['templates'], $params['theme']['templates']);
$template = new Template($params);
return $template->render($this->isLanding() ? 'theme::home' : 'theme::content', $context);
}

View File

@ -9,12 +9,18 @@ class Template
{
protected $engine;
protected $params;
/**
* @param string $base
* @param string $theme
*/
public function __construct($base, $theme)
public function __construct($params)
{
$this->params = $params;
$base = $params['templates'];
$theme = $params['theme']['templates'];
// Use internal templates if no templates
// dir exists in the working directory
if (!is_dir($base)) {
@ -57,6 +63,20 @@ class Template
return $this->renderNavigation($nav);
});
$this->engine->registerFunction('translate', function ($key) {
$language = $this->params['language'];
if (array_key_exists($key, $this->params['strings'][$language])) {
return $this->params['strings'][$language][$key];
}
if (array_key_exists($key, $this->params['strings']['en'])) {
return $this->params['strings']['en'][$key];
}
return "Unknown key $key";
});
$this->engine->registerFunction('get_breadcrumb_title', function ($page, $base_page) {
$title = '';
$breadcrumb_trail = $page['breadcrumb_trail'];