diff --git a/frappe/core/doctype/translation/translation.py b/frappe/core/doctype/translation/translation.py index 8f43e4fd76..b2bd23ca69 100644 --- a/frappe/core/doctype/translation/translation.py +++ b/frappe/core/doctype/translation/translation.py @@ -33,23 +33,24 @@ class Translation(Document): def create_translations(translation_map, language): from frappe.frappeclient import FrappeClient - translation_map_str = translation_map - translation_map = json.loads(translation_map_str) - + translation_map = json.loads(translation_map) + translation_map_to_send = frappe._dict({}) # first create / update local user translations for source_id, translation_dict in translation_map.items(): translation_dict = frappe._dict(translation_dict) - existing_doc_name = frappe.db.exists('Translation', { + existing_doc_name = frappe.db.get_all('Translation', { 'source_text': translation_dict.source_text, - 'context': translation_dict.context, + 'context': translation_dict.context or '', 'language': language, }) + translation_map_to_send[source_id] = translation_dict if existing_doc_name: - frappe.set_values('Translation', existing_doc_name, { + frappe.db.set_value('Translation', existing_doc_name[0].name, { 'translated_text': translation_dict.translated_text, 'contributed': 1, 'contribution_status': 'Pending' }) + translation_map_to_send[source_id].name = existing_doc_name[0].name else: doc = frappe.get_doc({ 'doctype': 'Translation', @@ -61,12 +62,14 @@ def create_translations(translation_map, language): 'language': language }) doc.insert() + translation_map_to_send[source_id].name = doc.name + params = { 'language': language, 'contributor_email': frappe.session.user, 'contributor_name': frappe.utils.get_fullname(frappe.session.user), - 'translation_map': translation_map_str + 'translation_map': json.dumps(translation_map_to_send) } translator = FrappeClient(frappe.conf.translator_url)