Problem/Motivation

Instead of using the config translation label, in #3019298 we hardcode the source language of the config to English and then run these labels again through t(). All these objects are config entities so instead of using locale to do the translation, we should depend on the config translation.

This is the original issue:

FILE: ...les/admin_toolbar/admin_toolbar_tools/admin_toolbar_tools.module
----------------------------------------------------------------------
FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
 100 | WARNING | Only string literals should be passed to t() where
     |         | possible
 110 | WARNING | Only string literals should be passed to t() where
     |         | possible
 233 | WARNING | Only string literals should be passed to t() where
     |         | possible
 277 | WARNING | Only string literals should be passed to t() where
     |         | possible
 321 | WARNING | Only string literals should be passed to t() where
     |         | possible
 539 | WARNING | Only string literals should be passed to t() where
     |         | possible
 571 | WARNING | Only string literals should be passed to t() where
     |         | possible
----------------------------------------------------------------------

Comments

thalles created an issue. See original summary.

thalles’s picture

Project: Administration menu » Admin Toolbar
Version: 8.x-3.x-dev » 8.x-1.x-dev
thalles’s picture

Status: Needs work » Needs review
StatusFileSize
new3.89 KB

Follow the patch

Status: Needs review » Needs work
adriancid’s picture

Hi @thalles as the problem says:

Only string literals should be passed to t() where possible

In this case, I don't think we are improving nothing, you're only changing the variable with a placeholder, but in the end, we are only translating a variable.

thalles’s picture

Status: Needs work » Closed (works as designed)

Ok! Thanks!

thalles’s picture

Status: Closed (works as designed) » Needs review

Hello @adriancid, sorry for reopening, but we have a good reason to change, in some places before the deploy runs a sniffer, which can block in case of occurrences, but feel free to accept the patch or not.

Thank you for your attention!

adriancid’s picture

Thanks, @thalles I will check the patch, but why you run a sniffer against contributed modules, you should do this only for your custom modules.

thalles’s picture

This helps us contribute to the community.

mpp’s picture

Status: Needs review » Needs work

Instead of putting the source label through the translation helper we should get the translated labels (e.g. with $entity->getTranslation()).

mpp’s picture

Title: String literals on t() » Config labels are not properly translated
Category: Task » Bug report
Priority: Normal » Major
Issue summary: View changes
Status: Needs work » Needs review
Related issues: +#3019298: Menu items for content entity show in wrong language
StatusFileSize
new4.34 KB

After some more debugging I found out that a bug has been introduced in #3019298.

Instead of using the config translation label, in #3019298 we hardcode the source language of the config to English and then run these labels again through t(). All these objects are config entities so instead of using locale to do the translation, we should depend on the config translation.

I added a patch that will fix the original issue ("String literals on t()") but that will also remove the redundant t() and the unneeded hardcoding of English config.
We could put this back in place in a follow up ticket as a feature to allow people to define the language for the menu. But as it now stands this is a bug.

gábor hojtsy’s picture

Config translation should not be hacked around like this IMHO indeed. Theme name looks like an exception that it is not config, but that should not be translated either, we don't translate component name.

fernly’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thx mpp.

  • adriancid committed f3d7b96 on 8.x-1.x authored by mpp
    Issue #3026337 by thalles, mpp, adriancid, Gábor Hojtsy: Config labels...
adriancid’s picture

Status: Reviewed & tested by the community » Fixed

Thanks to @all

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.