-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Separate parameters formatting #41136
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please give your PR a meaningful title. |
08f1df0
to
4cde975
Compare
src/Symfony/Component/Translation/Translatable/TranslatableCurrency.php
Outdated
Show resolved
Hide resolved
60985be
to
cdc168f
Compare
539ce31
to
f274351
Compare
@ro0NL I've actually created another interface: |
9b1506d
to
ed8eae3
Compare
0ce48cf
to
cc02f6a
Compare
Thank you @stof for the review, I've fixed my PR |
0f0101c
to
b642d18
Compare
b642d18
to
dab3f2a
Compare
$this->dateTime = $dateTime; | ||
$this->dateType = $dateType; | ||
$this->timeType = $timeType; | ||
} |
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 we use constructor promotion for all features targeting 6.1?
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.
yes (especially now that we target 7.1)
This PR was merged into the 6.1 branch. Discussion ---------- [Translation] Translatable parameters | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | TBD ✅ The TwigExtension now supports messages implementing `TranslatableInterface` (https://symfony.com/blog/new-in-symfony-5-2-translatable-objects). ✅ Thanks to #41858, `TranslatableMessage` now supports recursive `TranslatableInterface` as params. ❌ But using `TranslatableInterface` as params with regular messages is not supported yet. 💡 This PR addresses this issue and makes it possible to create dedicated `TranslatableInterface` implementations like the one from #41136 _Note: I would like also to add `TranslatableInterface` to the `trans(?string $id)` signature method like with the one from the [TwigExtension](https://github.com/symfony/symfony/blob/6.1/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php#L111) but I don't know how to do it without breaking BC. Any advice is welcome!_ Commits ------- 5beaee8 [Translation] Translatable parameters
This PR was merged into the 6.1 branch. Discussion ---------- [Translation] Translatable parameters | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | TBD ✅ The TwigExtension now supports messages implementing `TranslatableInterface` (https://symfony.com/blog/new-in-symfony-5-2-translatable-objects). ✅ Thanks to #41858, `TranslatableMessage` now supports recursive `TranslatableInterface` as params. ❌ But using `TranslatableInterface` as params with regular messages is not supported yet. 💡 This PR addresses this issue and makes it possible to create dedicated `TranslatableInterface` implementations like the one from symfony/symfony#41136 _Note: I would like also to add `TranslatableInterface` to the `trans(?string $id)` signature method like with the one from the [TwigExtension](https://github.com/symfony/symfony/blob/6.1/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php#L111) but I don't know how to do it without breaking BC. Any advice is welcome!_ Commits ------- 5beaee85f9 [Translation] Translatable parameters
This PR was merged into the 6.1 branch. Discussion ---------- [Translation] Translatable parameters | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | TBD ✅ The TwigExtension now supports messages implementing `TranslatableInterface` (https://symfony.com/blog/new-in-symfony-5-2-translatable-objects). ✅ Thanks to #41858, `TranslatableMessage` now supports recursive `TranslatableInterface` as params. ❌ But using `TranslatableInterface` as params with regular messages is not supported yet. 💡 This PR addresses this issue and makes it possible to create dedicated `TranslatableInterface` implementations like the one from symfony/symfony#41136 _Note: I would like also to add `TranslatableInterface` to the `trans(?string $id)` signature method like with the one from the [TwigExtension](https://github.com/symfony/symfony/blob/6.1/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php#L111) but I don't know how to do it without breaking BC. Any advice is welcome!_ Commits ------- 5beaee85f9 [Translation] Translatable parameters
* Add new implementations of `TranslatableInterface` to format parameters | ||
separately as recommended per the ICU for DateTime, money, and decimal values. |
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.
After rebase, this should be moved to 6.4 section
@sylfabre what is the status of this PR? There are some not addressed comments and the branch needs to be rebased, but I think we are close to be able to merge it. |
friendly ping @sylfabre 👋 |
@welcoMattic @OskarStark Sorry for the late answer: the back-to-school period was challenging on my side 🙈 Before that: @stof @nicolas-grekas does this suggestion/PR make sense to you? Is working on it worth it? |
No objections on my side, let's resume the PR for 7.1. |
$key = implode('.', [$locale, $this->dateType, $this->timeType, $timezone->getName()]); | ||
if (!isset(self::$formatters[$key])) { | ||
self::$formatters[$key] = new \IntlDateFormatter( | ||
$locale ?? $translator->getLocale(), |
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.
the coalesce is dead code as the default is already applied in the variable a few lines above
|
||
private static array $formatters = []; | ||
|
||
public function __construct( |
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 suggest adding @param \IntlDateFormatter::* $dateType
(and same for the other parameters in this constructor and static factory methods) so that static analysis tool can report invalid values
$this->dateTime = $dateTime; | ||
$this->dateType = $dateType; | ||
$this->timeType = $timeType; | ||
} |
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.
yes (especially now that we target 7.1)
@@ -47,7 +47,8 @@ | |||
"suggest": { | |||
"symfony/config": "", | |||
"symfony/yaml": "", | |||
"psr/log-implementation": "To use logging capability in translator" | |||
"psr/log-implementation": "To use logging capability in translator", | |||
"moneyphp/money": "To use money capability in translator" |
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 stopped using suggest
in the composer packages.
Thus, this suggestion is useless. If you don't already use this money library, there is no reason to suggest you to use it to use the MoneyTranslatable object (you would use its constructor directly). And if you already use the library, composer won't display the suggestion as it is already part of the project.
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.
thus, your PR does not even contain the fromMoney
static method described in the PR description.
Closing as there is no more activity. Feel to reopen when you have time. |
ICU recommends to first format advanced parameters before translation (https://unicode-org.github.io/icu/userguide/format_parse/messages/#format-the-parameters-separately-recommended).
Thanks to #41858,
TranslatableMessage
now supports recursiveTranslatableInterface
as params.This PR implements a few common use-cases for arguments that must be first formatted to improve DX:
DateTimeParameter
to format date and timeMoneyParameter
to format monetary values with the support of https://github.com/moneyphp/moneyDecimalParameter
to format decimal values as per locale specsThe following implementations could be considered in later PRs:
CountryParameter
to format the ISO 3166-2 into a localized country nameBefore this PR
After this PR
TODO
DecimalParameter