prezent / doctrine-translatable-bundle Goto Github PK
View Code? Open in Web Editor NEWIntegrate the doctrine-translatable extension in Symfony2
License: MIT License
Integrate the doctrine-translatable extension in Symfony2
License: MIT License
I can't seem to get the locale in the entity.
Whenever I manually fill the currentLocale, it works like a charm...
In the 1.0.6
patch version, after #24 has been closed, you have introduced a BC break (80afed0). The change is not compatible with the older versions of Symfony as there was no constructor nor getRootNode()
method in TreeBuilder
until 4.2
release ๐
The change has broken our framework (we are using caret constraints in our composer.json
), see https://travis-ci.org/shopsys/shopsys/jobs/541357267
When i add bundle to registerBundles() method, i can not generate any entities from yaml mapping by generator, i get this error:
Cannot adapt Doctrine driver of class Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver
Hi,
Thanks for your job.
I have a bug during installation:
PHP Fatal error: Class 'Prezent\Doctrine\Translatable\Mapping\Driver\YamlDriver' not found in /Users/comur/Documents/workspace/wid.localhost.net/app/cache/dev/appDevDebugProjectContainer.php on line 517
As i can see, you put "prezent/doctrine-translatable": ">=0.1,<0.2-dev",
in the bundle's requirement but 0.1 doesn't have this YamlDriver class yet so this causes a bug in service container when initializing it.
I suggest to put dev-master as prezent/doctrine-translatable requirement or create a new version of prezent/doctrine-translatable.
Thanks for your help.
Hello!
Could you please add support for prezent/doctrine-translatable
^3.0 in a new version / tag?
I query entities like in the following controller action:
/**
* @param int $id
* @param EntityManagerInterface $entityManager
* @param SerializerInterface $serializer
* @return JsonResponse
* @Route("/project/{id}", name="project_show")
*/
public function projectShow(int $id, EntityManagerInterface $entityManager, SerializerInterface $serializer) {
$project = $entityManager->getRepository('App:Project')->findOneBy([
'id' => $id
]);
return new JsonResponse($serializer->serialize($project, 'json'));
}
This returns an object of type Project
with a property of translations
with a value of null
.
The command php bin/console debug:event-dispatcher
shows that the LocaleListener
is active, but shows no trace of the TranslatableListener
.
The profiler's "Events" section reflects and confirm those findings.
The command php bin/console debug:container
shows the following:
Name | Service |
---|---|
prezent_doctrine_translatable.driver_chain | Metadata\Driver\DriverChain |
prezent_doctrine_translatable.listener | Prezent\Doctrine\Translatable\EventListener\TranslatableListener |
prezent_doctrine_translatable.listener.locale | Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener |
prezent_doctrine_translatable.metadata_factory | Metadata\MetadataFactory |
services.yaml
app/cache/[env]/ProjectContainer
as you mentioned in #3 and #13 . The cache layout may have changed with Symfony 4, but both listener class names can be found using a recursive search in the cache directory.stof/doctrine-extensions-bundle
and hence the gedmo/doctrine-extensions
for TimeStampable
and Softdeleteable
behaviour. Could there be any clash?Kernel.php
file upon installation via composer. I added it manually.Module | Version |
---|---|
Symfony | 4.1.0 |
php | 7.2.6 |
prezent/doctrine-translatable | 1.2.1 |
prezent/doctrine-translatable-bundle | 1.0.5 |
What can I do? Thanks in advance for you help.
There is an undefined variable $container
in PrezentDoctrineTranslatableExtension::loadSonata()
which triggers an error when the bundle is registered: https://github.com/Prezent/doctrine-translatable-bundle/blob/1.0.4/DependencyInjection/PrezentDoctrineTranslatableExtension.php#L45
In PrezentDoctrineTranslatableExtension.php line 45:
[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined variable: container
Fixed in #21, I'm creating this issue just for transparency - so it's clear what is happening.
I may be having a similar issue to what was mentioned here: #3
Basically, currentLocale is not being automatically set from the Request for me.
I need to manually set it in my Controller for things to work:
$locale = $this->get('request')->getLocale();
$product = new Product();
$product->setCurrentLocale($locale);
If don't set it manually, I get the exception: 'No locale has been set and currentLocale is empty'
I noticed in previous issue #3 that you mentioned that both Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener
and Prezent\Doctrine\Translatable\EventListener\TranslatableListener
should appear in app/cache/[env]/ProjectContainer.
In my app/cache/dev/appDevDebugProjectContainer.php I see this:
/**
* Gets the 'prezent_doctrine_translatable.listener' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Prezent\Doctrine\Translatable\EventListener\TranslatableListener A Prezent\Doctrine\Translatable\EventListener\TranslatableListener instance.
*/
protected function getPrezentDoctrineTranslatable_ListenerService()
{
$this->services['prezent_doctrine_translatable.listener'] = $instance = new \Prezent\Doctrine\Translatable\EventListener\TranslatableListener($this->get('prezent_doctrine_translatable.metadata_factory'));
$instance->setCurrentLocale('en');
$instance->setFallbackLocale('en');
return $instance;
}
/**
* Gets the 'prezent_doctrine_translatable.listener.locale' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener A Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener instance.
*/
protected function getPrezentDoctrineTranslatable_Listener_LocaleService()
{
return $this->services['prezent_doctrine_translatable.listener.locale'] = new \Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener($this->get('prezent_doctrine_translatable.listener'));
}
Below is my code for the translatable and translation entities which I am using to test this bundle. Please let me know if there is anything I might be doing wrong, or if more information is needed.
Translatable entity Product.php:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Prezent\Doctrine\Translatable\Annotation as Prezent;
use Prezent\Doctrine\Translatable\Entity\AbstractTranslatable;
use AppBundle\Entity\ProductTranslation;
/**
* @ORM\Entity
*/
class Product extends AbstractTranslatable
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Prezent\Translations(targetEntity="AppBundle\Entity\ProductTranslation")
*/
protected $translations;
/**
* @Prezent\CurrentLocale
*/
private $currentLocale;
private $currentTranslation;
public function __construct()
{
$this->translations = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function setCurrentLocale($locale)
{
$this->currentLocale = $locale;
return $this;
}
public function getCurrentLocale()
{
return $this->currentLocale;
}
/**
* Translation helper method
*/
public function translate($locale = null)
{
if (null === $locale) {
$locale = $this->currentLocale;
}
if (!$locale) {
throw new \RuntimeException('No locale has been set and currentLocale is empty');
}
if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) {
return $this->currentTranslation;
}
if (!$translation = $this->translations->get($locale)) {
$translation = new ProductTranslation();
$translation->setLocale($locale);
$this->addTranslation($translation);
}
$this->currentTranslation = $translation;
return $translation;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->translate()->setName($name);
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->translate()->getName();
}
/**
* Set color
*
* @param string $color
*/
public function setColor($color)
{
$this->translate()->setColor($color);
}
/**
* Get color
*
* @return string
*/
public function getColor()
{
return $this->translate()->getColor();
}
}
Translation entity ProductTranslation.php:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Prezent\Doctrine\Translatable\Annotation as Prezent;
use Prezent\Doctrine\Translatable\Entity\AbstractTranslation;
/**
* @ORM\Entity
*/
class ProductTranslation extends AbstractTranslation
{
/**
* @Prezent\Translatable(targetEntity="AppBundle\Entity\Product")
*/
protected $translatable;
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
/**
* @ORM\Column(type="string", length=100)
*/
private $color;
/**
* Set name
*
* @param string $name
* @return ProductTranslation
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set color
*
* @param string $color
* @return ProductTranslation
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* Get color
*
* @return string
*/
public function getColor()
{
return $this->color;
}
}
Hi,
Is it possible to dynamically (manually) set the currentLocale in code withoug calling a setCurrentLocale
in the entity manually?
In this case; i want to serialize an entity to a json file; and foreach json file I want another language to be active in the serialize process.
The currentLocale is being set by the TranslateListener on request; but can I change the currentLocale in code too?
Hi,
Please, help the noob to use your package.
I think I did everything according to the manual. The only problem for me is the listener. Where I can find more information about how to make it?
This PR broke our 3.4 LTS app with the error
FatalThrowableError
Type error: Argument 1 passed to Prezent\Doctrine\TranslatableBundle\EventListener\LocaleListener::onKernelRequest() must be an instance of Symfony\Component\HttpKernel\RequestEvent, instance of Symfony\Component\HttpKernel\Event\GetResponseEvent given, called in ... Symfony/Component/EventDispatcher/Debug/WrappedListener.php on line 115
A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.
It happens here:
DependencyInjection/Configuration.php
Looks like there is an upstream function signature change in Sonata that is now bring the installation of this bundle related to using Symfony 4 and Sonata 4.x branches.
Looks like this bundle depends on Sonata in the Filter/TranslatableFilter.php
Will you be branching?
It's currently no possible to install "prezent/doctrine-translatable-bundle 1.0.*@dev" with "minimum-stability": "stable".
It's because there is a requirement on "prezent/doctrine-translatable >=1.0" which doesn't exists as stable. Only 1.0-dev is available on packagist.
Composer error:
- Installation request for prezent/doctrine-translatable-bundle 1.0.*@dev -> satisfiable by prezent/doctrine-translatable-bundle[1.0.x-dev].
- prezent/doctrine-translatable-bundle 1.0.x-dev requires prezent/doctrine-translatable >=1.0,<2.0-dev -> no matching package found.
Should prezent release a stable version of prezent/doctrine-translatable ? Or should we not use doctrine-translatable-bundle 1.0.* ?
Since this afternoon update, and the update of composer.json : 0189bdf, the version 0.3.* has been deleted since it was not on the tags of the repository.
You can check on packagist: https://packagist.org/packages/prezent/doctrine-translatable-bundle
Could this being fixed ? At least, for not breaking projects which were requiring it.
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.