Setting permitted post languages on edit profile screen

main
Bob Mottram 2021-07-18 19:02:36 +01:00
parent 50096bff11
commit c0a3dd459b
20 changed files with 157 additions and 19 deletions

View File

@ -50,6 +50,8 @@ from matrix import getMatrixAddress
from matrix import setMatrixAddress from matrix import setMatrixAddress
from donate import getDonationUrl from donate import getDonationUrl
from donate import setDonationUrl from donate import setDonationUrl
from person import getActorLanguages
from person import setActorLanguages
from person import setPersonNotes from person import setPersonNotes
from person import getDefaultPersonContext from person import getDefaultPersonContext
from person import savePersonQrcode from person import savePersonQrcode
@ -4515,6 +4517,18 @@ class PubServer(BaseHTTPRequestHandler):
setBlogAddress(actorJson, '') setBlogAddress(actorJson, '')
actorChanged = True actorChanged = True
# change Languages address
currentShowLanguages = getActorLanguages(actorJson)
if fields.get('showLanguages'):
if fields['showLanguages'] != currentShowLanguages:
setActorLanguages(baseDir, actorJson,
fields['showLanguages'])
actorChanged = True
else:
if currentShowLanguages:
setActorLanguages(baseDir, actorJson, '')
actorChanged = True
# change tox address # change tox address
currentToxAddress = getToxAddress(actorJson) currentToxAddress = getToxAddress(actorJson)
if fields.get('toxAddress'): if fields.get('toxAddress'):

View File

@ -1353,3 +1353,79 @@ def getPersonAvatarUrl(baseDir: str, personUrl: str, personCache: {},
if personJson['icon'].get('url'): if personJson['icon'].get('url'):
return personJson['icon']['url'] return personJson['icon']['url']
return None return None
def _getActorLanguagesList(actorJson: {}) -> []:
"""Returns a list containing languages used by the given actor
"""
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue['name'].lower().startswith('languages'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue.get('value'):
continue
if not isinstance(propertyValue['value'], list):
continue
if propertyValue['type'] != 'PropertyValue':
continue
return propertyValue['value']
return []
def getActorLanguages(actorJson: {}) -> str:
"""Returns a string containing languages used by the given actor
"""
langList = _getActorLanguagesList(actorJson)
if not langList:
return ''
languagesStr = ''
for lang in languagesStr:
if languagesStr:
languagesStr += ' / ' + lang
else:
languagesStr = lang
return languagesStr
def setActorLanguages(baseDir: str, actorJson: {}, languagesStr: str) -> None:
"""Sets the languages used by the given actor
"""
separator = ','
if '/' in languagesStr:
separator = '/'
elif ';' in languagesStr:
separator = ';'
langList = languagesStr.lower().split(separator)
langList2 = []
for lang in langList:
lang = lang.strip()
languageFilename = baseDir + '/translations/' + lang + '.json'
if os.path.isfile(languageFilename):
langList2.append(lang)
# remove any existing value
propertyFound = None
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('languages'):
continue
propertyFound = propertyValue
break
if propertyFound:
actorJson['attachment'].remove(propertyFound)
if not langList2:
return
newLanguages = {
"name": "Languages",
"type": "PropertyValue",
"value": langList2
}
actorJson['attachment'].append(newLanguages)

View File

@ -450,5 +450,6 @@
"Export Theme": "موضوع التصدير", "Export Theme": "موضوع التصدير",
"Custom post submit button text": "عرف نشر إرسال نص زر", "Custom post submit button text": "عرف نشر إرسال نص زر",
"Blocked User Agents": "عوامل المستخدم المحظورة", "Blocked User Agents": "عوامل المستخدم المحظورة",
"Notify me when this account posts": "أعلمني عندما ينشر الحساب هذا" "Notify me when this account posts": "أعلمني عندما ينشر الحساب هذا",
"Languages": "اللغات"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Tema d'exportació", "Export Theme": "Tema d'exportació",
"Custom post submit button text": "Text de botó d'enviament de publicacions personalitzades", "Custom post submit button text": "Text de botó d'enviament de publicacions personalitzades",
"Blocked User Agents": "Agents d'usuari bloquejats", "Blocked User Agents": "Agents d'usuari bloquejats",
"Notify me when this account posts": "Aviseu-me quan publiqui aquest compte" "Notify me when this account posts": "Aviseu-me quan publiqui aquest compte",
"Languages": "Idiomes"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Thema Allforio", "Export Theme": "Thema Allforio",
"Custom post submit button text": "Testun Post Post Post", "Custom post submit button text": "Testun Post Post Post",
"Blocked User Agents": "Asiantau defnyddwyr wedi'u blocio", "Blocked User Agents": "Asiantau defnyddwyr wedi'u blocio",
"Notify me when this account posts": "Rhoi gwybod i mi pan fydd y cyfrifon cyfrif hwn" "Notify me when this account posts": "Rhoi gwybod i mi pan fydd y cyfrifon cyfrif hwn",
"Languages": "Ieithoedd"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Theme exportieren", "Export Theme": "Theme exportieren",
"Custom post submit button text": "Benutzerdefinierte Post-Senden Schaltfläche Text", "Custom post submit button text": "Benutzerdefinierte Post-Senden Schaltfläche Text",
"Blocked User Agents": "Blockierte Benutzeragenten", "Blocked User Agents": "Blockierte Benutzeragenten",
"Notify me when this account posts": "Benachrichtigen Sie mich, wenn dieses Konto postet" "Notify me when this account posts": "Benachrichtigen Sie mich, wenn dieses Konto postet",
"Languages": "Sprachen"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Export Theme", "Export Theme": "Export Theme",
"Custom post submit button text": "Custom post submit button text", "Custom post submit button text": "Custom post submit button text",
"Blocked User Agents": "Blocked User Agents", "Blocked User Agents": "Blocked User Agents",
"Notify me when this account posts": "Notify me when this account posts" "Notify me when this account posts": "Notify me when this account posts",
"Languages": "Languages"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Tema de exportación", "Export Theme": "Tema de exportación",
"Custom post submit button text": "POST POST PERSONALIZADO Botón Texto", "Custom post submit button text": "POST POST PERSONALIZADO Botón Texto",
"Blocked User Agents": "Agentes de usuario bloqueados", "Blocked User Agents": "Agentes de usuario bloqueados",
"Notify me when this account posts": "Notifíqueme cuando se publique esta cuenta" "Notify me when this account posts": "Notifíqueme cuando se publique esta cuenta",
"Languages": "Idiomas"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Thème d'exportation", "Export Theme": "Thème d'exportation",
"Custom post submit button text": "Texte de bouton d'envoi postal personnalisé", "Custom post submit button text": "Texte de bouton d'envoi postal personnalisé",
"Blocked User Agents": "Agents d'utilisateur bloqués", "Blocked User Agents": "Agents d'utilisateur bloqués",
"Notify me when this account posts": "Avertissez-moi quand ce compte publie" "Notify me when this account posts": "Avertissez-moi quand ce compte publie",
"Languages": "Langues"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Téama Easpórtála", "Export Theme": "Téama Easpórtála",
"Custom post submit button text": "Post saincheaptha Cuir isteach an cnaipe Téacs", "Custom post submit button text": "Post saincheaptha Cuir isteach an cnaipe Téacs",
"Blocked User Agents": "Gníomhairí úsáideora blocáilte", "Blocked User Agents": "Gníomhairí úsáideora blocáilte",
"Notify me when this account posts": "Cuir in iúl dom nuair a phostófar an cuntas seo" "Notify me when this account posts": "Cuir in iúl dom nuair a phostófar an cuntas seo",
"Languages": "Teangacha"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "निर्यात विषय", "Export Theme": "निर्यात विषय",
"Custom post submit button text": "कस्टम पोस्ट सबमिट बटन टेक्स्ट", "Custom post submit button text": "कस्टम पोस्ट सबमिट बटन टेक्स्ट",
"Blocked User Agents": "अवरुद्ध उपयोगकर्ता एजेंट", "Blocked User Agents": "अवरुद्ध उपयोगकर्ता एजेंट",
"Notify me when this account posts": "यह खाता पोस्ट होने पर मुझे सूचित करें" "Notify me when this account posts": "यह खाता पोस्ट होने पर मुझे सूचित करें",
"Languages": "बोली"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Esportare tema", "Export Theme": "Esportare tema",
"Custom post submit button text": "Pulsante di invio del post personalizzato", "Custom post submit button text": "Pulsante di invio del post personalizzato",
"Blocked User Agents": "Agenti utente bloccati", "Blocked User Agents": "Agenti utente bloccati",
"Notify me when this account posts": "Avvisami quando questo account messaggi" "Notify me when this account posts": "Avvisami quando questo account messaggi",
"Languages": "Le lingue"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "テーマをエクスポートします", "Export Theme": "テーマをエクスポートします",
"Custom post submit button text": "カスタムポスト送信ボタンテキスト", "Custom post submit button text": "カスタムポスト送信ボタンテキスト",
"Blocked User Agents": "ブロックされたユーザーエージェント", "Blocked User Agents": "ブロックされたユーザーエージェント",
"Notify me when this account posts": "この口座投稿を通知する" "Notify me when this account posts": "この口座投稿を通知する",
"Languages": "言語"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Mijara Export", "Export Theme": "Mijara Export",
"Custom post submit button text": "Nivîsa bişkojka paşîn a paşîn", "Custom post submit button text": "Nivîsa bişkojka paşîn a paşîn",
"Blocked User Agents": "Karmendên bikarhêner asteng kirin", "Blocked User Agents": "Karmendên bikarhêner asteng kirin",
"Notify me when this account posts": "Dema ku ev postên hesabê min agahdar bikin" "Notify me when this account posts": "Dema ku ev postên hesabê min agahdar bikin",
"Languages": "Ziman"
} }

View File

@ -446,5 +446,6 @@
"Export Theme": "Export Theme", "Export Theme": "Export Theme",
"Custom post submit button text": "Custom post submit button text", "Custom post submit button text": "Custom post submit button text",
"Blocked User Agents": "Blocked User Agents", "Blocked User Agents": "Blocked User Agents",
"Notify me when this account posts": "Notify me when this account posts" "Notify me when this account posts": "Notify me when this account posts",
"Languages": "Languages"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Exportar tema", "Export Theme": "Exportar tema",
"Custom post submit button text": "Texto de botão de envio de post personalizado", "Custom post submit button text": "Texto de botão de envio de post personalizado",
"Blocked User Agents": "Agentes de usuário bloqueados", "Blocked User Agents": "Agentes de usuário bloqueados",
"Notify me when this account posts": "Notifique-me quando esta conta posts" "Notify me when this account posts": "Notifique-me quando esta conta posts",
"Languages": "Línguas"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Экспортная тема", "Export Theme": "Экспортная тема",
"Custom post submit button text": "Пользовательский пост Отправить кнопку текста", "Custom post submit button text": "Пользовательский пост Отправить кнопку текста",
"Blocked User Agents": "Заблокированные пользовательские агенты", "Blocked User Agents": "Заблокированные пользовательские агенты",
"Notify me when this account posts": "Сообщите мне, когда эта учетная запись" "Notify me when this account posts": "Сообщите мне, когда эта учетная запись",
"Languages": "Языки"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "Tuma mandhari", "Export Theme": "Tuma mandhari",
"Custom post submit button text": "Ujumbe wa Desturi Wasilisha Nakala ya kifungo", "Custom post submit button text": "Ujumbe wa Desturi Wasilisha Nakala ya kifungo",
"Blocked User Agents": "Wakala wa watumiaji waliozuiwa", "Blocked User Agents": "Wakala wa watumiaji waliozuiwa",
"Notify me when this account posts": "Nijulishe wakati akaunti hii ya akaunti." "Notify me when this account posts": "Nijulishe wakati akaunti hii ya akaunti.",
"Languages": "Lugha"
} }

View File

@ -450,5 +450,6 @@
"Export Theme": "出口主题", "Export Theme": "出口主题",
"Custom post submit button text": "自定义发布提交按钮文本", "Custom post submit button text": "自定义发布提交按钮文本",
"Blocked User Agents": "阻止用户代理商", "Blocked User Agents": "阻止用户代理商",
"Notify me when this account posts": "此帐户帖子时通知我" "Notify me when this account posts": "此帐户帖子时通知我",
"Languages": "语言"
} }

View File

@ -25,6 +25,7 @@ from utils import getImageFormats
from utils import acctDir from utils import acctDir
from skills import getSkills from skills import getSkills
from theme import getThemesList from theme import getThemesList
from person import getActorLanguages
from person import personBoxJson from person import personBoxJson
from person import getActorJson from person import getActorJson
from person import getPersonAvatarUrl from person import getPersonAvatarUrl
@ -1775,7 +1776,26 @@ def _htmlEditProfileOptions(manuallyApprovesFollowers: str,
return editProfileForm return editProfileForm
def _htmlEditProfileMain(displayNickname: str, bioStr: str, def _getSupportedLanguages(baseDir: str) -> str:
"""Returns a list of supported languages
"""
languagesStr = ''
for subdir, dirs, files in os.walk(baseDir + '/translations'):
for f in files:
if not f.endswith('.json'):
continue
langStr = f.split('.')[0]
if len(langStr) != 2:
continue
if languagesStr:
languagesStr += ' / ' + langStr
else:
languagesStr = langStr
break
return languagesStr
def _htmlEditProfileMain(baseDir: str, displayNickname: str, bioStr: str,
movedTo: str, donateUrl: str, movedTo: str, donateUrl: str,
blogAddress: str, actorJson: {}, blogAddress: str, actorJson: {},
translate: {}) -> str: translate: {}) -> str:
@ -1846,6 +1866,16 @@ def _htmlEditProfileMain(displayNickname: str, bioStr: str,
' <input type="text" name="blogAddress" value="' + \ ' <input type="text" name="blogAddress" value="' + \
blogAddress + '">\n' + \ blogAddress + '">\n' + \
' </div>\n' ' </div>\n'
languagesListStr = _getSupportedLanguages(baseDir)
showLanguages = getActorLanguages(actorJson)
editProfileForm += \
'<label class="labels">' + \
translate['Languages'] + '</label><br>\n' + \
'<label class="labels">' + languagesListStr + '</label><br>\n' + \
' <input type="text" name="showLanguages" value="' + \
showLanguages + '">\n' + \
' </div>\n'
return editProfileForm return editProfileForm
@ -2038,7 +2068,8 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
# main info # main info
editProfileForm += \ editProfileForm += \
_htmlEditProfileMain(displayNickname, bioStr, movedTo, donateUrl, _htmlEditProfileMain(baseDir, displayNickname, bioStr,
movedTo, donateUrl,
blogAddress, actorJson, translate) blogAddress, actorJson, translate)
# Option checkboxes # Option checkboxes