summaryrefslogtreecommitdiff
path: root/addons/transifex
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2017-08-09 15:15:55 +0200
committerMartin Trigaux <mat@odoo.com>2017-09-25 15:26:54 +0200
commit7e205ea6a980e4c50b9ca7c2347e1b49d71b2e48 (patch)
tree7663c25d6249ea4ee801cf2314578f04347139f9 /addons/transifex
parenteb75cb09b5edec9a5569377de7add644a3d989e8 (diff)
[ADD] transifex: integration module
Create a new module to directly find a source term on Transifex This will not make translation easier but improve the collaboration and allow easily to find a source term.
Diffstat (limited to 'addons/transifex')
-rw-r--r--addons/transifex/__init__.py4
-rw-r--r--addons/transifex/__manifest__.py28
-rw-r--r--addons/transifex/data/ir_translation_view.xml28
-rw-r--r--addons/transifex/data/transifex_data.xml9
-rw-r--r--addons/transifex/models/__init__.py4
-rw-r--r--addons/transifex/models/ir_translation.py84
-rw-r--r--addons/transifex/static/description/icon.pngbin0 -> 3279 bytes
7 files changed, 157 insertions, 0 deletions
diff --git a/addons/transifex/__init__.py b/addons/transifex/__init__.py
new file mode 100644
index 00000000000..dc5e6b693d1
--- /dev/null
+++ b/addons/transifex/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import models
diff --git a/addons/transifex/__manifest__.py b/addons/transifex/__manifest__.py
new file mode 100644
index 00000000000..98a1341bcec
--- /dev/null
+++ b/addons/transifex/__manifest__.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+{
+ 'name': 'Transifex integration',
+ 'version': '1.0',
+ 'summary': 'Add a link to edit a translation in Transifex',
+ 'category': 'Extra Tools',
+ 'description':
+ """
+Transifex integration
+=====================
+This module will add a link to the Transifex project in the translation view.
+The purpose of this module is to speed up translations of the main modules.
+
+To work, Odoo uses Transifex configuration files `.tx/config` to detec the
+project source. Custom modules will not be translated (as not published on
+the main Transifex project).
+
+The language the user tries to translate must be activated on the Transifex
+project.
+ """,
+ 'data': [
+ 'data/transifex_data.xml',
+ 'data/ir_translation_view.xml',
+ ],
+ 'depends': ['base'],
+}
diff --git a/addons/transifex/data/ir_translation_view.xml b/addons/transifex/data/ir_translation_view.xml
new file mode 100644
index 00000000000..bd6541b9567
--- /dev/null
+++ b/addons/transifex/data/ir_translation_view.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="ir_translation_view_tree_transifex" model="ir.ui.view">
+ <field name="name">ir.translation.transifex</field>
+ <field name="model">ir.translation</field>
+ <field name="inherit_id" ref="base.view_translation_tree"/>
+ <field name="arch" type="xml">
+ <field name="lang" position="after">
+ <field name="transifex_url"
+ widget="link_button"
+ string="Transifex" />
+ </field>
+ </field>
+ </record>
+
+ <record id="ir_translation_dialog_view_tree_transifex" model="ir.ui.view">
+ <field name="name">ir.translation.transifex</field>
+ <field name="model">ir.translation</field>
+ <field name="inherit_id" ref="base.view_translation_dialog_tree"/>
+ <field name="arch" type="xml">
+ <field name="lang" position="after">
+ <field name="transifex_url"
+ widget="link_button"
+ string="Transifex" />
+ </field>
+ </field>
+ </record>
+</odoo>
diff --git a/addons/transifex/data/transifex_data.xml b/addons/transifex/data/transifex_data.xml
new file mode 100644
index 00000000000..a8faefd1661
--- /dev/null
+++ b/addons/transifex/data/transifex_data.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo noupdate="1">
+
+ <record id="transifex_project_url" model="ir.config_parameter">
+ <field name="key">transifex.project_url</field>
+ <field name="value">https://www.transifex.com/odoo</field>
+ </record>
+
+</odoo>
diff --git a/addons/transifex/models/__init__.py b/addons/transifex/models/__init__.py
new file mode 100644
index 00000000000..76fec4841b3
--- /dev/null
+++ b/addons/transifex/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import ir_translation
diff --git a/addons/transifex/models/ir_translation.py b/addons/transifex/models/ir_translation.py
new file mode 100644
index 00000000000..7629ecaf835
--- /dev/null
+++ b/addons/transifex/models/ir_translation.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from configparser import ConfigParser
+from os.path import join as opj
+import os
+import werkzeug
+
+from odoo import models, fields
+from odoo.modules.module import ad_paths
+
+
+class IrTranslation(models.Model):
+
+ _inherit = 'ir.translation'
+
+ transifex_url = fields.Char("Transifex URL", compute='_get_transifex_url')
+
+ def _get_transifex_url(self):
+ """ Construct transifex URL based on the module on configuration """
+ # e.g. 'https://www.transifex.com/odoo/'
+ base_url = self.env['ir.config_parameter'].sudo().get_param('transifex.project_url')
+
+ tx_config_file = ConfigParser()
+ tx_sections = []
+ for addon_path in ad_paths:
+ tx_path = opj(addon_path, '.tx', 'config')
+ if os.path.isfile(tx_path):
+ tx_config_file.read(tx_path)
+ # first section is [main], after [odoo-11.sale]
+ tx_sections.extend(tx_config_file.sections()[1:])
+
+ # parent directory ad .tx/config is root directory in odoo/odoo
+ tx_path = opj(addon_path, os.pardir, '.tx', 'config')
+ if os.path.isfile(tx_path):
+ tx_config_file.read(tx_path)
+ tx_sections.extend(tx_config_file.sections()[1:])
+
+ if not base_url or not tx_sections:
+ self.transifex_url = False
+ else:
+ base_url = base_url.rstrip('/')
+
+ # will probably be the same for all terms, avoid multiple searches
+ translation_languages = list(set(self.mapped('lang')))
+ languages = self.env['res.lang'].with_context(active_test=False).search(
+ [('code', 'in', translation_languages)])
+
+ language_codes = dict((l.code, l.iso_code) for l in languages)
+
+ # .tx/config files contains the project reference
+ # using ini files like '[odoo-master.website_sale]'
+ translation_modules = set(self.mapped('module'))
+ project_modules = {}
+ for module in translation_modules:
+ for section in tx_sections:
+ tx_project, tx_mod = section.split('.')
+ if tx_mod == module:
+ project_modules[module] = tx_project
+
+ for translation in self:
+ if not translation.module or not translation.source or translation.lang == 'en_US':
+ # custom or source term
+ translation.transifex_url = False
+ continue
+
+ lang_code = language_codes.get(translation.lang)
+ if not lang_code:
+ translation.transifex_url = False
+ continue
+
+ project = project_modules.get(translation.module)
+ if not project:
+ translation.transifex_url = False
+ continue
+
+ # e.g. 'https://www.transifex.com/odoo/odoo-10/translate/#fr/sale/42?q=Sale+Order'
+ translation.transifex_url = "%(url)s/%(project)s/translate/#%(lang)s/%(module)s/42?q=%(src)s" % {
+ 'url': base_url,
+ 'project': project,
+ 'lang': lang_code,
+ 'module': translation.module,
+ 'src': werkzeug.url_quote_plus(translation.source[:50]),
+ }
diff --git a/addons/transifex/static/description/icon.png b/addons/transifex/static/description/icon.png
new file mode 100644
index 00000000000..9da4be521b0
--- /dev/null
+++ b/addons/transifex/static/description/icon.png
Binary files differ