Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:2.7fromxabbuh:issue-13552
Apr 3, 2015

Conversation

@xabbuh
Copy link
Member

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#13552
LicenseMIT
Doc PRTODO

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:

twig:date:format:d.m.Y, H:i:sinterval_format:%%d daystimezone:Europe/Berlinnumber_format:decimals:2decimal_point:,thousands_separator:.

@stof
Copy link
Member

this implementation is wrong. the Twig_Environment should not be configured through the TwigEngine, as this means that thetwig service is not configured fully whne using it directly rather than using the templating component

@xabbuh
Copy link
MemberAuthor

I see your point, but do we have a better place where we can call methods of the Twig extensions?

@stof
Copy link
Member

@xabbuh Well, there is 2 solutions here:

  • registering the Twig_Extension_Core explicitly (so that we have a private service for it)
  • using a service configurator to apply the logic. An example can be foundin DoctrineBundle usedthere

Copy link
Member

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
Copy link
MemberAuthor

@stof Thanks for pointing me towards service configurators.

Copy link
MemberAuthor

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 182

Copy link
Member

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.

Copy link
Member

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

Copy link
MemberAuthor

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.

Copy link
Member

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)

Copy link
MemberAuthor

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.

Copy link
MemberAuthor

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.

Copy link
Contributor

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.

Copy link
MemberAuthor

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?

Copy link
Contributor

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
Copy link
MemberAuthor

ping @symfony/deciders

Copy link
Contributor

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

@xabbuhxabbuhforce-pushed theissue-13552 branch 3 times, most recently fromc7716eb to82b249bCompareMarch 27, 2015 15:03
@xabbuh
Copy link
MemberAuthor

I addressed@Tobion's last comments and added an entry to the changelog.

@Tobion
Copy link
Contributor

@stof what do you think about#13554 (comment)

@xabbuh
Copy link
MemberAuthor

By the way, why is the DependencyInjection component not a mandatory requirement? Does this make sense at all?

@xabbuh
Copy link
MemberAuthor

ping @symfony/deciders Would be nice if we could get this into 2.7. Bumping the DependencyInjection version imho could be discussed afterwards.

@Tobion
Copy link
Contributor

👍

1 similar comment
@aitboudad
Copy link
Contributor

👍

Copy link
Member

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.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

Copy link
Contributor

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
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commite9bc23b intosymfony:2.7Apr 3, 2015
fabpot added a commit that referenced this pull requestApr 3, 2015
…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
@xabbuhxabbuh deleted the issue-13552 branchApril 3, 2015 12:41
@King2500
Copy link
Contributor

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
Copy link

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

maxim-dovydenok reacted with heart emoji

nicolas-grekas added a commit that referenced this pull requestJul 11, 2017
…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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@xabbuh@stof@Tobion@aitboudad@fabpot@King2500@smolinari@stloyd

[8]ページ先頭

©2009-2025 Movatter.jp