Skip to content

DEV: Add the ability to translate a single piece of text #281

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

Merged
merged 2 commits into from
Apr 23, 2025
Merged

Conversation

nattsw
Copy link
Contributor

@nattsw nattsw commented Apr 22, 2025

Currently the translator providers are all implementing a translate! that takes in a model (post or topic). We want to add a generate translate_text method that allows us to just say "Translate '日本' to English"

Note that since we omit the source language, this new method is unsupported on Libre and Yandex.

def self.required_settings_enabled
SiteSetting.translator_enabled && SiteSetting.translator_provider == "DiscourseAi" &&
SiteSetting.discourse_ai_enabled && SiteSetting.ai_helper_enabled
def self.required_settings_enabled!
Copy link
Contributor

Choose a reason for hiding this comment

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

naming nit: I was wondering if something like validate_required_settings might be clearer.. when I read these, my initial thought was that this method was modifying stuff because of the !.

@nattsw nattsw merged commit e42c0da into main Apr 23, 2025
6 checks passed
@nattsw nattsw deleted the translate-text branch April 23, 2025 03:01
@jonaharagon
Copy link

Note that since we omit the source language, this new method is unsupported on Libre and Yandex.

I believe you're mistaken because auto is a valid source language with LibreTranslate

nattsw added a commit that referenced this pull request Apr 24, 2025
This feature introduces the ability to translate categories on core's CategoryLocalization from discourse/discourse#32380. This includes 

- the addition of a generic `Translator.translate` which takes in supported models
- a `CategoryTranslator` specific to categories, which uses the basic text translator introduced in #281
- a 12-hourly scheduled job that invokes a regular job.

Anyone can manually translate all categories using

```
Jobs.enqueue(:translate_categories)
```
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