Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Symfony 4.2 has deprecated \Symfony\Component\Translation\TranslatorInterface::transChoice()
.
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
*/
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%%count%%" parameter.', __METHOD__), \E_USER_DEPRECATED);
However we implement this method in \Drupal\Core\Validation\DrupalTranslator:
/**
* {@inheritdoc}
*/
public function transChoice($id, $number, array $parameters = [], $domain = NULL, $locale = NULL) {
We did not get a deprecation notice as we do not call the parent method.
Steps to reproduce
Proposed resolution
Deprecate this method for removal, or just remove it entirely, as it is likely only called by upstream code.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff_13-16.txt | 895 bytes | murilohp |
#16 | drupal-trans-choice-deprecated-3255250-16.patch | 3.21 KB | murilohp |
#3 | drupal-trans-choice-deprecated-3255250-3.patch | 1.83 KB | murilohp |
|
Comments
Comment #2
longwaveComment #3
murilohp CreditAttribution: murilohp at CI&T commentedHey @longwave, I searched the entire code on branch 10.0.x for
transChoice
and I haven't found anything, so following your proposed solution, removed the function.Thanks!
Comment #4
Gábor HojtsyI think it would be better to deprecate this, as contributed projects may still use it.
Comment #5
murilohp CreditAttribution: murilohp at CI&T commentedThanks for the response, and I think it's a good catch, here's a new patch deprecating the method.
Comment #6
murilohp CreditAttribution: murilohp at CI&T commentedComment #7
daffie CreditAttribution: daffie commentedWe need 2 more things in the patch:
Outside of the patch: we need a change record.
@murilohp: Check the code for examples of how to do it.
Comment #8
murilohp CreditAttribution: murilohp at CI&T commentedThanks for the feedback @daffie!
Comment #9
Gábor HojtsyCreated a change record draft at https://www.drupal.org/node/3256859.
Comment #10
Gábor HojtsyAlso we can deprecate in 9.4.x and remove in Drupal 10 since Symfony 4.2 already deprecated the method and Drupal 10 will be based hopefully on Symfony 6.
Comment #11
murilohp CreditAttribution: murilohp at CI&T commentedThanks for the change record @Gábor Hojtsy, I followed your idea and changed the depreacation to D9.4, @daffie, I updated the docblock and about the test, I haven't found any tests for
DrupalTranslation
class, maybe we should open a new issue to cover this class. To cover the deprecation message, I created a new test class and a new function to validate this scenario.So I'm uploading 2 patches, the first one is focused on D9.4 and it's the test-only. The second patch is for D9.4 and its the correct patch.
About the function cleanup(Drupal 10), we already have the patch #3.
Thanks!
Comment #12
murilohp CreditAttribution: murilohp at CI&T commentedUploading new patches to fix coding standards.
Comment #13
murilohp CreditAttribution: murilohp at CI&T commentedForgot the @see on #12(drupal-trans-choice-deprecated-3255250-12.patch). Now I think it's ready to go.
Comment #15
daffie CreditAttribution: daffie commentedPatch looks good. Just one minor nitpick:
Every test need an assertion. Can you add one to this line. Something like the result is equal to: "There is one apple". The assertion does not need to be useful, it just need to be there.
Comment #16
murilohp CreditAttribution: murilohp at CI&T commented@daffie here's a new patch asserting the
transChoice
call on the test. Since thestring_translation
is a mock object, I decided to assert just the class instance.Thanks!
Comment #17
daffie CreditAttribution: daffie commentedAll the code changes look good to me.
The IS and the CR are in order.
For me it is RTBC.
Comment #18
alexpottCommitted and pushed c274b2b8f3f to 10.0.x and 5b6ee132108 to 9.4.x. Thanks!
Comment #22
quietone CreditAttribution: quietone at PreviousNext commentedPublished the CR per #17