Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 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
derrabus commentedMay 8, 2021
Please give your PR a meaningful title. |
08f1df0 to4cde975Compare This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Translation/Translatable/TranslatableCurrency.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
60985be tocdc168fCompare539ce31 tof274351Comparesylfabre commentedMay 30, 2021
@ro0NL I've actually created another interface: |
9b1506d toed8eae3Compare0ce48cf tocc02f6aComparesylfabre commentedDec 6, 2021
Thank you@stof for the review, I've fixed my PR |
0f0101c tob642d18Compareb642d18 todab3f2aCompare| $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 fromsymfony/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 fromsymfony/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
welcoMattic commentedSep 20, 2023
@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. |
OskarStark commentedOct 24, 2023
friendly ping@sylfabre 👋 |
sylfabre commentedOct 24, 2023
@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? |
nicolas-grekas commentedOct 24, 2023
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
| privatestaticarray$formatters = []; | ||
| publicfunction__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)
| "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 usingsuggest 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 thefromMoney static method described in the PR description.
fabpot commentedFeb 4, 2024
Closing as there is no more activity. Feel to reopen when you have time. |
Uh oh!
There was an error while loading.Please reload this page.
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,
TranslatableMessagenow supports recursiveTranslatableInterfaceas params.This PR implements a few common use-cases for arguments that must be first formatted to improve DX:
DateTimeParameterto format date and timeMoneyParameterto format monetary values with the support ofhttps://github.com/moneyphp/moneyDecimalParameterto format decimal values as per locale specsThe following implementations could be considered in later PRs:
CountryParameterto format the ISO 3166-2 into a localized country nameBefore this PR
After this PR
TODO
DecimalParameter