Skip to content

Commit

Permalink
[IMP] base: do not set a value for new translations
Browse files Browse the repository at this point in the history
When generating new translations (e.g. 'edit translations' button on a view or
on a translatable field), the new generated translations have the source as
translation value.

Set the state to 'to_translate' as it is the default value

This change requires to add a fallback in web_editor when computing translated
dom

When a translation has no value, there is a fallback done in the different
translation method (e.g. xml_translate) but, as the node was manually created
in edit_translation_mapping, the fallback was missing

closes #24391
  • Loading branch information
mart-e committed Sep 4, 2018
1 parent 5a53e5b commit d65969d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion addons/web_editor/models/ir_translation.py
Expand Up @@ -8,7 +8,7 @@


def edit_translation_mapping(data):
data = dict(data, model=data['name'].partition(',')[0])
data = dict(data, model=data['name'].partition(',')[0], value=data['value'] or data['src'])
return '<span data-oe-model="%(model)s" data-oe-translation-id="%(id)s" data-oe-translation-state="%(state)s">%(value)s</span>' % data


Expand Down
8 changes: 4 additions & 4 deletions odoo/addons/base/models/ir_translation.py
Expand Up @@ -590,8 +590,8 @@ def insert_missing(self, field, records):
external_ids = records.get_external_id() # if no xml_id, empty string
if callable(field.translate):
# insert missing translations for each term in src
query = """ INSERT INTO ir_translation (lang, type, name, res_id, src, value, module)
SELECT l.code, 'model', %(name)s, %(res_id)s, %(src)s, %(src)s, %(module)s
query = """ INSERT INTO ir_translation (lang, type, name, res_id, src, module, state)
SELECT l.code, 'model', %(name)s, %(res_id)s, %(src)s, %(module)s, 'to_translate'
FROM res_lang l
WHERE l.active AND l.translatable AND NOT EXISTS (
SELECT 1 FROM ir_translation
Expand All @@ -610,8 +610,8 @@ def insert_missing(self, field, records):
})
else:
# insert missing translations for src
query = """ INSERT INTO ir_translation (lang, type, name, res_id, src, value, module)
SELECT l.code, 'model', %(name)s, %(res_id)s, %(src)s, %(src)s, %(module)s
query = """ INSERT INTO ir_translation (lang, type, name, res_id, src, module, state)
SELECT l.code, 'model', %(name)s, %(res_id)s, %(src)s, %(module)s, 'to_translate'
FROM res_lang l
WHERE l.active AND l.translatable AND l.code != 'en_US' AND NOT EXISTS (
SELECT 1 FROM ir_translation
Expand Down

0 comments on commit d65969d

Please sign in to comment.