I have a symfony 4.4 project with enabled translations and now I have to find a solution
that translations also take effect for swagger annotations. The result has to translate
the description attribute of these annotations.
Nelmio ApiDoc Bundle to v3.10.1
My annotation is:
* #Operation(
* tags={"02.02 X - Y"},
* summary="Set a ....",
* #SWG\Parameter(
* name="VideoBitRate",
* in="formData",
* description="encoding.vbitrate",
* required=false,
* type="string"
* ),
* ....
Translation is working for the whole project, only for the description of the defined
Swagger Parameters it does not work. The Nelmio docs are small and I cant find anything related.
My ideas are:
overwrite the docExtractor from Nelmio (no idea how - with the old version I could do this)
overwrite the AnnotatiosReader but I dont understand how exactly NelmioApiDocBundle generates the APIDocs with the new Version or with which AnnotationReader.
Related
I am developing a project in Symfony 4.3. I am trying to create URLs in different languages. I have tried to use this notation:
/**
* #Route({
* "it": "/{_locale}/rassegna/stampa",
* "bg": "/{_locale}/Статии/в/печата"
* }, name="rassegna_stampa", utf8=true)
*/
The problem is that when I try to create a link in a twig to change language, for example:
GO TO BG LANGUAGE
it is rendered in something like:
http://website.it/it/%D0%A1%D1%82%D0%B0%D1%82%D0%B8%D0%B8/%D0%B2/%D0%BF%D0%B5%D1%87%D0%B0%D1%82%D0%B0
So it seems that the translated final part is ok, but the _locale parameter is not matched, as the {_locale} placeholder is filled with the current locale, and not with the locale that I requested in the link. It is 'it' but it should be 'bg'.
I've a Symfony 4 app that is running fine until I want to define a route with the _locale parameter.
I define two routes for the same action with the following code :
/**
* #Route("/sites/{id}",
* name="site_get",
* methods={"GET"},
* requirements={"id": "\d+"},
* )
* #Route("/{_locale}/sites/{id}",
* name="site_get_with_locale",
* methods={"GET"},
* requirements={"id": "\d+"},
* )
*/
When I call the url /sites/1 I get the resource but if I call /en/sites/1 I get a 404 error "route not found".
Here are the things I've tried :
tried to change /{_locale}/sites/{id} with /{locale}/sites/{id} and the route is working but, obviously, the locale is not changed.
tried to set requirements for the _locale parameter but it is no better
tried to set the {_locale} parameter as a prefix (in annotations.yaml) with no luck neither
I can see the route definition in the debug:router :
site_get.0 GET ANY ANY /api/sites/{id}
site_get_with_locale.0 GET ANY ANY /api/{_locale}/sites/{id}
Edit 1 :
In the profiler for the given failed request /en/sites/1 :
the configuration sections shows me thet the Intl locale is fr.
In the routing section I don't see the same at in the debug:router command :
{_locale} is changed into 0 (even if I set requirement for the _locale to fr|en)
Edit 2 :
I was using Symfony 4.4.8 but downgrading to 4.4.7 seems to work.
I also have the problem with 4.4.10
Any idea of another path to explore?
Thank you,
Vincent
The Cookbook show how to translate assert messages, but how to do the same on #Constraint annotations on a class level? Example which is not working :
use Symfony\Bridge\Doctrine\Validator\Constraints as Constraint;
/**
* #Constraint\UniqueEntity(
* fields={"mobileDomainName"},
* errorPath="mobileDomainName",
* message="site.validation.mobileName.alreadyUsed"
* )
*/
class Site {
Thanks for your answers.
EDIT : translator is activated, all others classical calls worked (including Assert annotations).
In my case I have to enable translator in the config
translator: {
fallbacks: ['%locale%']
}
like Adam Elsodaney said.
Thanks to A.L comment, I read again the documentation (that I already tried to follow). But I misread the translation file name (i.e. validators.language.filetype), whereas I orignally dropped my translations in my custom validation file.
With all constraints validation in good file, all is working.
Thanks for your answers and pointing.
I've been working with Symfony2 recently, and I've been using annotations for routing, instead of the standard yml or PHP.
I've managed to get my head around most of it, but I'm having trouble using #Method to limit what type of http requests get a response from a controller.
I'm currently using:
/**
* #Route("/contact/", name="_contact")
* #Method({"GET", "POST"})
*/
and getting an error that states Cannot import resource "C:\wamp\www\jimmy\src\Scott\BlogBundle/Controller/" from "C:/wamp/www/jimmy/app/config\routing.yml".
If I remove the #Method line completely the page loads as normal. I've read the documentation on symfony about #Method and they do the same #Method line in their examples, so I'm really not sure where I have gone wrong.
My routing.yml in app/config is:
scott_blog:
resource: "#ScottBlogBundle/Controller/"
type: annotation
prefix: /
Thanks for any help.
You might have forgot to use the namespace Sensio\Bundle\FrameworkExtraBundle\Configuration\Method . If that is the case , add
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
I have installed FPNTagBundle via composer. I have successfully added tags to my articles, but when I add DoctrineExtensions' TagRepository as the repositoryClass with
/**
* #ORM\Entity(repositoryClass="DoctrineExtensions\Taggable\Entity\TagRepository")
* #ORM\Table
*/
class Tag extends FPN\TagBundle\Entity\Tag
and try to use TagRepository's method getResourceIdsForTag('post', 'tagname'), it fails. I've checked the repository class with
$tagRepo = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:Tag');
echo get_class($tagRepo);
and it's not TagRepository, but Doctrine\ORM\Entity\Repository. I don't have any other error message regarding the repositoryClass thing, even if I specify an invalid classname.
Have I found a bug, or do I miss something somewhere?
It seems I was hitting a bug. After merging some pull requests by Fabien Pennequin 16 days ago, it now seems working as expected.