Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue job descriptions not translated #9696

Closed
carlcs opened this issue Aug 10, 2021 · 11 comments
Closed

Queue job descriptions not translated #9696

carlcs opened this issue Aug 10, 2021 · 11 comments

Comments

@carlcs
Copy link
Contributor

carlcs commented Aug 10, 2021

Description

Queue job descriptions in the CP sidebar show in the source language instead of being translated to the user’s language.

Steps to reproduce

  1. Start a queue job from the console

    php craft resave/entries --queue=1
  2. Log into the control panel as a user with preferred language set to German

  3. See how the description shows in English

Additional info

  • Craft version: 3.7.8
  • PHP version: 7.3.7
  • Database driver & version: PostgreSQL 11.11
  • Plugins & versions: n/a
@carlcs carlcs added the bug label Aug 10, 2021
@brandonkelly
Copy link
Member

They will show whatever language was active at the time the job was added to the queue (unless no insttance-specific description was provided, so it just goes with the job’s default description).

Unfortunately it’s not possible to change that, unless we start eager-translating the description into all possible languages up front and storing them all as part of the job’s data, which would take up quite a bit more storage.

@carlcs
Copy link
Contributor Author

carlcs commented Aug 10, 2021

Thanks for the answer, Brandon. Is this something that changed since Craft 3.6.12? We’re running some custom jobs regularly and I’m pretty sure descriptions were translated just fine in the past.

@brandonkelly
Copy link
Member

It’s been this way since 3.0.0. Perhaps the job in question has recently started gaining an instance-specific description though. Which job is it?

@carlcs
Copy link
Contributor Author

carlcs commented Aug 19, 2021

It’s a custom job. I have now reverted to 3.6.12 to test this again, and for some reason both the description (set via Job::defaultDescription()) and the progress label (set via Job::setProgress()) are translated to German. But it happens to be translated to German for all users, so there’s indeed no user-language targeted translation happening as I have thought.

After the test I’ve updated to 3.7.9 (no further code changes), and the job descriptions are now output in English again.

They will show whatever language was active at the time the job was added to the queue

How’s the “active language” determined when the queue job is added via a console command? Maybe this is what has changed in Craft 3.7. Language of my primary site is set to German.

@carlcs
Copy link
Contributor Author

carlcs commented Aug 19, 2021

I’ve also noticed that the progress label of the native “Resave elements” job isn’t translated in 3.7 any longer. The progress label shows “x of total“ instead of “x von total” how it was in Craft 3.6.

  1. Set you user language to German
  2. Trigger a “Resave elements” job from the CP by going into an entry section’s settings and updating the URI format

$this->setProgress($queue, ($e->position - 1) / $total, Craft::t('app', '{step, number} of {total, number}', [
'step' => $e->position,
'total' => $total,
]));

@brandonkelly
Copy link
Member

brandonkelly commented Aug 19, 2021

How’s the “active language” determined when the queue job is added via a console command? Maybe this is what has changed in Craft 3.7. Language of my primary site is set to German.

Ahhh, that explains it. As of 3.7, console requests just stick to the app’s source language (English), per #7747. I changed that because most CLI messages aren’t translatable in the first place (since we don’t have a way of knowing the user’s preferred language from CLI commands).

I’ve also noticed that the progress label of the native “Resave elements” job isn’t translated in 3.7 any longer. The progress label shows “x of total“ instead of “x von total” how it was in Craft 3.6.

Same explanation there, if you’re running the queue from a CLI command.

I’m going to add a new cliLanguage config setting that you can set to fix this.

@brandonkelly brandonkelly reopened this Aug 19, 2021
@carlcs
Copy link
Contributor Author

carlcs commented Aug 19, 2021

Same explanation there, if you’re running the queue from a CLI command.

It would be nice if you could make it happen so that the description and progress label are using the same language. Because currently the description shows in the CP user’s language even if the queue is run from console.

@brandonkelly
Copy link
Member

Not sure how we’d do that though. The description is translated at job creation time, and the progress statuses are translated by the job during execution.

Jobs could start being configured with the current language at the time it was queued up, and use that language when translating progress messages, but that only makes them consistent with the description language; both would still not necessarily be the right language for every control panel user.

If we’re going to solve this correctly, it’s going to be by setting the description and progress messages to an array that includes the message category (app or a plugin handle) plus the source message string and any translation params, and letting the UI do the actual Craft::t() call, for the current user’s language.

That wouldn’t be too difficult, but it would mess up the translation message scraper feature in the Yii2 Inspections PhpStorm plugin which we rely on, so we’d need to work that out.

@carlcs
Copy link
Contributor Author

carlcs commented Aug 19, 2021

I only wanted to mention what my next complaint will be, before you’re working on a cliLanguage config setting.

Personally I’m totally fine with job descriptions showing untranslated in English in the CP. I’ve probably only noticed it because I’ve recently added German translations for a couple of custom jobs and wondered why they weren‘t working any longer in 3.7.

We have users with language set to English too, so in our case I’ll just remove my translations again and have everyone see descriptions in English. I wouldn’t use that cliLanguage setting.

You’ve got me behind you with that other suggestion though. 😄

@brandonkelly
Copy link
Member

Just resolved this for v4: #9745

@carlcs
Copy link
Contributor Author

carlcs commented Aug 23, 2021

Beautiful solution. Thanks Brandon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants