[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) <tde@openerp.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--Terms to translate for the outlook plugin -->
|
||||
<ressources>
|
||||
<string>Log Email Into Lead</string>
|
||||
<string>Opportunities</string>
|
||||
<string>Opportunities (%(count)s)</string>
|
||||
<string>%(expected_revenue)s at %(probability)s%</string>
|
||||
<string>%(expected_revenue)s + %(recurring_revenue)s %(recurring_plan)s at %(probability)s%</string>
|
||||
<string>Save Contact to create new Opportunities.</string>
|
||||
<string>No opportunities found for this contact.</string>
|
||||
</ressources>
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--Terms to translate for the outlook plugin.
|
||||
Only named string params e.g: %(param)s are supported by the plugins,
|
||||
unnamed params like %s are not supported.-->
|
||||
<resources>
|
||||
<string>Logout</string>
|
||||
<string>Company created</string>
|
||||
<string>Company Insights</string>
|
||||
<string>Revenues</string>
|
||||
<string>Company Type</string>
|
||||
<string>Keywords</string>
|
||||
<string>Year founded</string>
|
||||
<string>Employees</string>
|
||||
<string>Industry</string>
|
||||
<string>Website</string>
|
||||
<string>Phone</string>
|
||||
<string>Address</string>
|
||||
<string>Contact created</string>
|
||||
<string>Buy More</string>
|
||||
<string>Search In Odoo</string>
|
||||
<string>Search In Database</string>
|
||||
<string>Contacts Found (%(count)s)</string>
|
||||
<string>Search contact in Odoo...</string>
|
||||
<string>Refresh Contact</string>
|
||||
<string>Add Contact To Database</string>
|
||||
<string>Contact Details</string>
|
||||
<string>Log Email Into Contact</string>
|
||||
<string>This contact has no email address, no company could be enriched</string>
|
||||
<string>No company attached to this contact</string>
|
||||
<string>Create a Company</string>
|
||||
<string>No company linked to this contact could be enriched</string>
|
||||
<string>No company linked to this contact could be enriched or found in Odoo</string>
|
||||
<string>No data found for this email address.</string>
|
||||
<string>You don't have enough credit to enrich.</string>
|
||||
<string>Something bad happened. Please, try again later.</string>
|
||||
<string>Could not autocomplete the company. Internal error. Try again later...</string>
|
||||
<string>There was a problem contacting the service, please try again later.</string>
|
||||
<string>An error has occurred when trying to fetch translations.</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user