diff --git a/languages.py b/languages.py index 83f8a31a4..3eb436ad2 100644 --- a/languages.py +++ b/languages.py @@ -61,8 +61,11 @@ def setActorLanguages(baseDir: str, actorJson: {}, languagesStr: str) -> None: langList2 = [] for lang in langList: lang = lang.strip() - languageFilename = baseDir + '/translations/' + lang + '.json' - if os.path.isfile(languageFilename): + if baseDir: + languageFilename = baseDir + '/translations/' + lang + '.json' + if os.path.isfile(languageFilename): + langList2.append(lang) + else: langList2.append(lang) # remove any existing value diff --git a/tests.py b/tests.py index baf303151..ed98ad64d 100644 --- a/tests.py +++ b/tests.py @@ -123,6 +123,7 @@ from mastoapiv1 import getNicknameFromMastoApiV1Id from webapp_post import prepareHtmlPostNickname from speaker import speakerReplaceLinks from markdown import markdownToHtml +from languages import setActorLanguages testServerAliceRunning = False testServerBobRunning = False @@ -4207,9 +4208,26 @@ def _testLimitRepetedWords() -> None: assert result == expected +def _testSetActorLanguages(): + print('testSetActorLanguages') + actorJson = { + "attachment": [] + } + setActorLanguages(None, actorJson, 'en, es, fr') + print(str(actorJson)) + assert len(actorJson['attachment']) == 1 + assert actorJson['attachment'][0]['name'] == 'Languages' + assert actorJson['attachment'][0]['type'] == 'PropertyValue' + assert len(actorJson['attachment'][0]['value']) == 3 + assert 'en' in actorJson['attachment'][0]['value'] + assert 'fr' in actorJson['attachment'][0]['value'] + assert 'es' in actorJson['attachment'][0]['value'] + + def runAllTests(): print('Running tests...') updateDefaultThemesList(os.getcwd()) + _testSetActorLanguages() _testLimitRepetedWords() _testLimitWordLengths() _testSwitchWords()