fix: Translation map str

This commit is contained in:
Suraj Shetty 2020-04-02 12:45:10 +05:30
parent fc3b47f610
commit 1c8d945b33

View file

@ -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)