Discourse 翻译器

:discourse2: Summary Discourse Translator translates posts on Discourse using Microsoft, Google, or Yandex translation APIs.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-translator
:open_book: Install Guide How to install plugins in Discourse

Features

  • Each post is only translated once per locale which saves you :moneybag:
    • Note that language detection is also run once for every post. Be careful when enabling this on old and large forums.
  • Access Token is cached server side for faster translations.
  • Translations are rate limited to 3 per minute by default (admins can configure this value)

Translation Services Supported

Configuration Steps

Microsoft
  1. Follow the steps in Microsoft Translator API on Azure to obtain a subscription key. You may pick from any of the available subscription offers.

  2. In your Discourse, under Admin > Settings > Plugins, enter the subscription key that you’ve obtained from the steps above.

enter subscription key

  1. In your Discourse, under Admin > Settings > Basic Setup, enable allow user locale.
Google Translator
  1. Go to https://console.developers.google.com

  2. Click on My Project

my project

  1. Click on the :heavy_plus_sign: to create a new project

  1. Enter your project name and click create

  2. Select Enable API and search for Google Cloud Translator API. Look for the enable button and click it to enable the API. Note that there is no free tier for the Google Translator API so it may prompt you to enable billing.

  3. Once you’re done, click on credentials in the left menu

credentials

  1. Click create credentials and select API key. Copy the API Key and paste it into the translator google api key site setting in Discourse.

  2. In Discourse, under Admin > Settings > Basic Setup, enable allow user locale.

Settings

Name Description
translator enabled Allow inline translation of posts.
translator The provider of the translation service.
translator azure subscription key Azure Subscription Key
translator azure region Azure Region
translator azure custom subdomain Required if using a Virtual Network or Firewall for Azure Cognitive Services. Note: Only enter the custom subdomain not the full custom endpoint.
translator aws region AWS Region
translator aws key id AWS Key ID
translator aws secret access AWS secret access key
translator aws iam role AWS IAM Role
translator google api key Google API Key
translator yandex api key Yandex API Key
translator libretranslate endpoint LibreTranslate Endpoint
translator libretranslate api key LibreTranslate API Key
max translations per minute The number of translations per minute a regular user can perform.
restrict translation by group Only allowlisted groups can translate
restrict translation by poster group Only allow translation of posts made by allowlisted users

Known Issues

  • Does not translate text within polls generated by discourse-poll plugin.
  • Images are enlarged upon translating.

:discourse2: Hosted by us? This plugin is available on our Enterprise plan.

Last edited by @JammyDodger 2024-06-18T14:19:34Z

Check documentPerform check on document:
102 个赞

帖子已拆分为新主题:我正在寻找这样的解决方案,以使用 LLM 翻译我论坛的热门帖子

一个帖子被拆分到一个新主题:为语言检测服务添加单独的配置选项

帖子已拆分为新主题:由 Discourse 托管的论坛是否使用 LibreTranslate 的本地实例?

我正在使用自托管的 LibreTranslate,它过去运行良好,但现在我收到了很多重复的“Job exception: The translator service is currently not available”(作业异常:翻译服务当前不可用)错误。我已检查 URL,它过去一直正常工作。如果我访问该 URL,LibreTranslate 网页会显示。由于我的 LibreTranslate 实例是私有的,没有互联网访问权限,因此不需要 API/令牌。

回溯显示:

Message (548 copies reported)

Job exception: The translator service is currently not available.

Backtrace

/var/www/discourse/plugins/discourse-translator/services/discourse_translator/libretranslate.rb:168:in `result'
/var/www/discourse/plugins/discourse-translator/services/discourse_translator/libretranslate.rb:85:in `detect'
/var/www/discourse/plugins/discourse-translator/plugin.rb:120:in `block in execute'
/var/www/discourse/lib/distributed_mutex.rb:53:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize'
/var/www/discourse/plugins/discourse-translator/plugin.rb:119:in `execute'
/var/www/discourse/app/jobs/base.rb:305:in `block (2 levels) in perform'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/rails_multisite-6.0.0/lib/rails_multisite/connection_management/null_instance.rb:49:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/rails_multisite-6.0.0/lib/rails_multisite/connection_management.rb:21:in `with_connection'
/var/www/discourse/app/jobs/base.rb:292:in `block in perform'
/var/www/discourse/app/jobs/base.rb:288:in `each'
/var/www/discourse/app/jobs/base.rb:288:in `perform'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:202:in `execute_job'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:170:in `block (2 levels) in process'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:177:in `block in invoke'
/var/www/discourse/lib/sidekiq/pausable.rb:132:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:179:in `block in invoke'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:182:in `invoke'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:169:in `block in process'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:136:in `block (6 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_retry.rb:113:in `local'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:135:in `block (5 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq.rb:44:in `block in <module:Sidekiq>'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:263:in `stats'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_logger.rb:13:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_retry.rb:80:in `global'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:124:in `block in dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_logger.rb:39:in `prepare'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:123:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:168:in `process'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:78:in `process_one'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:68:in `run'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/component.rb:8:in `watchdog'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/component.rb:17:in `block in safe_thread'

有什么想法可以解决这个问题吗?

2 个赞

‘Discourse’ 中尚无 ‘Hindi’ 区域设置选项。但 ‘Hindi’ 翻译可通过不同服务获得(我正在使用 ‘Microsoft Azure’)。

那么,如何在 Discourse 界面保持为英文的情况下,设置将所有/任何非 Hindi 帖子翻译成 ‘Hindi’ 呢?这是否可行?

1 个赞

我也尝试将此问题交叉发布到他们的 discourse 论坛。

3 个赞

我想考虑将此翻译器添加到我们的论坛。但我有两个主要顾虑:

1. 是否可以修改翻译?
我希望确保某些术语以特定方式翻译。为此,我需要能够查看可用翻译,并在必要时进行更改。

2. 帖子何时会被“重新翻译”?
一些论坛帖子会经常编辑。我该如何确保每一次修正的拼写错误都不会导致高昂的翻译费用?此外,我该如何确保新的更改能够准确地更新到翻译中?

3 个赞

我认为这可能不可行,因为您需要修改供应商(Microsoft/Google)的级别。除非翻译的内容受到单词替换功能的影响,否则您可以使用它。

不过,这里有一个功能请求

  1. 如果第一篇帖子不是英文,则自动将其翻译成英文。
  2. 提供一个按钮,可以一次性翻译整个帖子。
  3. 在用户级别为整个论坛启用自动翻译功能。也就是说,如果用户在其个人资料中选择他们只说罗马尼亚语,那么所有内容都将翻译成罗马尼亚语。如果他们选择说多种语言,则仅在帖子不是用这些语言撰写时才进行翻译。
2 个赞

作为网站管理员,我看到这个感到很惊讶:

这个隐藏的设置在哪里? :smiling_face_with_sunglasses:

1 个赞
./launcher enter app
rails c
SiteSetting.automatic_translation_backfill_rate = <wanted value>
exit
exit

但我认为在更新的版本中,它可能已经不存在了。

2 个赞

你是怎么学会这些的? :sweat_smile: 好的,谢谢!我会等团队的答复,以确保。

1 个赞

两种方式:使用搜索和 ask.discourse.com

3 个赞
3 个赞

标题为“已翻译主题”的通知似乎未在通知栏中翻译:

1 个赞

我的帖子也被错误地翻译成了另一种语言,通过一个链接?


在编辑器中查看,这是我实际写的内容:

我注意到翻译时 oneboxing 也不起作用。

1 个赞

您截图中的通知使用了您帖子主题的原始标题,因此目前它是“正确”的。我们将在未来确保通知(主题标题)被翻译。

至于上面的帖子,我们的机器翻译出现了问题,它被错误地检测为“西班牙语 (es)”,并且随后出现了错误的翻译。现在已经纠正。我们正在通过更好的翻译提示进行迭代。

2 个赞

我在安装 discourse-translator 插件时遇到了此错误。我的 discourse 版本是 3.5.0.beta1。

I, [2025-04-24T01:33:20.510994 #1]  INFO -- : cd /var/www/discourse & su discourse -c 'bundle exec rake db:migrate'
        82: from /usr/local/bin/bundle:25:in `<main>'
        81: from /usr/local/bin/bundle:25:in `load'
        80: from /usr/local/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/exe/bundle:20:in `<top (required)>'
     ....
        10: from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/lazy_load_hooks.rb:87:in `with_execution_control'
        9: from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/lazy_load_hooks.rb:94:in `block in execute_hook'
        8: from /var/www/discourse/config/application.rb:249:in `block in <class:Application>'
        7: from /var/www/discourse/lib/plugin.rb:6:in `initialization_guard'
        6: from /var/www/discourse/config/application.rb:249:in `block (2 levels) in <class:Application>'
        5: from /var/www/discourse/config/application.rb:249:in `each'
        4: from /var/www/discourse/lib/plugin/instance.rb:629:in `notify_after_initialize'
        3: from /var/www/discourse/lib/plugin/instance.rb:629:in `each'
        2: from /var/www/discourse/lib/plugin/instance.rb:631:in `block in notify_after_initialize'
        1: from /var/www/discourse/plugins/discourse-translator/plugin.rb:40:in `block in activate!'
/var/www/discourse/plugins/discourse-translator/lib/discourse_translator/inline_translation.rb:86:in `inject': protected method `register_topic_preloader_associations' called for an instance of Plugin::Instance (NoMethodError)

如何修复?

1 个赞

您好,可以通过在安装插件前先更新Discourse来减轻错误。

方法register_topic_preloader_associations已从受保护状态提升为公共状态。

4 个赞

谢谢,升级 Discourse 到最新版本后我成功安装了。

2 个赞