Skip to content

Commit 73e1889

Browse files
authored
Sw 1306 translation docs (mrbeam#1511)
* SW_1306 add exmepted translations for mr beam docs * SW_1306 add doc string and make sure parameter is a string before calling function
1 parent cc535e3 commit 73e1889

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

octoprint_mrbeam/services/document_service.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
from octoprint_mrbeam.model.document_model import DocumentLinkModel, DocumentModel, DocumentSimpleModel
44
from octoprint_mrbeam.util import string_util
55

6+
ALL_EXEMPTED = '*'
7+
EXEMPTED_TRANSLATIONS = {
8+
'en': {ALL_EXEMPTED},
9+
'de': {'Quickstart Guide'}
10+
}
11+
612

713
class DocumentService:
814
"""
@@ -41,11 +47,7 @@ def get_document_simple_for(self, definition, language):
4147
def _get_title_translated(self, definition):
4248
title_key = string_util.separate_camelcase_words(definition.mrbeamdoc_type.value)
4349
title_translated = gettext(title_key)
44-
if get_locale() is not None and get_locale().language != 'en' and title_key == title_translated:
45-
self._logger.error(
46-
'No key found for title_key=%(title_key)s title_translated=%(title_translated)s' % {
47-
'title_key': title_key,
48-
'title_translated': title_translated})
50+
self._log_error_on_missing_translation(title_key, str(title_translated))
4951
return title_translated
5052

5153
@staticmethod
@@ -55,3 +57,23 @@ def _get_url_for_definition_language(definition, language, extension='pdf'):
5557
'language': language.value,
5658
'mrbeam_type': definition.mrbeamdoc_type.value,
5759
'extension': extension}
60+
61+
def _log_error_on_missing_translation(self, translation_key, translation):
62+
"""
63+
Arguments:
64+
translation_key: str
65+
translation: str
66+
"""
67+
if get_locale() is None:
68+
self._logger.error('Trying to get Locale failed. Is Flask initialised?')
69+
return
70+
71+
exempted_translations_for_language = EXEMPTED_TRANSLATIONS.get(get_locale().language, {})
72+
is_not_exempted_key = not any(
73+
key in exempted_translations_for_language for key in [ALL_EXEMPTED, translation_key])
74+
75+
if is_not_exempted_key and translation_key == translation:
76+
self._logger.error(
77+
'No key found for translation_key=%(translation_key)s translation=%(translation)s' % {
78+
'translation_key': translation_key,
79+
'translation': translation})

0 commit comments

Comments
 (0)