From c6e99b35d52e55a5bf2545579334edc600824162 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Fri, 10 Aug 2018 00:11:48 +0200 Subject: [PATCH] moved twig globals to dynamic compiler pass (#264) --- UPGRADING.md | 26 +++++++++++ config/packages/kimai.yaml | 12 +++--- src/DependencyInjection/AppExtension.php | 3 ++ .../Compiler/TwigContextCompilerPass.php | 33 ++++++++++++++ src/DependencyInjection/Configuration.php | 11 +++++ src/Kernel.php | 2 + var/docs/README.md | 1 + var/docs/developers.md | 15 +------ var/docs/internal.md | 2 +- var/docs/translations.md | 43 +++++++++++++++++++ 10 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 src/DependencyInjection/Compiler/TwigContextCompilerPass.php create mode 100644 var/docs/translations.md diff --git a/UPGRADING.md b/UPGRADING.md index 05d05b5c..4b49168e 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -5,6 +5,32 @@ Database upgrades are currently ONLY provided for MySQL/MariaDB and SQLite. If you plan on using e.g. PostgreSQL, please read more about the `bin/console doctrine:migrations:diff` and `bin/console doctrine:migrations:migrate` commands and contact us, so we can integrate them into the official releases. +## 0.4 (not yet released) + +In the time between 0.3 and 0.4 there was a release of composer that introduced a BC break, +which leads to problems between Composer and Symfony Flex, resulting in an error like this when running it: + +``` + [ErrorException] + Declaration of Symfony\Flex\ParallelDownloader::getRemoteContents($originUrl, $fileUrl, $context) should be compatible with Composer\Util\RemoteFilesystem::getRemoteContents($originUrl, $fileUrl, $context, ?array &$responseHeaders = NULL) +``` + +This can be fixed by updating composer before the Kimai update and running composer without the flex plugin: +``` +composer self-update +sudo -u www-data composer install --no-plugins +``` + +So the full update goes like that: + +```bash +git pull origin master +sudo -u www-data composer install --no-dev --optimize-autoloader --no-plugins +sudo -u www-data bin/console cache:clear --env=prod +sudo -u www-data bin/console cache:warmup --env=prod +bin/console doctrine:migrations:migrate +``` + ## [0.3](https://github.com/kevinpapst/kimai2/releases/tag/0.3) (2018-07-22) **Update from 0.2:** diff --git a/config/packages/kimai.yaml b/config/packages/kimai.yaml index 402e1d48..9ec6dfab 100644 --- a/config/packages/kimai.yaml +++ b/config/packages/kimai.yaml @@ -68,8 +68,10 @@ kimai: # id: 'de.german#holiday@group.v.calendar.google.com' # color: '#ccc' -twig: - globals: - kimai_context: - box_color: "green" # a color for: TODO ??? find out ??? - active_warning: 3 # display a warning color if the user has at least X active recordings + # theme related settings, will be available as twig settings + theme: + # display a warning color if the user has at least X active recordings + active_warning: 3 + # fallback color for all widgets that don't have a dedicated color + # possible options: blue, black, purple, yellow, red, green + box_color: 'green' diff --git a/src/DependencyInjection/AppExtension.php b/src/DependencyInjection/AppExtension.php index 7e6fd86a..a3090e30 100644 --- a/src/DependencyInjection/AppExtension.php +++ b/src/DependencyInjection/AppExtension.php @@ -36,6 +36,7 @@ class AppExtension extends Extension implements PrependExtensionInterface $container->setParameter('kimai.languages', $config['languages']); $container->setParameter('kimai.calendar', $config['calendar']); + $container->setParameter('kimai.theme', $config['theme']); $this->createUserParameter($config, $container); $this->createTimesheetParameter($config, $container); @@ -98,6 +99,7 @@ class AppExtension extends Extension implements PrependExtensionInterface */ public function prepend(ContainerBuilder $container) { + /* $configuration = new Configuration(); $configs = $container->getExtensionConfig($this->getAlias()); try { @@ -115,6 +117,7 @@ class AppExtension extends Extension implements PrependExtensionInterface ], ] ); + */ } /** diff --git a/src/DependencyInjection/Compiler/TwigContextCompilerPass.php b/src/DependencyInjection/Compiler/TwigContextCompilerPass.php new file mode 100644 index 00000000..e70b1a80 --- /dev/null +++ b/src/DependencyInjection/Compiler/TwigContextCompilerPass.php @@ -0,0 +1,33 @@ +getDefinition('twig'); + $theme = $container->getParameter('kimai.theme'); + $durationOnly = $container->getParameter('kimai.timesheet.duration_only'); + + $twig->addMethodCall('addGlobal', ['kimai_context', $theme]); + $twig->addMethodCall('addGlobal', ['duration_only', $durationOnly]); + } +} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f81f4d4d..53472cdb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -29,6 +29,17 @@ class Configuration implements ConfigurationInterface $rootNode ->children() + ->arrayNode('theme') + ->addDefaultsIfNotSet() + ->children() + ->integerNode('active_warning') + ->defaultValue(3) + ->end() + ->scalarNode('box_color') + ->defaultValue('green') + ->end() + ->end() + ->end() ->arrayNode('user') ->addDefaultsIfNotSet() ->children() diff --git a/src/Kernel.php b/src/Kernel.php index 2892a2ed..debdd06e 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -11,6 +11,7 @@ namespace App; use App\DependencyInjection\AppExtension; use App\DependencyInjection\Compiler\DoctrineCompilerPass; +use App\DependencyInjection\Compiler\TwigContextCompilerPass; use App\Timesheet\CalculatorInterface; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; @@ -66,6 +67,7 @@ class Kernel extends BaseKernel $loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob'); $container->addCompilerPass(new DoctrineCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000); + $container->addCompilerPass(new TwigContextCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000); } protected function configureRoutes(RouteCollectionBuilder $routes) diff --git a/var/docs/README.md b/var/docs/README.md index 880adf5a..27ba7041 100644 --- a/var/docs/README.md +++ b/var/docs/README.md @@ -21,6 +21,7 @@ For the most part Kimai usage should be self-explanatory, so we will only cover - [FAQ](faq.md) - some answers to frequently asked questions - [Emails](emails.md) - transport configuration and handling of emails - [API](developers_api.md) - how to use the JSON API +- [Translations](translations.md) - all about languages and translations ## Installation diff --git a/var/docs/developers.md b/var/docs/developers.md index 3d178c38..4749289a 100644 --- a/var/docs/developers.md +++ b/var/docs/developers.md @@ -79,22 +79,9 @@ Be aware that this command will modify all files with violations in the director Our code-styles are configured in [.php_cs.dist](../../.php_cs.dist). - ## Translations -We try to keep the number of language files small, in order to make it easier to identify the location of application messages and to unify the codebase. - -- If you add a new key, you have to add it in every language file -- Its very likely that you want to edit the file `messages` as it holds 90% of our application translations - -The files in `translations/` as a quick overview: - -- `exceptions` only holds translations of error pages and exception handlers -- `flashmessages` hold all success and error messages, that will be shown as results from action calls after page reload -- `messages` holds most of the visible application translations (like all the static UI elements and form translations) -- `pagerfanta` includes the translations for the pagination component -- `sidebar` holds all the translations of the right sidebar -- `validators` only hold translations related to violations/validation of submitted form data (or API calls) +Read more about [languages and translations](translations.md). ## Extending the navigation bar diff --git a/var/docs/internal.md b/var/docs/internal.md index a5d8975b..007d2072 100644 --- a/var/docs/internal.md +++ b/var/docs/internal.md @@ -10,4 +10,4 @@ Internal documentation for project maintainers - Push a release branch and add it as last PR merge into master - Edit the release-draft and add the "Full changelog" link + everything from the "Merged pull requests" section from CHANGELOG.md - Create the release -- Post a new issue at [YunoHost tracker for Kimai 2](https://github.com/YunoHost-Apps/kimai2_ynh) \ No newline at end of file +- Post a new issue at [YunoHost tracker for Kimai 2](https://github.com/YunoHost-Apps/kimai2_ynh) diff --git a/var/docs/translations.md b/var/docs/translations.md new file mode 100644 index 00000000..4d107322 --- /dev/null +++ b/var/docs/translations.md @@ -0,0 +1,43 @@ +# Translations + +We try to keep the number of language files small, in order to make it easier to identify the location of application messages and to unify the codebase. + +- If you add a new key, you have to add it in every language file +- Its very likely that you want to edit the file `messages` as it holds 90% of our application translations + +The files in `translations/` as a quick overview: + +- `exceptions` only holds translations of error pages and exception handlers +- `flashmessages` hold all success and error messages, that will be shown as results from action calls after page reload +- `messages` holds most of the visible application translations (like all the static UI elements and form translations) +- `pagerfanta` includes the translations for the pagination component +- `sidebar` holds all the translations of the right sidebar +- `validators` only hold translations related to violations/validation of submitted form data (or API calls) + +## Add a new language + +As example I choose a new hypothetical language with the locale `xx`. + +Copy each translation file from `translations/*.en.xliff` and rename them to `translations/*.xx.xliff`. + +Adjust the `target-language` in the file header, as example for the new file `exceptions.xx.xliff`: +```yml +` +``` + +Adjust the file `config/kimai.yaml` and add the language settings below the key `kimai.languages`: +```yaml +kimai: + languages: + xx: + date_short: 'd.m.Y' +``` + +Append the new locale in the file `config/services.yaml` at `parameters.app_locales` divided by a pipe: + +```yaml +parameters: + locale: en + app_locales: en|de|ru|it|xx +``` + \ No newline at end of file