Add translated texts
This commit is contained in:
parent
5e872b7288
commit
7c438f8e78
2 changed files with 51 additions and 28 deletions
|
@ -172,34 +172,6 @@ class MastodonEmailBridge:
|
||||||
next_url = slink[0].replace('<', '').replace('>', '')
|
next_url = slink[0].replace('<', '').replace('>', '')
|
||||||
return next_url
|
return next_url
|
||||||
|
|
||||||
def _translate_data(self, data):
|
|
||||||
if self.config['libretranslate_url'] is None or self.config['libretranslate_url'] == '':
|
|
||||||
self._log.debug(
|
|
||||||
"Not translating data because no LibreTranslate URL was specified"
|
|
||||||
)
|
|
||||||
return data
|
|
||||||
new_data = data
|
|
||||||
if (
|
|
||||||
'language' not in data or
|
|
||||||
data['language'] is None
|
|
||||||
):
|
|
||||||
source_language = 'auto'
|
|
||||||
else:
|
|
||||||
source_language = data['language']
|
|
||||||
if source_language in self.config['not_translate_language']:
|
|
||||||
return data
|
|
||||||
fields_to_translate = [
|
|
||||||
'spoiler',
|
|
||||||
'content'
|
|
||||||
]
|
|
||||||
for field in fields_to_translate:
|
|
||||||
if field in data:
|
|
||||||
new_data[f"translated_{field}"] = self._translate(
|
|
||||||
data[field],
|
|
||||||
source_language=source_language
|
|
||||||
)
|
|
||||||
return new_data
|
|
||||||
|
|
||||||
def get_post(self, post_id):
|
def get_post(self, post_id):
|
||||||
'''Get a single post'''
|
'''Get a single post'''
|
||||||
post = {}
|
post = {}
|
||||||
|
@ -273,6 +245,34 @@ class MastodonEmailBridge:
|
||||||
result = template.render(data=data)
|
result = template.render(data=data)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _translate_data(self, data):
|
||||||
|
if self.config['libretranslate_url'] is None or self.config['libretranslate_url'] == '':
|
||||||
|
self._log.debug(
|
||||||
|
"Not translating data because no LibreTranslate URL was specified"
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
new_data = data
|
||||||
|
if (
|
||||||
|
'language' not in data or
|
||||||
|
data['language'] is None
|
||||||
|
):
|
||||||
|
source_language = 'auto'
|
||||||
|
else:
|
||||||
|
source_language = data['language']
|
||||||
|
if source_language in self.config['not_translate_language']:
|
||||||
|
return data
|
||||||
|
fields_to_translate = [
|
||||||
|
'spoiler',
|
||||||
|
'content'
|
||||||
|
]
|
||||||
|
for field in fields_to_translate:
|
||||||
|
if field in data:
|
||||||
|
new_data[f"translated_{field}"] = self._translate(
|
||||||
|
data[field],
|
||||||
|
source_language=source_language
|
||||||
|
)
|
||||||
|
return new_data
|
||||||
|
|
||||||
def _translate(self, text, source_language='auto', destination_language=None):
|
def _translate(self, text, source_language='auto', destination_language=None):
|
||||||
if text == '':
|
if text == '':
|
||||||
return ''
|
return ''
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<BODY>
|
<BODY>
|
||||||
|
Language {{ data['language'] }}
|
||||||
{% if data['url'] != "" %}
|
{% if data['url'] != "" %}
|
||||||
<!-- URL -->
|
<!-- URL -->
|
||||||
<A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
|
<A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
|
||||||
|
@ -58,12 +59,20 @@
|
||||||
<DIV STYLE='font-size: 24px;'>
|
<DIV STYLE='font-size: 24px;'>
|
||||||
{% if data['spoiler'] != "" and data['spoiler'] != null %}
|
{% if data['spoiler'] != "" and data['spoiler'] != null %}
|
||||||
<!-- spoiler -->
|
<!-- spoiler -->
|
||||||
|
{% if data['translated_spoiler'] != "" and data['translated_spoiler'] != null %}
|
||||||
|
<DIV CLASS='item-spoiler'>
|
||||||
|
{{ data['translated_spoiler'] }}
|
||||||
|
</DIV>
|
||||||
|
{% endif %}
|
||||||
<DIV CLASS='item-spoiler'>
|
<DIV CLASS='item-spoiler'>
|
||||||
{{ data['spoiler'] }}
|
{{ data['spoiler'] }}
|
||||||
</DIV>
|
</DIV>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- item-content -->
|
<!-- item-content -->
|
||||||
<DIV CLASS='item-content' STYLE="margin:0.5%;background-color:#111;padding:0.5%;">
|
<DIV CLASS='item-content' STYLE="margin:0.5%;background-color:#111;padding:0.5%;">
|
||||||
|
{% if data['translated_content'] != '' and data['translated_content'] != null %}
|
||||||
|
{{ data['translated_content'] }}
|
||||||
|
{% endif %}
|
||||||
{{ data['content'] }}
|
{{ data['content'] }}
|
||||||
<!-- media -->
|
<!-- media -->
|
||||||
{% if data['media_attachments'] %}
|
{% if data['media_attachments'] %}
|
||||||
|
@ -113,10 +122,16 @@
|
||||||
<DIV STYLE='font-size: 24px;'>
|
<DIV STYLE='font-size: 24px;'>
|
||||||
<!-- reply_spoiler -->
|
<!-- reply_spoiler -->
|
||||||
<DIV CLASS='reply-spoiler'>
|
<DIV CLASS='reply-spoiler'>
|
||||||
|
{% if reply['translated_spoiler'] != '' and reply['translated_spoiler'] != null %}
|
||||||
|
{{ reply['translated_spoiler'] }}
|
||||||
|
{% endif %}
|
||||||
{{ reply['spoiler'] }}
|
{{ reply['spoiler'] }}
|
||||||
</DIV>
|
</DIV>
|
||||||
<!-- reply_content -->
|
<!-- reply_content -->
|
||||||
<DIV CLASS='reply-content'>
|
<DIV CLASS='reply-content'>
|
||||||
|
{% if reply['translated_content'] != '' and reply['translated_content'] != null %}
|
||||||
|
{{ reply['translated_content'] }}
|
||||||
|
{% endif %}
|
||||||
{{ reply['content'] }}
|
{{ reply['content'] }}
|
||||||
<!-- media -->
|
<!-- media -->
|
||||||
{% if reply['media_attachments'] %}
|
{% if reply['media_attachments'] %}
|
||||||
|
@ -169,11 +184,19 @@
|
||||||
<!-- reblog_content_bloc -->
|
<!-- reblog_content_bloc -->
|
||||||
<DIV STYLE='font-size: 24px;'>
|
<DIV STYLE='font-size: 24px;'>
|
||||||
<!-- reblog_spoiler -->
|
<!-- reblog_spoiler -->
|
||||||
|
{% if data['reblog']['translated_spoiler'] != '' and data['reblog']['translated_spoiler'] != null %}
|
||||||
|
<DIV CLASS='reblog-spoiler'>
|
||||||
|
{{ data['reblog']['translated_spoiler'] }}
|
||||||
|
</DIV>
|
||||||
|
{% endif %}
|
||||||
<DIV CLASS='reblog-spoiler'>
|
<DIV CLASS='reblog-spoiler'>
|
||||||
{{ data['reblog']['spoiler'] }}
|
{{ data['reblog']['spoiler'] }}
|
||||||
</DIV>
|
</DIV>
|
||||||
<!-- reblog_content -->
|
<!-- reblog_content -->
|
||||||
<DIV CLASS='reblog-content'>
|
<DIV CLASS='reblog-content'>
|
||||||
|
{% if data['reblog']['translated_content'] != '' and data['reblog']['translated_content'] != null %}
|
||||||
|
{{ data['reblog']['translated_content'] }}
|
||||||
|
{% endif %}
|
||||||
{{ data['reblog']['content'] }}
|
{{ data['reblog']['content'] }}
|
||||||
<!-- media -->
|
<!-- media -->
|
||||||
{% if data['reblog']['media_attachments'] %}
|
{% if data['reblog']['media_attachments'] %}
|
||||||
|
|
Loading…
Reference in a new issue