From 24d5c789f1096a28f8d22158159ed3bf796c0226 Mon Sep 17 00:00:00 2001 From: nounoubensebia Date: Wed, 7 Apr 2021 08:57:15 +0000 Subject: [PATCH] [IMP] mail_plugin, crm_mail_plugin: add translation support for email plugins In mail_plugin module, add a method which returns translatable modules, this method will be overridden in the other modules to add their module names. Translations are prepared via the _prepare_translations method which uses the get_translations_for_webclient method, this way we can easily fetch translations without having to write python code. We also add xml files in "static/", these files contain terms to be translated, for each plugin we create a separate xml file so that we can easily update each plugin separately. This implementation will allow having translations handled by Odoo, which has several advantages: - existing system, nothing to develop - it will use transifex and the terms will be translated by the community - forces that mail_client implementations to have the same logic (consistency) - compared to other solutions which rely on python code to return translations, this solution is more robust as it avoids having to type the string to translate twice Task-2480075 closes odoo/odoo#69118 Ent-pr: https://github.com/odoo/enterprise/pull/17626 Plugin-pr: https://github.com/odoo/mail-client-extensions/pull/6 Related: odoo/enterprise#17626 Signed-off-by: Thibault Delavallee (tde) --- addons/crm_mail_plugin/__manifest__.py | 3 ++ .../controllers/mail_plugin.py | 3 ++ .../src/to_translate/translations_outlook.xml | 11 ++++++ addons/mail_plugin/__manifest__.py | 3 ++ addons/mail_plugin/controllers/mail_plugin.py | 23 +++++++++++ .../src/to_translate/translations_outlook.xml | 39 +++++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml create mode 100644 addons/mail_plugin/static/src/to_translate/translations_outlook.xml diff --git a/addons/crm_mail_plugin/__manifest__.py b/addons/crm_mail_plugin/__manifest__.py index aec93db3e10..9670b49eaf2 100644 --- a/addons/crm_mail_plugin/__manifest__.py +++ b/addons/crm_mail_plugin/__manifest__.py @@ -17,6 +17,9 @@ 'views/crm_mail_plugin_lead.xml', 'views/crm_lead_views.xml' ], + 'web.assets_backend': [ + 'crm_mail_plugin/static/src/to_translate/**/*', + ], 'installable': True, 'application': False, 'auto_install': True diff --git a/addons/crm_mail_plugin/controllers/mail_plugin.py b/addons/crm_mail_plugin/controllers/mail_plugin.py index de5ac25e0c0..64685c3c69f 100644 --- a/addons/crm_mail_plugin/controllers/mail_plugin.py +++ b/addons/crm_mail_plugin/controllers/mail_plugin.py @@ -61,3 +61,6 @@ class MailPluginController(mail_plugin.MailPluginController): def _mail_content_logging_models_whitelist(self): return super(MailPluginController, self)._mail_content_logging_models_whitelist() + ['crm.lead'] + + def _translation_modules_whitelist(self): + return super(MailPluginController, self)._translation_modules_whitelist() + ['crm_mail_plugin'] diff --git a/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml b/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml new file mode 100644 index 00000000000..22ce4b7c5fd --- /dev/null +++ b/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml @@ -0,0 +1,11 @@ + + + + Log Email Into Lead + Opportunities + Opportunities (%(count)s) + %(expected_revenue)s at %(probability)s% + %(expected_revenue)s + %(recurring_revenue)s %(recurring_plan)s at %(probability)s% + Save Contact to create new Opportunities. + No opportunities found for this contact. + diff --git a/addons/mail_plugin/__manifest__.py b/addons/mail_plugin/__manifest__.py index e2318644207..9f9bf11f784 100644 --- a/addons/mail_plugin/__manifest__.py +++ b/addons/mail_plugin/__manifest__.py @@ -13,6 +13,9 @@ 'contacts', 'iap' ], + 'web.assets_backend': [ + 'mail_plugin/static/src/to_translate/**/*', + ], 'data': [ 'views/mail_plugin_login.xml', 'views/res_partner_iap_views.xml', diff --git a/addons/mail_plugin/controllers/mail_plugin.py b/addons/mail_plugin/controllers/mail_plugin.py index b7f5ac83a81..608b8cddb20 100644 --- a/addons/mail_plugin/controllers/mail_plugin.py +++ b/addons/mail_plugin/controllers/mail_plugin.py @@ -165,6 +165,10 @@ class MailPluginController(http.Controller): raise Forbidden() request.env[model].browse(res_id).message_post(body=message) + @http.route('/mail_plugin/get_translations', type="json", auth="outlook", cors="*") + def get_translations(self): + return self._prepare_translations() + def _iap_enrich(self, domain): enriched_data = {} try: @@ -311,3 +315,22 @@ class MailPluginController(http.Controller): """ domain = tools.email_domain_extract(email) return ("@" + domain) if domain not in iap_tools._MAIL_DOMAIN_BLACKLIST else email + + def _translation_modules_whitelist(self): + """ + Returns the list of modules to be translated + Other mail plugin modules have to override this method to include their module names + """ + return ['mail_plugin'] + + def _prepare_translations(self): + lang = request.env['res.users'].browse(request.uid).lang + translations_per_module = request.env["ir.translation"].get_translations_for_webclient( + self._translation_modules_whitelist(), lang)[0] + translations_dict = {} + for module in self._translation_modules_whitelist(): + translations = translations_per_module.get(module, {}) + messages = translations.get('messages', {}) + for message in messages: + translations_dict.update({message['id']: message['string']}) + return translations_dict diff --git a/addons/mail_plugin/static/src/to_translate/translations_outlook.xml b/addons/mail_plugin/static/src/to_translate/translations_outlook.xml new file mode 100644 index 00000000000..9d2489ac772 --- /dev/null +++ b/addons/mail_plugin/static/src/to_translate/translations_outlook.xml @@ -0,0 +1,39 @@ + + + + Logout + Company created + Company Insights + Revenues + Company Type + Keywords + Year founded + Employees + Industry + Website + Phone + Address + Contact created + Buy More + Search In Odoo + Search In Database + Contacts Found (%(count)s) + Search contact in Odoo... + Refresh Contact + Add Contact To Database + Contact Details + Log Email Into Contact + This contact has no email address, no company could be enriched + No company attached to this contact + Create a Company + No company linked to this contact could be enriched + No company linked to this contact could be enriched or found in Odoo + No data found for this email address. + You don't have enough credit to enrich. + Something bad happened. Please, try again later. + Could not autocomplete the company. Internal error. Try again later... + There was a problem contacting the service, please try again later. + An error has occurred when trying to fetch translations. +