Commit 7fd7a9eb authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

content_translation: delete from content_translation table if translated text is empty.

also set _p_changed=True in deletePropertyTranslation().
parent 4f5814b2
<dtml-let content_translation_dict_list="CatalogTool_getContentTranslationDictList(Base_getContentTranslationTargetObject)">
<dtml-if "content_translation_dict_list">
<dtml-let document_list="[]" delete_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(content_translation_dict_list))">
<dtml-if "content_translation_dict_list[loop_item]['translated_text']">
<dtml-call expr="document_list.append(loop_item)">
<dtml-else>
<dtml-call expr="delete_list.append(loop_item)">
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(document_list) > 0">
REPLACE INTO content_translation
VALUES
<dtml-in "content_translation_dict_list">
(<dtml-sqlvar "_['sequence-item']['uid']" type=int>,
<dtml-sqlvar "_['sequence-item']['property_name']" type=string>,
<dtml-sqlvar "_['sequence-item']['content_language']" type=string>,
<dtml-sqlvar "_['sequence-item']['translated_text']" type=string>
<dtml-in prefix="loop" expr="document_list">
(<dtml-sqlvar "content_translation_dict_list[loop_item]['uid']" type=int>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['property_name']" type=string>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['content_language']" type=string>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['translated_text']" type=string>
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>
</dtml-if>
<dtml-if expr="_.len(delete_list) > 0">
<dtml-var sql_delimiter>
DELETE FROM content_translation
WHERE
(uid, property_name, content_language) IN (<dtml-in prefix="loop" expr="delete_list">
(<dtml-sqlvar "content_translation_dict_list[loop_item]['uid']" type=int>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['property_name']" type=string>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['content_language']" type=string>
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>)
</dtml-if>
</dtml-let>
</dtml-let>
......@@ -35,19 +35,17 @@ for document in document_list:
if original_text is not None and translation_method is not None:
temporary_translated_text = translation_method(language=content_language)
if original_text != temporary_translated_text:
translated_text = temporary_translated_text
if translated_text:
temporary_result.append({'uid': uid,
'property_name': property_name,
'content_language': content_language,
'translated_text': translated_text,
})
# also add original content
if original_text is not None:
translated_text = temporary_translated_text
temporary_result.append({'uid': uid,
'property_name': property_name,
'content_language': '',
'translated_text': original_text,
'content_language': content_language,
'translated_text': translated_text,
})
# also add original content
temporary_result.append({'uid': uid,
'property_name': property_name,
'content_language': '',
'translated_text': original_text,
})
result.extend(temporary_result)
return result
......@@ -66,6 +66,7 @@ class PropertyTranslatableBuiltInDictMixIn:
def deletePropertyTranslation(self, property_id, language):
try:
del self._getTranslationDict()[(property_id, language)]
self._p_changed = True
except KeyError:
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment