-
-
Notifications
You must be signed in to change notification settings - Fork 589
/
ir_translation.py
102 lines (79 loc) · 3.88 KB
/
ir_translation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2015-2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2016 Stanislav Krotov <https://it-projects.info/team/ufaks>
# Copyright 2017 Ilmir Karamov <https://it-projects.info/team/ilmir-k>
# Copyright 2017 Nicolas JEUDY <https://github.com/njeudy>
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# Copyright 2018 Ildar Nasyrov <https://it-projects.info/team/iledarn>
# Copyright 2019 Eugene Molotov <https://it-projects.info/team/molotov>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import re
from odoo import api
from odoo import models
from odoo import tools
from .ir_config_parameter import get_debranding_parameters_env
def debrand_documentation_links(source, new_documentation_website):
return re.sub(r'https://www.odoo.com/documentation/',
new_documentation_website + 'documentation/',
source, flags=re.IGNORECASE)
def debrand_links(source, new_website):
return re.sub(r'\bodoo.com\b', new_website, source, flags=re.IGNORECASE)
def debrand(env, source, is_code=False):
if not source or not re.search(r'\bodoo\b', source, re.IGNORECASE):
return source
params = get_debranding_parameters_env(env)
new_name = params.get('web_debranding.new_name')
new_website = params.get('web_debranding.new_website')
new_documentation_website = params.get('web_debranding.new_documentation_website')
source = debrand_documentation_links(source, new_documentation_website)
source = debrand_links(source, new_website)
# We must exclude the next cases, which occur only in a code,
# Since JS functions are also contained in the localization files.
# Next regular expression exclude from substitution 'odoo.SMTH', 'odoo =', 'odoo=', 'odooSMTH', 'odoo['
# Where SMTH is an any symbol or number or '_'. Option odoo.com were excluded previously.
# Examples:
# odoo.
# xml file: https://github.com/odoo/odoo/blob/9.0/addons/im_livechat/views/im_livechat_channel_templates.xml#L148
# odooSMTH
# https://github.com/odoo/odoo/blob/11.0/addons/website_google_map/views/google_map_templates.xml#L14
# odoo =
# https://github.com/odoo/odoo/blob/11.0/addons/web/views/webclient_templates.xml#L260
# odoo[
# https://github.com/odoo/odoo/blob/11.0/addons/web_editor/views/iframe.xml#L43-L44
# SMTH.odoo
# https://github.com/odoo/odoo/blob/11.0/addons/web_editor/views/iframe.xml#L43
source = re.sub(r'\b(?<!\.)odoo(?!\.\S|\s?=|\w|\[)\b', new_name, source, flags=re.IGNORECASE)
return source
def debrand_bytes(env, source):
if type(source) is bytes:
source = source.decode('utf-8')
return bytes(debrand(env, source), 'utf-8')
class IrTranslation(models.Model):
_inherit = 'ir.translation'
@api.model
def _debrand_dict(self, res):
for k in res:
res[k] = self._debrand(res[k])
return res
@api.model
def _debrand(self, source):
return debrand(self.env, source)
@tools.ormcache('name', 'types', 'lang', 'source', 'res_id')
def __get_source(self, name, types, lang, source, res_id):
res = super(IrTranslation, self).__get_source(name, types, lang, source, res_id)
return self._debrand(res)
@api.model
@tools.ormcache_context('model_name', keys=('lang',))
def get_field_string(self, model_name):
res = super(IrTranslation, self).get_field_string(model_name)
return self._debrand_dict(res)
@api.model
@tools.ormcache_context('model_name', keys=('lang',))
def get_field_help(self, model_name):
res = super(IrTranslation, self).get_field_help(model_name)
return self._debrand_dict(res)
@api.model
def decorated_clear_caches(self):
"""For calling clear_caches from via xml <function ... />
we wrapped it in the api.model decorator
"""
self.clear_caches()