Snake case

main
Bob Mottram 2021-12-26 10:35:37 +00:00
parent 164393cd3d
commit 8d259d25a0
4 changed files with 45 additions and 45 deletions

View File

@ -21,11 +21,11 @@ from cache import getPersonFromCache
def getActorLanguages(actor_json: {}) -> str:
"""Returns a string containing languages used by the given actor
"""
langList = get_actor_languages_list(actor_json)
if not langList:
lang_list = get_actor_languages_list(actor_json)
if not lang_list:
return ''
languagesStr = ''
for lang in langList:
for lang in lang_list:
if languagesStr:
languagesStr += ' / ' + lang
else:
@ -48,22 +48,22 @@ def setActorLanguages(base_dir: str, actor_json: {},
separator = '+'
elif ' ' in languagesStr:
separator = ' '
langList = languagesStr.lower().split(separator)
langList2 = ''
for lang in langList:
lang_list = languagesStr.lower().split(separator)
lang_list2 = ''
for lang in lang_list:
lang = lang.strip()
if base_dir:
languageFilename = base_dir + '/translations/' + lang + '.json'
if os.path.isfile(languageFilename):
if langList2:
langList2 += ', ' + lang.strip()
if lang_list2:
lang_list2 += ', ' + lang.strip()
else:
langList2 += lang.strip()
lang_list2 += lang.strip()
else:
if langList2:
langList2 += ', ' + lang.strip()
if lang_list2:
lang_list2 += ', ' + lang.strip()
else:
langList2 += lang.strip()
lang_list2 += lang.strip()
# remove any existing value
propertyFound = None
@ -79,13 +79,13 @@ def setActorLanguages(base_dir: str, actor_json: {},
if propertyFound:
actor_json['attachment'].remove(propertyFound)
if not langList2:
if not lang_list2:
return
newLanguages = {
"name": "Languages",
"type": "PropertyValue",
"value": langList2
"value": lang_list2
}
actor_json['attachment'].append(newLanguages)
@ -121,9 +121,9 @@ def understoodPostLanguage(base_dir: str, nickname: str, domain: str,
libretranslateUrl = getConfigParam(base_dir, "libretranslateUrl")
if libretranslateUrl:
libretranslateApiKey = getConfigParam(base_dir, "libretranslateApiKey")
langList = \
lang_list = \
libretranslateLanguages(libretranslateUrl, libretranslateApiKey)
for lang in langList:
for lang in lang_list:
if msgObject['contentMap'].get(lang):
return True
return False
@ -159,7 +159,7 @@ def libretranslateLanguages(url: str, apiKey: str = None) -> []:
if not isinstance(result, list):
return []
langList = []
lang_list = []
for lang in result:
if not isinstance(lang, dict):
continue
@ -168,9 +168,9 @@ def libretranslateLanguages(url: str, apiKey: str = None) -> []:
langCode = lang['code']
if len(langCode) != 2:
continue
langList.append(langCode)
langList.sort()
return langList
lang_list.append(langCode)
lang_list.sort()
return lang_list
def getLinksFromContent(content: str) -> {}:
@ -291,9 +291,9 @@ def autoTranslatePost(base_dir: str, post_json_object: {},
if not libretranslateUrl:
return ''
libretranslateApiKey = getConfigParam(base_dir, "libretranslateApiKey")
langList = \
lang_list = \
libretranslateLanguages(libretranslateUrl, libretranslateApiKey)
for lang in langList:
for lang in lang_list:
if msgObject['contentMap'].get(lang):
content = msgObject['contentMap'][lang]
translatedText = \

View File

@ -5595,10 +5595,10 @@ def _testSetActorLanguages():
assert actor_json['attachment'][0]['type'] == 'PropertyValue'
assert isinstance(actor_json['attachment'][0]['value'], str)
assert ',' in actor_json['attachment'][0]['value']
langList = get_actor_languages_list(actor_json)
assert 'en' in langList
assert 'fr' in langList
assert 'es' in langList
lang_list = get_actor_languages_list(actor_json)
assert 'en' in lang_list
assert 'fr' in lang_list
assert 'es' in lang_list
languagesStr = getActorLanguages(actor_json)
assert languagesStr == 'en / es / fr'

View File

@ -51,29 +51,29 @@ def get_actor_languages_list(actor_json: {}) -> []:
if property_value['type'] != 'PropertyValue':
continue
if isinstance(property_value['value'], list):
langList = property_value['value']
langList.sort()
return langList
lang_list = property_value['value']
lang_list.sort()
return lang_list
elif isinstance(property_value['value'], str):
langStr = property_value['value']
langListTemp = []
lang_listTemp = []
if ',' in langStr:
langListTemp = langStr.split(',')
lang_listTemp = langStr.split(',')
elif ';' in langStr:
langListTemp = langStr.split(';')
lang_listTemp = langStr.split(';')
elif '/' in langStr:
langListTemp = langStr.split('/')
lang_listTemp = langStr.split('/')
elif '+' in langStr:
langListTemp = langStr.split('+')
lang_listTemp = langStr.split('+')
elif ' ' in langStr:
langListTemp = langStr.split(' ')
langList = []
for lang in langListTemp:
lang_listTemp = langStr.split(' ')
lang_list = []
for lang in lang_listTemp:
lang = lang.strip()
if lang not in langList:
langList.append(lang)
langList.sort()
return langList
if lang not in lang_list:
lang_list.append(lang)
lang_list.sort()
return lang_list
return []

View File

@ -1970,12 +1970,12 @@ def _htmlEditProfileOptions(isAdmin: bool,
def _getSupportedLanguagesSorted(base_dir: str) -> str:
"""Returns a list of supported languages
"""
langList = getSupportedLanguages(base_dir)
if not langList:
lang_list = getSupportedLanguages(base_dir)
if not lang_list:
return ''
langList.sort()
lang_list.sort()
languagesStr = ''
for lang in langList:
for lang in lang_list:
if languagesStr:
languagesStr += ' / ' + lang
else: