added chinese translations (#1310)
This commit is contained in:
@@ -11,20 +11,17 @@ namespace App\Configuration;
|
||||
|
||||
use App\Utils\MomentFormatConverter;
|
||||
|
||||
class LanguageFormattings
|
||||
final class LanguageFormattings
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
private $settings;
|
||||
/**
|
||||
* @var MomentFormatConverter
|
||||
*/
|
||||
protected $momentFormatter;
|
||||
private $momentFormatter;
|
||||
|
||||
/**
|
||||
* @param array $languageSettings
|
||||
*/
|
||||
public function __construct(array $languageSettings)
|
||||
{
|
||||
$this->settings = $languageSettings;
|
||||
@@ -145,7 +142,7 @@ class LanguageFormattings
|
||||
* @param string $locale
|
||||
* @return string
|
||||
*/
|
||||
protected function getConfig(string $key, string $locale): string
|
||||
private function getConfig(string $key, string $locale): string
|
||||
{
|
||||
if (!isset($this->settings[$locale])) {
|
||||
throw new \InvalidArgumentException(sprintf('Unknown locale given: %s', $locale));
|
||||
|
||||
@@ -38,4 +38,8 @@ class Constants
|
||||
* Homepage, used in multiple views
|
||||
*/
|
||||
public const HOMEPAGE = 'https://www.kimai.org';
|
||||
/**
|
||||
* Application wide default locale.
|
||||
*/
|
||||
public const DEFAULT_LOCALE = 'en';
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\DependencyInjection;
|
||||
|
||||
use App\Constants;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
@@ -52,7 +53,9 @@ class AppExtension extends Extension
|
||||
$container->setParameter('kimai.data_dir', $config['data_dir']);
|
||||
$container->setParameter('kimai.plugin_dir', $config['plugin_dir']);
|
||||
|
||||
$container->setParameter('kimai.languages', $config['languages']);
|
||||
$this->setLanguageFormats($config['languages'], $container);
|
||||
unset($config['languages']);
|
||||
|
||||
$container->setParameter('kimai.calendar', $config['calendar']);
|
||||
$container->setParameter('kimai.dashboard', $config['dashboard']);
|
||||
$container->setParameter('kimai.widgets', $config['widgets']);
|
||||
@@ -96,6 +99,29 @@ class AppExtension extends Extension
|
||||
$container->setParameter('kimai.config', $config);
|
||||
}
|
||||
|
||||
protected function setLanguageFormats(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$locales = explode('|', $container->getParameter('app_locales'));
|
||||
|
||||
// make sure all allowed locales are registered
|
||||
foreach ($locales as $locale) {
|
||||
if (!array_key_exists($locale, $config)) {
|
||||
$config[$locale] = $config[Constants::DEFAULT_LOCALE];
|
||||
}
|
||||
}
|
||||
|
||||
// make sure all keys are registered for every locale
|
||||
foreach ($config as $locale => $settings) {
|
||||
if ($locale === Constants::DEFAULT_LOCALE) {
|
||||
continue;
|
||||
}
|
||||
// pre-fill all formats with the default locale settings
|
||||
$config[$locale] = array_merge($config[Constants::DEFAULT_LOCALE], $config[$locale]);
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.languages', $config);
|
||||
}
|
||||
|
||||
protected function setLdapParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (!isset($config['connection']['baseDn'])) {
|
||||
|
||||
@@ -10,30 +10,26 @@
|
||||
namespace App\Utils;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Constants;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Use this class, when you want information about formats for the "current request locale".
|
||||
*/
|
||||
class LocaleSettings
|
||||
final class LocaleSettings
|
||||
{
|
||||
/**
|
||||
* @var LanguageFormattings
|
||||
*/
|
||||
protected $formats;
|
||||
|
||||
private $formats;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $locale = 'en';
|
||||
private $locale = Constants::DEFAULT_LOCALE;
|
||||
|
||||
/**
|
||||
* @param RequestStack $requestStack
|
||||
* @param LanguageFormattings $formats
|
||||
*/
|
||||
public function __construct(RequestStack $requestStack, LanguageFormattings $formats)
|
||||
{
|
||||
// It can be null in a console command
|
||||
// request is null in a console command
|
||||
if (null !== $requestStack->getMasterRequest()) {
|
||||
$this->locale = $requestStack->getMasterRequest()->getLocale();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user