Closed (won't fix)
Project:
Drupal core
Version:
11.x-dev
Component:
other
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
19 Jun 2020 at 08:47 UTC
Updated:
21 Dec 2023 at 14:31 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
hardik_patel_12 commentedKindly review a new patch.
Comment #3
hardik_patel_12 commentedComment #4
mondrakeComment #5
siddhant.bhosale commentedComment #6
siddhant.bhosale commentedHi, the patch applies cleanly, and also the tests are run successfully.
Comment #7
alexpottfind ./core -type f -name "*Test*.php" -exec grep -E 'setLabel.*t\(' {} + Tue 14 Jul 10:22:53 2020
./core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php: ->setLabel(t('A comment field'))
./core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php: ->setLabel(t('ID'))
./core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php: ->setLabel(t('UUID'))
./core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestObjectItem.php: ->setLabel(t('Value'))
./core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php: ->setLabel(t('Test integer value'))
./core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestWithRevisionLog.php: ->setLabel(t('Name'))
./core/modules/system/tests/modules/entity_test_update/src/Plugin/Field/FieldType/MultiValueTestItem.php: ->setLabel(t('First value'));
./core/modules/system/tests/modules/entity_test_update/src/Plugin/Field/FieldType/MultiValueTestItem.php: ->setLabel(t('Second value'));
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php: ->setLabel(t('Some custom description'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestFieldMethods.php: ->setLabel(t('Test field method invocation order.'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMapField.php: ->setLabel(t('Data'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php: ->setLabel(t('Test field'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php: ->setLabel(t('Non translatable'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php: ->setLabel(t('Field with no display'));
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php: ->setLabel(t('Field with configurable display'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php: ->setLabel(t('Field with non-configurable display'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php: ->setLabel(t('A field with multiple values'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php: ->setLabel(t('Revision ID'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php: ->setLabel(t('Revision translation affected'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php: ->setLabel(t('ID'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraints.php: ->setLabel(t('Changed'));
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php: ->setLabel(t('Changed'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php: ->setLabel(t('Non translatable'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php: ->setLabel(t('Some custom description'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php: ->setLabel(t('Name'))
./core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php: ->setLabel(t('Non Revisionable Field'))
./core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php: $definitions['new_base_field']->setLabel(t('A new base field'));
./core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php: ->setLabel(t('A new long-named base field'))
./core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php: ->setLabel(t('A new revisionable base field'))
./core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php: ->setLabel(t('A new bundle field'))
And
I think instances where this is needed should be commented and we should also take the opportunity to consider whether the test code in entity_test should use t() too.
Comment #8
snehalgaikwad commentedComment #9
paulocsReplace t() in some more places that was missing.
Comment #10
paulocsInterdiff #8 and #9
Comment #11
longwaveI reviewed the patch with
git diff --color-wordsand only t() wrappers are removed.I also checked for missed items with
rg 'setLabel\(t\('|rg -i testandrg 'setDescription\(t\('|rg -i testand didn't find any.Therefore this is RTBC.
Comment #13
longwave#3037436: [random test failure] Make QuickEditIntegrationTest more robust and fail proof strikes again
Comment #14
alexpottSo we have #3157938: Use t() for #title and #description in tests and test modules which is going in the other direction. Not sure what's correct here. I discovered recently that the PO extractor ignores all of these strings so maybe the argument that we should be consistent with real runtime code in tests and set a good example for copy and paste.
Comment #15
alexpottFWIW I don't think this t() usage is the same as remove t() from an assertion message. I'm not really sure this should be part of #3133726: [meta] Remove usage of t() in tests not testing translation
Comment #16
andypost-1 here because I often using test modules to show examples of how something could be used
Instead of that I'd removed
t()from all entity classes (baseFieldDefinitions()at least because havingt()here really confusing).Moreover both methods
setLabel()andsetDescription()could check is passed in string or translatable object and in case of strings wrap it into translatable class... but it will need to tune potx to extract this strings...Comment #17
longwave> Moreover both methods setLabel() and setDescription() could check is passed in string or translatable object
Maybe we should go further and only allow TranslatableMarkup to be passed in? ie. add a deprecation warning if it's a string and then use a typehint in D10?
Comment #18
andypost++ to #17 and set proper type to arguments in d10
Comment #19
longwaveLet's try #17 though I think this is going to fail horribly somewhere, we might need a way to bypass this in some cases.
Comment #26
quietone commentedTagging for coding standards and moving to the 'other' component where such issues live.
Comment #27
chaitanyadessai commentedRemoved t() calls from setLabel() and setDescription().
Comment #28
smustgrave commented@chaitanyadessai please include an interdiff with your patches
Doing a search for ->setLabel(t(
Showed more instances from test files I don't think are related to revisions
Same for setDescription
Comment #29
adeshsharma commentedRemoved t calls.
Comment #30
smustgrave commentedSeems all instances have been removed. So guess we weren't testing translation of either of those. Should we open a follow up to add testing?
Comment #31
longwaveThis still needs discussion as to whether we should actually do it, as per #14 through #18.
Comment #33
longwaveThinking this through some more after working on the final t() removals in tests in #3410128: Remove remaining unnecessary uses of t() in tests, I now think this is won't fix - we need test coverage of TranslatableMarkup passed through to various common APIs like render, form and field API and test coverage should provide good examples to use as well.
Marking "needs review" for this comment, hiding all other patches.
Comment #34
longwaveExplaining a bit further:
In real-world implementations of
setLabel()and similar methods we uset(). By removingt()in tests we are not really testing the same way a real-world implementation would, if we only used raw strings in tests then how would be sure that the code actually works with translatable strings?Also, tests are sometimes used as examples of features and the code is copy-pasted and then edited and used for real. If we drop
t()here we risk people copy-pasting and not following the best practice of adding translatable labels and descriptions.It's similar to when we have a test form. In most test form implementations we still wrap form element labels in
t()because that's what a real world implementation of a form should do.Comment #35
smustgrave commentedExplanation makes sense, anyone really disagrees please reopne.