-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command translations? #7
Comments
Hi, ANy hints on how I could resolve that issue? Thank you :) |
I guess I've found a part of a solution: diff -up vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Resources/config/services.yml.patch vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Resources/config/services.yml
--- vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Resources/config/services.yml.patch 2016-01-20 09:17:13.780380229 +0100
+++ vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Resources/config/services.yml 2016-01-20 09:18:34.319413250 +0100
@@ -12,3 +12,4 @@ services:
arguments: [%gettext.locale_shortcuts%,@router, %kernel.root_dir%]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
+ - { name: kernel.event_listener, event: console.command, method: onConsoleCommand }
diff -up vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Routing/GettextLocaleListener.php.patch vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Routing/GettextLocaleListener.php
--- vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Routing/GettextLocaleListener.php.patch 2016-01-20 09:17:40.197063060 +0100
+++ vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Routing/GettextLocaleListener.php 2016-01-20 09:53:39.274297866 +0100
@@ -5,6 +5,7 @@ use Symfony\Component\Routing\RouterInte
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Exception\InvalidParameterException;
+use Symfony\Component\Console\Event\ConsoleCommandEvent;
/**
* Gettext locale listener
@@ -61,6 +62,28 @@ class GettextLocaleListener
}
$this->setupGetText();
+ }
+
+ /**
+ * Binds the default domain to the combined translations on Kernel Request
+ *
+ * @param GetResponseEvent $event event
+ *
+ * @throws InvalidParameterException
+ */
+ public function onConsoleCommand(ConsoleCommandEvent $event)
+ {
+ $currentLocale = $this->getCurrentLocale();
+ //$requestedLocale = $this->getRequestedLocale(); //hardcoded for now since I do not know how to retrieve correct one :(
+ $requestedLocale = 'fr_FR';
+
+ if ($requestedLocale && $currentLocale != $requestedLocale) {
+ if (!setlocale(LC_MESSAGES, $requestedLocale.'.UTF-8', $requestedLocale.'.utf8', $requestedLocale.'.utf-8', $requestedLocale.'UTF8')) {
+ throw new InvalidParameterException("Requested locale '$requestedLocale' could not be set. Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.");
+ }
+ }
+
+ $this->setupGetText();
}
private function getCurrentLocale() With this patch, I'm able to get my french translations from a console command. But I've hardcoded the locale; I do not know how to retrieve it unfortunately... |
Seems like a good lead to allow translation easily. |
Well, there already is a parameter for the default locale; but I do not know how to get it from the Listener class... :) |
Any ideas to solve this issue? @trasher |
@wujku no sorry... I've used the "hardoced" solution I've found, but I'm no longer using the bundle for now. |
Hello,
I'm trying to get gettext translations from symfony commands (in twig templates that send mails, for instance). Mails are correctly translated when sent from the main app, but remains in english when sent from a console command.
Looking at this issue, i've found that we should use the following to get that working with symfony's translations:
What should I do with gettextbundle to get that work as expected?
Thank you :)
The text was updated successfully, but these errors were encountered: