Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[TwigBundle] make date formats and number formats configurable#13554
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
stof commentedJan 30, 2015
this implementation is wrong. the Twig_Environment should not be configured through the TwigEngine, as this means that the |
xabbuh commentedJan 30, 2015
I see your point, but do we have a better place where we can call methods of the Twig extensions? |
stof commentedJan 30, 2015
@xabbuh Well, there is 2 solutions here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should be an integer node
xabbuh commentedJan 30, 2015
@stof Thanks for pointing me towards service configurators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Interestingly, we cannot make the service private because it then gets inlined and the XML dumper fails here:https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php#L182
The error message then is:
ContextErrorException: Warning: DOMElement::setAttribute() expects parameter 2 to be string, object given in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php line 182There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Casting the second argument to a string should fix the issue properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
no it won't. The issue is that the XML format cannot accept inline services for the configurator, and so cannot handle the case of private configurator service definitions getting inlined in place where they are used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Imho the same would be true for other formats as well since the definition does not contain the service id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@xabbuh the PHP dumper already supports this case. And the YamlDumper is irrelevant, because it is already unusable on a compiled container (the YAML config format does not support inline service definitions in arguments for instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please have a look at#13557 for a proposal about making it possible to use inlined configurator services in the XML format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Given that factories and configurators can now be inlined, this is not an issue anymore and I made the service private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I guess you need to update the depdency to require the DependencyInjection component version where this has been fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure if we really need to do this. It would mean to add a conflict rule to the Composer config. The issue has been solved in the latest patch version of all maintained Symfony versions though. How did we deal with things like this in the past?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We didn't pay enough attention to such things so far. But to be correct it would be required.
xabbuh commentedMar 23, 2015
ping @symfony/deciders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should be documented that null meansdate_default_timezone_get
c7716eb to82b249bComparexabbuh commentedMar 27, 2015
I addressed@Tobion's last comments and added an entry to the changelog. |
Tobion commentedMar 27, 2015
@stof what do you think about#13554 (comment) |
xabbuh commentedMar 27, 2015
By the way, why is the DependencyInjection component not a mandatory requirement? Does this make sense at all? |
xabbuh commentedMar 31, 2015
ping @symfony/deciders Would be nice if we could get this into 2.7. Bumping the DependencyInjection version imho could be discussed afterwards. |
Tobion commentedMar 31, 2015
👍 |
1 similar comment
aitboudad commentedMar 31, 2015
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
All those parameters should be removed and instead, you should inject the value in the service directly. That's what we are doing now as much as possible to avoid polluting the parameters with information you don't need to access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe to not confuse developers looking where those arguments are set add comment like:
<!-- Above arguments are set in TwigExtension-->This adds new Twig configuration options that make it possible toconfigure the format of both numbers and dates as well as timezoneswithout the need to write custom code.For example, using the new configuration options can look like this:```yamltwig: date: format: d.m.Y, H:i:s interval_format: %%d days timezone: Europe/Berlin number_format: decimals: 2 decimal_point: , thousands_separator: .```
fabpot commentedApr 3, 2015
Thank you@xabbuh. |
…igurable (xabbuh)This PR was merged into the 2.7 branch.Discussion----------[TwigBundle] make date formats and number formats configurable| Q | A| ------------- | ---| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#13552| License | MIT| Doc PR | TODOThis adds new Twig configuration options that make it possible toconfigure the format of both numbers and dates as well as timezoneswithout the need to write custom code.For example, using the new configuration options can look like this:```yamltwig: date: format: d.m.Y, H:i:s interval_format: %%d days timezone: Europe/Berlin number_format: decimals: 2 decimal_point: , thousands_separator: .```Commits-------e9bc23b make date formats and number formats configurable
King2500 commentedApr 6, 2015
This is fine. As long as you dont have multiple locales. Wouldn't it make more sense to configure it (additionally?) via translation files? |
smolinari commentedApr 9, 2015
I made that same argument here:#13552 (comment) and got no love. I agree there needed to be a better overall way to generally make changing formats easier, however, I see it the same way as@King2500 . Date, number and even currency formats should be part of ( are defined by?) the end user's locale. If you only need one format, then you most likely only have your application working with users who live in one locale (if there are other reasons for changing the formatting in an application globally, please let me know, as I don't understand the reasoning/ use cases). If you have different users with different locales using the application, then you have to use different locale formats. How does this improvement work with those other locale formats? Also, if you actually do need to use different formatting schemes than the locales offer (and again, I'd love to understand why this might be necessary in a global perspective), then the locale definition is what should be overridable (or possibly make custom locale definitions? Though, that makes even less sense...hmmmm.). Or actually, this extension http://twig.sensiolabs.org/doc/extensions/intl.html has the right logic and I think should actually be part of the core twig package (of an internationally usable templating system). With it in the core, then the locales should be configurable as to which locales are used in the application (defined by each user) and/ or which are overridden or new or customized and how. So that way, when you create templates with variables needing formatting, Twig already takes the user's locale (or the special overridden formatting) into consideration and outputs the formatting accordingly (yes, I'd even leave out the filters and only use a filter, if overriding in the template is actually necessary). If the addition of the extension to the core causes "too much overhead" and why others that don't really need it can avoid using it (and why it is an extension?), then I'd venture to say, the whole formatting system in Twig needs to be revisited. It wasn't created with an "international templating system" in mind, which any template system should be first and foremost. Scott |
…igs (xabbuh)This PR was merged into the 2.7 branch.Discussion----------[TwigBundle] allow to configure custom formats in XML configs| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#13554| License | MIT| Doc PR |Commits-------5a3a24b allow to configure custom formats in XML configs
This adds new Twig configuration options that make it possible to
configure the format of both numbers and dates as well as timezones
without the need to write custom code.
For example, using the new configuration options can look like this: