leaseweb / lswgettexttranslationbundle Goto Github PK
View Code? Open in Web Editor NEWSymfony2 bundle that adds native (faster) gettext translation support and is easy to use.
License: MIT License
Symfony2 bundle that adds native (faster) gettext translation support and is easy to use.
License: MIT License
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:
$this->getContainer()->get('translator')->setLocale('fr');
What should I do with gettextbundle to get that work as expected?
Thank you :)
I'm stuck on that:
Notice: Use of undefined constant LC_MESSAGES - assumed 'LC_MESSAGES' in C:\xampp\htdocs\symfony2_8project\vendor\leaseweb\gettext-translation-bundle\Lsw\GettextTranslationBundle\Routing\GettextLocaleListener.php on line 56
Warning: setlocale(): Invalid locale category name LC_MESSAGES, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME in C:\xampp\htdocs\symfony2_8project\vendor\leaseweb\gettext-translation-bundle\Lsw\GettextTranslationBundle\Routing\GettextLocaleListener.php on line 56
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\InvalidParameterException' with message 'Requested locale 'en_US' could not be set.
Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.'
in C:\xampp\htdocs\symfony2_8project\vendor\leaseweb\gettext-translation-bundle\Lsw\GettextTranslationBundle\Routing\GettextLocaleListener.php:58
Stack trace:
#0 [internal function]: Lsw\GettextTranslationBundle\Routing\GettextLocaleListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#1 C:\xampp\htdocs\symfony2_8project\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php(181): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#2 C:\xampp\htdocs\symfony_projec in C:\xampp\htdocs\symfony2_8project\vendor\leaseweb\gettext-translation-bundle\Lsw\GettextTranslationBundle\Routing\GettextLocaleListener.php on line 58
I'm trying to use GettextBundle with my specific Twig error pages (404 mainly).
First of all, using the command "gettext:app:extract" will try to find strings to translate only in "app/Resources/views" directory; but to override Twig error pages, we have to use "app/Resources/TwigBundle/views/" directory.
I've solved that on my side changing a bit AbstractCommand.php:
diff -up vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Command/AbstractCommand.php.patch vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Command/AbstractCommand.php
--- vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Command/AbstractCommand.php.patch 2014-03-05 10:48:57.298092011 +0100
+++ vendor/leaseweb/gettext-translation-bundle/Lsw/GettextTranslationBundle/Command/AbstractCommand.php 2014-03-05 11:33:46.031956078 +0100
@@ -97,7 +97,12 @@ abstract class AbstractCommand extends C
mkdir($dir, 0755, true);
}
- $templates = $this->findFilesInFolder($dir . '/../views', 'twig');
+ $templates = array();
+ if ( $name === 'app' ) {
+ $templates = $this->findFilesInFolder($dir . '/../../', 'twig');
+ } else {
+ $templates = $this->findFilesInFolder($dir . '/../views', 'twig');
+ }
$php = "<?php\n";
$twig = $this->getContainer()->get('twig');
This way, I can successfully extract string from all overrided bundles views.
But that does not work as expected... No strings are translated; even those from the main template my 404 view inherits from.
Taking a look in the code, it appears that the problem in GettextLocaleListener.php, in the onKernelRequest method:
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
I do not understand what is that condition for, but if I remove those lines, my 404 page is translated.
Is it a bad idea to remove those lines?
And what about the trick to handle overrided templates?
Thank you.
Hey,
we just added your nifty bundle to a project, but we already have some custom gettext handler/listener. It'd be great if there'd be a config option to en/disable the bundle's services. For now I've just overriden yours with an empty dummy listener.
http://symfony.com/doc/current/cookbook/bundles/configuration.html
Cheers
Matthias
Hello,
I'm trying to use your bundle in my Symfony 2.3 application; string extraction is working fine on the PHP side using "_('My string to translate')" notation, all strings are properly extracted in the po files.
But I can't get Twig messages extracted at all :/ Using --keep-cache argument, the file MyBundle/Resources/gettext/twig.cache.php is created using the Symfony way ($this->env->getExtension('translator')->getTranslator()->trans("Clear", array(), "messages")).
So the question is, have I mised something, or is there any changes in recent Symfony releases that make gettext bundle unhappy?
Thank you :)
Hey,
the commands don't work anymore due to removal of the Dialog helper:
bin/console gettext:bundle:extract
[Symfony\Component\Console\Exception\InvalidArgumentException]
The helper "dialog" is not defined.
"The Dialog Helper was deprecated in Symfony 2.5 and removed in Symfony 3.0. You should now use the Question Helper instead, which is simpler to use."
Cheers
Matthias
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.