This commit introduces a new optional feature in the chatter. Users can request translation from the Google Cloud Translation API. Documentation: <https://cloud.google.com/translate/docs#docs> Adding the key in settings will instantly enable the feature for all users of the database and consumption is not measured nor limited by Odoo as it is natively supported using the Google Cloud Console. Translation values are stored in the database to reduce cost as much as possible. Therefore, translation values are automatically garbage collected every 2 weeks to prevent database pollution. Task-3338165 closes odoo/odoo#126555 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class MessageTranslation(models.Model):
|
|
_name = "mail.message.translation"
|
|
_description = "Message Translation"
|
|
|
|
message_id = fields.Many2one("mail.message", "Message", required=True, ondelete="cascade")
|
|
source_lang = fields.Char(
|
|
"Source Language", required=True, help="Result of the language detection based on its content."
|
|
)
|
|
target_lang = fields.Char(
|
|
"Target Language", required=True, help="Shortened language code used as the target for the translation request."
|
|
)
|
|
body = fields.Html(
|
|
"Translation Body", required=True, sanitize_style=True, help="String received from the translation request."
|
|
)
|
|
create_date = fields.Datetime(index=True)
|
|
|
|
def init(self):
|
|
self.env.cr.execute(
|
|
f"CREATE UNIQUE INDEX IF NOT EXISTS mail_message_translation_unique ON {self._table} (message_id, target_lang)"
|
|
)
|
|
|
|
@api.autovacuum
|
|
def _gc_translations(self):
|
|
treshold = fields.Datetime().now() - relativedelta(weeks=2)
|
|
self.search([("create_date", "<", treshold)]).unlink()
|