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

[Translator] Deprecated transChoice and moved it away from contracts#28375

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 2 commits intosymfony:masterfromNyholm:transchoice-deprecation
Oct 6, 2018

Conversation

@Nyholm
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRIssue:symfony/symfony-docs#10264

This will address comment made here:#27399 (review)

This PR moves thetransChoice() method away from Contracts and back to the component. I also reverted changes in theIdentityTranslator. I will still use the deprecatedMessageSelector but this is not fine sincetransChoice() is also deprecated.

jvasseur and ro0NL reacted with thumbs up emojiKoc reacted with heart emoji
Copy link
MemberAuthor

@NyholmNyholm left a comment

Choose a reason for hiding this comment

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

I added some comments that I think will help the review.

-----------

* The`TranslatorInterface` has been deprecated in favor of`Symfony\Contracts\Translation\TranslatorInterface`
* The`Translator::transChoice()` has been deprecated in favor of using`Translator::trans()` with intl message format
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I choose to use the implementation (Translator) here. We already say that the full interface is deprecated.

nicolas-grekas reacted with thumbs up emoji
* @param int $number The number of items represented for the message
* @param string $locale The locale to use for choosing
* @param string$message The message being translated
* @param int|float $number The number of items represented for the message
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We actually support floats.

privatefunctiongetPluralizationRule(int$number,string$locale):int
{
return PluralizationRules::get($number,$locale,false);
returnstrtr($this->selector->choose((string)$id,$number,$locale ?:$this->getLocale()),$parameters);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

FYI: In 4.1 we use(int) $number.

{
returnnewIdentityTranslator();
}

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

These tests are moved from Contracts.

*/
interface TranslatorInterfaceextends BaseTranslatorInterface
{
/**
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Moved this back from Contracts

/**
* {@inheritdoc}
*/
publicfunctiontransChoice($id,$number,array$parameters =array(),$domain =null,$locale =null)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This function was removed. It was a replacement for the deprecatedMessageSelector. I do not think it is needed anymore, right?

Copy link
Member

@nicolas-grekasnicolas-grekasSep 6, 2018
edited
Loading

Choose a reason for hiding this comment

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

right,same for getPluralizationRule below

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Open questions:

  • what should happen when the intl extension is not installed?
  • should be ship a command converting from one format to the other in this PR?

/**
* {@inheritdoc}
*/
publicfunctiontransChoice($id,$number,array$parameters =array(),$domain =null,$locale =null)
Copy link
Member

@nicolas-grekasnicolas-grekasSep 6, 2018
edited
Loading

Choose a reason for hiding this comment

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

right,same for getPluralizationRule below

@Nyholm
Copy link
MemberAuthor

what should happen when the intl extension is not installed?

I think we should ship with "SimpleIntlFormat" that maybe covers some use cases.

should be ship a command converting from one format to the other in this PR?

I think that is a good idea. But that is not a requirement for this PR (nor for 4.2). But the sooner the better.

@nicolas-grekas
Copy link
Member

I think it would be friendly to make migrating to the new format as seamless as possible, running a command to update existing catalogs would be awesome. It should be shipped at the same time as the deprecation to me. If doable of course.

We should also deprecate the twig helpers btw! (as highlighted by the CI ;) )

@Nyholm
Copy link
MemberAuthor

Okey. I'll will not do it in this PR. It is a lot of code and hard to review already. I will work on a migration script now and add that in a other PR.

We should also deprecate the twig helpers btw! (as highlighted by the CI ;) )

Thank you. I saw those now. 👍

Label: Needs work

@stof
Copy link
Member

stof commentedSep 6, 2018

Well, you cannot deprecate thetransChoice API if catalogues are still using the old format.

And we also need to figure out the migration path between format.
And that path should take into account bundles which might need to keep support for 3.4 and 4.1. Forcing bundles to either use the deprecated API or drop support for 3.4 and 4.1 is hurting the upgrade path for bundles (dropping support for the LTS is often not an option for them)

{
if ($this->selector) {
returnstrtr($this->selector->choose((string)$id, (int)$number,$locale ?:$this->getLocale()),$parameters);
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "trans()" method with intl formatted messages instead.',__METHOD__),E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

4.1 ? That's too late for that

Nyholm reacted with laugh emoji
@Nyholm
Copy link
MemberAuthor

This PR is blocked by#28486 and related to#28492.

@nicolas-grekas
Copy link
Member

I just rebased+squashed the PR by pushing on your fork.
There is now#28523 we need to take care of.
I'd suggest moving forward the implementationas if MessageFormatter was always available.
We'll then be able to move#28486 forward independently.

@NyholmNyholmforce-pushed thetranschoice-deprecation branch from868e9bd to39fcccfCompareSeptember 22, 2018 10:45
if ($this->translatorinstanceof LegacyTranslatorInterface) {
$trans =$this->translator->transChoice($id,$number,$parameters,$domain,$locale);
}else {
$trans =$this->doTransChoice($id,$number,$parameters,$domain,$locale);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Is this correct to use the trait here and in the DataCollector?

publicfunctionaddViolation()
{
if (null ===$this->plural) {
if (null ===$this->plural || !$this->translatorinstanceof LegacyTranslatorInterface) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This will cause some deprecations. How can I know if I should use transChoice or not?

@Nyholm
Copy link
MemberAuthor

@stof Thank you for the review.

Well, you cannot deprecate the transChoice API if catalogues are still using the old format.

The migration path would be to run thetranslation:convert-to-intl-message. See#28486

About supporting both formats: That is a fair point, do you have any suggestions?

Status: needs review

@nicolas-grekasnicolas-grekasforce-pushed thetranschoice-deprecation branch 4 times, most recently from562bdff to7cdef58CompareOctober 1, 2018 19:35
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedOct 1, 2018
edited
Loading

I pushed a new approach here, see 2nd commit: I think we should not deprecate the current plural format as this would create a too steep migration path for devs. Instead, I think we should make "trans()" able to resolve plurals. That's already the case when using the INTL message format, so let's make it work with the Symfony format.

What is proposed now is to make the%count% parameter special: when it is defined and is numeric, then the message is parsed using the plural rules.

For Twig,{% transchoice 5 %} is replaced by{% trans count 5 %} or{% trans with {"%count%": 5} %}
and{{ 'message'|transchoice(5) }} by{{ 'message'|trans(count=5) }} or{{ 'message'|trans({"%count%": 5}) }}

There is a potential for conflicts with existing messages when these two conditions are met together:

  1. a%count% parameter is used withtrans(),
  2. the message embeds a pipe character (|).

We could choose another special parameter name if we think the risk is unreasonable (to me it's OK).
WDYT?

Ready for review.

ogizanagi reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Oct 1, 2018
Copy link
MemberAuthor

@NyholmNyholm left a comment

Choose a reason for hiding this comment

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

I've reviewed this carefully. I think it looks alright.

About%count%. I was considering to use# because that is that INTL is using. However, the potential conflicts are larger and we do not need to take this step towards INTL format right now.

👍

$trans =$this->translator->transChoice($id,$number,$parameters,$domain,$locale);
$this->collectMessage($locale,$domain,$id,$trans,$parameters,$number);

$this->collectMessage($locale,$domain,$id,$trans,array('%count%' =>$number) +$parameters);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I've always got problems when adding arrays. Shouldn't we use the more easy-to-read array_merge?

Choose a reason for hiding this comment

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

array_merge is a function call, personally I prefer using the language directly.

ogizanagi reacted with thumbs up emoji
publicfunction__construct(string$fieldName,CsrfTokenManagerInterface$tokenManager,string$tokenId,string$errorMessage,$translator =null,string$translationDomain =null,ServerParams$serverParams =null)
{
if (null !==$translator && !$translatorinstanceof LegacyTranslatorInterface && !$translatorinstanceof TranslatorInterface) {
thrownew \TypeError(sprintf('Argument 5 passed to %s() must be an instance of %s, %s given',__METHOD__, TranslatorInterface::class,\is_object($translator) ?\get_class($translator) :\gettype($translator)));
Copy link
Member

Choose a reason for hiding this comment

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

missing . at the end of the exception message.

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

There are many other occurrences.

Choose a reason for hiding this comment

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

oups, now all of them are fixed

@fabpot
Copy link
Member

Thank you@Nyholm.

@fabpotfabpot merged commitdc5f3bf intosymfony:masterOct 6, 2018
fabpot added a commit that referenced this pull requestOct 6, 2018
…from contracts (Nyholm, nicolas-grekas)This PR was merged into the 4.2-dev branch.Discussion----------[Translator] Deprecated transChoice and moved it away from contracts| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | Issue:symfony/symfony-docs#10264This will address comment made here:#27399 (review)This PR moves the `transChoice()` method away from Contracts and back to the component. I also reverted changes in the `IdentityTranslator`. I will still use the deprecated `MessageSelector` but this is not fine since `transChoice()` is also deprecated.Commits-------dc5f3bf Make trans + %count% parameter resolve pluralsd870a85 [Translator] Deprecated transChoice and moved it away from contracts
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof requested changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

5 participants

@Nyholm@nicolas-grekas@stof@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp