symfony: Format date in assert message - symfony

I have assertion on my entity to validate dates. It's work well, but the outuput is formated whith time. I need only the date. (The text is in french)
My entity :
/**
* #var \DateTime
* #Assert\DateTime(format="d/m/Y")
* #Assert\LessThanOrEqual(
* value="-2 days",
* message="rapports.max_date"
* )
*/
protected $dateDebut;
My translation file :
max_date: 'La date saisie doit être inférieur ou égale au {{ compared_value }}.'
That output is "La date saisie doit être supérieur ou égale au 1 janv. 2015 à 01:00.". I want "La date saisie doit être supérieur ou égale au 01/001/2015."
I want to format the 'compared_value'. WHo can I do that ?

Maybe use the date_format filter:
max_date: 'La date saisie doit être inférieur ou égale au {{ compared_value | date_format('Y-m-d') }}.'

You can do the following:
Write a service and make it globally available to the twig engine.
This service has to define a public function that takes the compared_value, parses the wrongly formatted date, and outputs the correctly formatted one.
So:
class MyService
{
public function parse($compared_value) {
return date_format('Y-m-d', strtotime($compared_value));
}
}
in config.yml
twig:
globals:
my_service: '#my_service'
services:
my_service:
class: AppBundle\Service\MyService
and finally
max_date: 'La date saisie doit être inférieur ou égale au {{ my_service.parse(compared_value) }}.'

Related

Symfony4: validation contraints translation are not applied

Context
I am working on a Symfony 4 application, with an OroPlatform overlay.
I have followed this tutorial : https://symfony.com/doc/4.4/validation/translations.html
Here is my code :
<?php
/**
* #ORM\Entity(repositoryClass="Baltimore\Bundle\AppBundle\Repository\SubscriptionRepository")
* #ORM\Table(name="app_subscription")
*/
class Subscription
{
/**
* #ORM\Id()
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*
* #var int
*/
private $id;
/**
* #ORM\Column(type="integer")
* #Assert\NotBlank(message="author.name.not_blank")
* #Assert\Type(type="integer")
*
* #var int
*/
private $number;
}
As you can see, I have put this line to change to default NotBlank message #Assert\NotBlank(message="author.name.not_blank")
Issue
My current locale is fr_FR, I have check with the following code :
<?php
$locale = $request->getLocale();
Here is my translations/validators.fr_FR.xlf (path is relative to the project root directory) :
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="author.name.not_blank">
<source>author.name.not_blank</source>
<target>Veuillez entrer un nom d'auteur</target>
</trans-unit>
</body>
</file>
</xliff>
Cache is cleared symfony console cache:clear
But nothing change, the error message is author.name.not_blank instead of my translation.
The output of the command line php bin/console debug:translation fr BaltimoreAppBundle :
It seems to came from the fact that OroPlatform have his own command line to update translation.
Here is my working configuration :
# /translations/validators.fr_FR.yml
This value should not be blank.: Cette valeur ne doit pas être vide
Then, I run these commands : php bin/console clear:cache and php bin/console oro:translation:dump
Now I can see my updated translation.

set_locale in wordpress - woocommerce - stripe

Hello
my locale setting work everywhere except in stripe geteway plugin ( have asked stripe and woocommerce support : no solution )
detail of the probleme/bug here
https://github.com/woocommerce/woocommerce-gateway-stripe/issues/701
new info for this
testing this morning with the hook "wc_stripe_localized_messages"
add_filter("wc_stripe_localized_messages", function($arr_def){
$lang = WPTBASE::$theme_var["lang"];
WPTBASE::init_lang( $lang ); // this init lang and local
$wp_locale = get_locale(); // wp locale val
print "<pre>";
print "theme locale = " . WPTBASE::$theme_var["local"] . "\n";
print "wp locale = " . $wp_locale . "\n";
print $lang . "\n";
print $arr_def["invalid_number"];
print "\n";
print __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' );
print "</pre>";
return $arr_def;
});
this ouput at the top of the checkout page
https://www.support-rack.com/sr_2018/ca/eng/checkout/
this :
theme locale = en_CA
wp locale = en_CA
eng
Le numéro de la carte de paiement n’est pas un numéro de carte de paiement valide.
Le numéro de la carte de paiement n’est pas un numéro de carte de paiement valide.
the wordpress locale is en_CA
but the __() ouput is french ?
help !
Resolve !
Wordpress french locale file is 'fr_CA' / canada
the stripe french locale file is fr_FR / france
I'm using fr_CA .....
details / details / details
this was a friday exercice

Filter not working in the magnolia cms delivery endpoint

I am trying to use filter to query the delivery endpoint API as mentioned in the below doc
https://documentation.magnolia-cms.com/display/DOCS56/Delivery+endpoint+API#DeliveryendpointAPI-queryNodes-filterFilters
The filter is not working and I am getting the complete content of the page in the JSON response. I am getting all the nodes instead of the specified node
I even tried to use the #name property filter, still I get the entire content instead of that particular node
curl -X GET "http://localhost:8080/magnoliaAuthor/.rest/delivery/website/v1/travel/hello?#name=03
my rest endpoint yaml configuration is as follows
class: info.magnolia.rest.delivery.jcr.v1.JcrDeliveryEndpointDefinition
params:
website:
depth: 2
nodeTypes:
- mgnl:page
- mgnl:area
- mgnl:component
childNodeTypes:
- mgnl:area
- mgnl:component
rootPath: /
workspace: website
includeSystemProperties: false
I did the test in the demo (https://demoauthor.magnolia-cms.com) and it works.
I created this file:
class: info.magnolia.rest.delivery.jcr.v1.JcrDeliveryEndpointDefinition
params:
website:
depth: 2
nodeTypes:
- mgnl:page
- mgnl:area
- mgnl:component
childNodeTypes:
- mgnl:area
- mgnl:component
rootPath: /
workspace: website
includeSystemProperties: false
Into this path: /travel-demo/restEndpoints/restTest.yaml (in the Resources App)
Then I queried the first component from the main area of the About page at:
https://demoauthor.magnolia-cms.com/.rest/delivery/website/v1/travel/about/main/00
With this result:
{"#name":"00","#path":"/travel/about/main/00","#id":"01db6fc1-78af-4284-adf0-8c997309df6a","#nodeType":"mgnl:component","text":"<p>We are a full service, independent travel agency.</p>\n<p>We offer unique tours from every continent on the planet. Get inspired and book your tour with us for an experience you’ll always remember.</p> ","text_de":"<p>Wir sind eine unabhängige Reiseagentur mit Rundumservice.</p>\n<p>Wir bieten einzigartige Reisen für jeden Kontinent der Erde an. Lassen Sie sich inspirieren und buchen Sie Ihre Reise bei uns, um Erfahrungen zu machen, die Ihnen für immer in Erinnerung bleiben werden.</p> ","jcr:createdBy":"admin","headline_de":"Über Magnolia Travels","mgnl:lastActivatedBy":"superuser","mgnl:template":"travel-demo:components/jumbotron","mgnl:lastActivated":"2015-10-27T13:50:52.396+0100","jcr:created":"2018-01-23T22:33:44.55+0100","mgnl:created":"2015-02-02T20:23:37.199+0100","imagePosition":"below","headlineLevel":"small","mgnl:createdBy":"superuser","headline":"About Magnolia Travels","mgnl:lastModified":"2015-06-18T11:08:06.983+0200","mgnl:activationStatus":"true","mgnl:lastModifiedBy":"superuser","#nodes":[]}
And then I queried the entire page at:
https://demoauthor.magnolia-cms.com/.rest/delivery/website/v1/travel/about/
With this result:
{"#name":"about","#path":"/travel/about","#id":"808ebe4c-72b2-49f1-b9f7-e7db22bce02f","#nodeType":"mgnl:page","jcr:createdBy":"admin","hideInNav":"false","mgnl:template":"travel-demo:pages/standard","mgnl:lastActivatedBy":"superuser","mgnl:lastActivated":"2018-01-23T22:33:55.104+0100","jcr:created":"2018-01-23T22:33:44.53+0100","mgnl:created":"2015-02-02T17:34:28.816+0100","mgnl:createdBy":"superuser","title":"About","title_de":"Über uns","mgnl:lastModified":"2015-10-27T13:50:28.322+0100","mgnl:activationStatus":"true","mgnl:lastModifiedBy":"superuser","main":{"#name":"main","#path":"/travel/about/main","#id":"f3b2681f-e747-4ff6-bcbb-2a9a9f01553e","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-10-27T13:50:28.322+0100","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","jcr:created":"2018-01-23T22:33:44.54+0100","mgnl:lastActivated":"2015-10-27T13:50:52.396+0100","mgnl:lastModifiedBy":"superuser","mgnl:created":"2015-02-02T17:34:34.651+0100","00":{"#name":"00","#path":"/travel/about/main/00","#id":"01db6fc1-78af-4284-adf0-8c997309df6a","#nodeType":"mgnl:component","text":"<p>We are a full service, independent travel agency.</p>\n<p>We offer unique tours from every continent on the planet. Get inspired and book your tour with us for an experience you’ll always remember.</p> ","text_de":"<p>Wir sind eine unabhängige Reiseagentur mit Rundumservice.</p>\n<p>Wir bieten einzigartige Reisen für jeden Kontinent der Erde an. Lassen Sie sich inspirieren und buchen Sie Ihre Reise bei uns, um Erfahrungen zu machen, die Ihnen für immer in Erinnerung bleiben werden.</p> ","jcr:createdBy":"admin","headline_de":"Über Magnolia Travels","mgnl:lastActivatedBy":"superuser","mgnl:template":"travel-demo:components/jumbotron","mgnl:lastActivated":"2015-10-27T13:50:52.396+0100","jcr:created":"2018-01-23T22:33:44.55+0100","mgnl:created":"2015-02-02T20:23:37.199+0100","imagePosition":"below","headlineLevel":"small","mgnl:createdBy":"superuser","headline":"About Magnolia Travels","mgnl:lastModified":"2015-06-18T11:08:06.983+0200","mgnl:activationStatus":"true","mgnl:lastModifiedBy":"superuser","#nodes":[]},"04":{"#name":"04","#path":"/travel/about/main/04","#id":"834ef0b0-1519-4834-b1f5-4166ae004ac0","#nodeType":"mgnl:component","jcr:createdBy":"admin","layout":"8x4","mgnl:lastActivatedBy":"superuser","mgnl:template":"travel-demo:components/columnLayout","mgnl:lastActivated":"2015-10-27T13:50:52.397+0100","jcr:created":"2018-01-23T22:33:44.56+0100","mgnl:created":"2015-10-27T12:03:30.193+0100","mgnl:createdBy":"superuser","mgnl:lastModified":"2015-10-27T13:50:28.322+0100","mgnl:activationStatus":"true","mgnl:lastModifiedBy":"superuser","#nodes":[]},"#nodes":["00","04"]},"footer":{"#name":"footer","#path":"/travel/about/footer","#id":"21da1190-52e6-45d5-8e68-5a2878733d6c","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-06-18T17:43:12.575+0200","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","mgnl:lastActivated":"2015-10-27T13:50:52.400+0100","jcr:created":"2018-01-23T22:33:44.63+0100","mgnl:created":"2015-02-02T17:34:34.666+0100","mgnl:lastModifiedBy":"superuser","footer1":{"#name":"footer1","#path":"/travel/about/footer/footer1","#id":"7b1bb2e5-4a96-46ba-9e37-213d49bd874f","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-02-26T16:27:05.82+0100","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","jcr:created":"2018-01-23T22:33:44.64+0100","mgnl:lastActivated":"2015-10-27T13:50:52.400+0100","mgnl:lastModifiedBy":"superuser","mgnl:created":"2015-02-26T16:27:05.82+0100","#nodes":[]},"footer2":{"#name":"footer2","#path":"/travel/about/footer/footer2","#id":"847f6b8c-a997-4c1a-ad7f-00c777351f32","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-02-26T16:27:05.109+0100","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","mgnl:lastActivated":"2015-10-27T13:50:52.400+0100","jcr:created":"2018-01-23T22:33:44.65+0100","mgnl:created":"2015-02-26T16:27:05.109+0100","mgnl:lastModifiedBy":"superuser","#nodes":[]},"footer3":{"#name":"footer3","#path":"/travel/about/footer/footer3","#id":"8d80386e-d6b7-489b-881a-b50a391fc08e","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-02-26T16:27:05.138+0100","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","jcr:created":"2018-01-23T22:33:44.66+0100","mgnl:lastActivated":"2015-10-27T13:50:52.400+0100","mgnl:created":"2015-02-26T16:27:05.138+0100","mgnl:lastModifiedBy":"superuser","#nodes":[]},"footer4":{"#name":"footer4","#path":"/travel/about/footer/footer4","#id":"83939ec7-c633-4bc0-a2f0-e874ac64b327","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-02-26T16:27:05.155+0100","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","mgnl:lastActivated":"2015-10-27T13:50:52.401+0100","jcr:created":"2018-01-23T22:33:44.66+0100","mgnl:created":"2015-02-26T16:27:05.155+0100","mgnl:lastModifiedBy":"superuser","#nodes":[]},"lastLinks":{"#name":"lastLinks","#path":"/travel/about/footer/lastLinks","#id":"5a9f3338-a98d-4797-b35e-0d9f10550a1e","#nodeType":"mgnl:area","mgnl:createdBy":"superuser","jcr:createdBy":"admin","mgnl:lastModified":"2015-06-18T17:43:12.583+0200","mgnl:activationStatus":"true","mgnl:lastActivatedBy":"superuser","mgnl:lastActivated":"2015-10-27T13:50:52.401+0100","jcr:created":"2018-01-23T22:33:44.67+0100","mgnl:created":"2015-06-18T17:43:12.583+0200","mgnl:lastModifiedBy":"superuser","#nodes":[]},"#nodes":["footer1","footer2","footer3","footer4","lastLinks"]},"#nodes":["main","footer"]}
So in my opinion everything is OK.
I would check the path you are requesting. It's probably wrong.
Using the JCR browser helps on this.
Greetings

GenemuFormBundle not translating "The captcha is not valid" To locale language (fr)?

All in the title, and in the validators.fr.yml all is good, this is it:
The captcha is invalid.: Le captcha est invalide.
genemu_form:
recaptcha:
incorrect-captcha-sol: Le captcha n'est pas valide.
invalid-site-private-key: La clé privée est invalide.

Garbled utf-8 QString when reading network reply

I am building a BlackBerry 10 application and I am using the QT libraries. However I got some character encoding issues and I was wondering if you might have a clue as how to solve this.
I have the following data that gets send to me via a web service.
{"title":"Seconde Guerre mondiale - Wikipédia","content":"Théâtre européen L’Europe au 1er septembre 1939 Après s’être assuré de ne pas risquer une guerre avec l’URSS en signant le Pacte germano-soviétique, Hitler lance ses armées sur la Pologne, l...","favicon":"http://fr.m.wikipedia.org//bits.wikimedia.org/favicon/wikipedia.ico"}
If I wireshark it, the raw data is:
[truncated] {"title":"Seconde Guerre mondiale - Wikip\303\251dia","content":"Th\303\251\303\242tre
However when I parse this using the following code:
void WebpageFetcher::onPageRequestFinished(QNetworkReply* networkReply)
{
qDebug() << "WebpageFetcher:: onPageRequestFinished";
QByteArray content = networkReply->readAll();
qDebug() << QString::fromUtf8(content.data(), content.size());
}
I get this result:
"{"title":"Seconde Guerre mondiale - Wikipédia","content":"Théâtre européen L’Europe au 1er septembre 1939 Après s’être assuré de ne pas risquer une guerre avec l’URSS en signant le Pacte germano-soviétique, Hitler lance ses armées sur la Pologne, l...","favicon":"http://fr.m.wikipedia.org//bits.wikimedia.org/favicon/wikipedia.ico"}"
Not exactly what I am looking for. Does anyone have a clue? My browsers seem to be able to interpret the characters in this JSON reply perfectly.

Resources