Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Feb 26, 2025

Not too long ago, we moved language detections to a scheduled job. (see internal /t/134867/21)

But the new inline translation feature (when turned on) sends all content for translation the moment it is created. So far, we are not seeing an issue with load for this.

This PR reverts the batching for language detection to the original way, in-line with the new translation feature.

This PR also does a bit of cleanup - introducing three files to encapsulate the plugin event hooks into their own functionality (automatic translation, inline translation, dual-text translation)

This changes here will help to simplify the problem of 🌐 showing up in the post briefly, but in a subsequent PR.

def execute(args)
return unless SiteSetting.translator_enabled

translatable = args[:type].constantize.find_by(id: args[:translatable_id])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate that args[:type] returns a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair!

class AutomaticTranslations
def inject(plugin)
plugin.on(:post_process_cooked) do |_, post|
if SiteSetting.automatic_translation_target_languages.present? && post.user_id > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm missing some context on how auto-translation should work for system-type users like system (typically with negative user IDs), I'm assuming from these that they are deliberately exempt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for now, bot posts should not be translated. (so stuff like discobot PMs or AI bot responses should generally be avoided)

Copy link
Contributor

@tyb-talks tyb-talks left a comment

Choose a reason for hiding this comment

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

lgtm outside of the nit on validating args[:type] :)

@nattsw nattsw merged commit 65baebb into main Feb 26, 2025
5 checks passed
@nattsw nattsw deleted the exist-method-detect-immediately branch February 26, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants