mirror of https://gitlab.com/openlp/openlp.git
Fix AuthorType not getting translated
This commit is contained in:
parent
9844915164
commit
e520dd5951
|
@ -392,7 +392,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
|
|||
self.author_types_combo_box.clear()
|
||||
# Don't iterate over the dictionary to give them this specific order
|
||||
for author_type in AuthorType.SortedTypes:
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[author_type], author_type)
|
||||
self.author_types_combo_box.addItem(AuthorType.get_translated_type(author_type), author_type)
|
||||
|
||||
def load_topics(self):
|
||||
"""
|
||||
|
@ -648,7 +648,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
|
|||
choice, ok = QtWidgets.QInputDialog.getItem(self, translate('SongsPlugin.EditSongForm', 'Edit Author Type'),
|
||||
translate('SongsPlugin.EditSongForm',
|
||||
'Choose type for this author'),
|
||||
AuthorType.TranslatedTypes,
|
||||
AuthorType.get_translated_types_list(),
|
||||
current=AuthorType.SortedTypes.index(author_type),
|
||||
editable=False)
|
||||
if not ok:
|
||||
|
|
|
@ -143,14 +143,6 @@ class AuthorType(object):
|
|||
Music = 'music'
|
||||
WordsAndMusic = 'words+music'
|
||||
Translation = 'translation'
|
||||
Types = {
|
||||
NoType: '',
|
||||
Words: translate('SongsPlugin.AuthorType', 'Words', 'Author who wrote the lyrics of a song'),
|
||||
Music: translate('SongsPlugin.AuthorType', 'Music', 'Author who wrote the music of a song'),
|
||||
WordsAndMusic: translate('SongsPlugin.AuthorType', 'Words and Music',
|
||||
'Author who wrote both lyrics and music of a song'),
|
||||
Translation: translate('SongsPlugin.AuthorType', 'Translation', 'Author who translated the song')
|
||||
}
|
||||
SortedTypes = [
|
||||
NoType,
|
||||
Words,
|
||||
|
@ -158,13 +150,45 @@ class AuthorType(object):
|
|||
WordsAndMusic,
|
||||
Translation
|
||||
]
|
||||
TranslatedTypes = [
|
||||
Types[NoType],
|
||||
Types[Words],
|
||||
Types[Music],
|
||||
Types[WordsAndMusic],
|
||||
Types[Translation]
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_translated_type(cls, author_type: str) -> str:
|
||||
if author_type == cls.NoType:
|
||||
return ''
|
||||
elif author_type == cls.Words:
|
||||
return translate('SongsPlugin.AuthorType', 'Words',
|
||||
'Author who wrote the lyrics of a song')
|
||||
elif author_type == cls.Music:
|
||||
return translate('SongsPlugin.AuthorType', 'Music',
|
||||
'Author who wrote the music of a song')
|
||||
elif author_type == cls.WordsAndMusic:
|
||||
return translate('SongsPlugin.AuthorType', 'Words and Music',
|
||||
'Author who wrote both lyrics and music of a song')
|
||||
elif author_type == cls.Translation:
|
||||
return translate('SongsPlugin.AuthorType', 'Translation',
|
||||
'Author who translated the song')
|
||||
|
||||
raise ValueError(f'Unknown author type: {author_type}')
|
||||
|
||||
@classmethod
|
||||
def get_translated_types(cls):
|
||||
return {
|
||||
cls.NoType: cls.get_translated_type(cls.NoType),
|
||||
cls.Words: cls.get_translated_type(cls.Words),
|
||||
cls.Music: cls.get_translated_type(cls.Music),
|
||||
cls.WordsAndMusic: cls.get_translated_type(cls.WordsAndMusic),
|
||||
cls.Translation: cls.get_translated_type(cls.Translation)
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_translated_types_list(cls):
|
||||
return [
|
||||
cls.get_translated_type(cls.NoType),
|
||||
cls.get_translated_type(cls.Words),
|
||||
cls.get_translated_type(cls.Music),
|
||||
cls.get_translated_type(cls.WordsAndMusic),
|
||||
cls.get_translated_type(cls.Translation)
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def from_translated_text(translated_type):
|
||||
|
@ -172,7 +196,7 @@ class AuthorType(object):
|
|||
Get the AuthorType from a translated string.
|
||||
:param translated_type: Translated Author type.
|
||||
"""
|
||||
for key, value in AuthorType.Types.items():
|
||||
for key, value in AuthorType.get_translated_types().items():
|
||||
if value == translated_type:
|
||||
return key
|
||||
return AuthorType.NoType
|
||||
|
@ -194,7 +218,8 @@ class Author(Base):
|
|||
def get_display_name(self, author_type: Optional[str] = None) -> str:
|
||||
"""Determine the display name"""
|
||||
if author_type:
|
||||
return "{name} ({author})".format(name=self.display_name, author=AuthorType.Types[author_type])
|
||||
return "{name} ({author})".format(name=self.display_name,
|
||||
author=AuthorType.get_translated_type(author_type))
|
||||
return self.display_name
|
||||
|
||||
@property
|
||||
|
|
|
@ -657,17 +657,21 @@ class SongMediaItem(MediaManagerItem):
|
|||
item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'),
|
||||
authors=create_separated_list(authors.none)))
|
||||
if authors.words_music:
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.WordsAndMusic],
|
||||
authors=create_separated_list(authors.words_music)))
|
||||
item.raw_footer.append("{text}: {authors}".format(
|
||||
text=AuthorType.get_translated_type(AuthorType.WordsAndMusic),
|
||||
authors=create_separated_list(authors.words_music))
|
||||
)
|
||||
if authors.words:
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Words],
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.get_translated_type(AuthorType.Words),
|
||||
authors=create_separated_list(authors.words)))
|
||||
if authors.music:
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Music],
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.get_translated_type(AuthorType.Music),
|
||||
authors=create_separated_list(authors.music)))
|
||||
if authors.translation:
|
||||
item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Translation],
|
||||
authors=create_separated_list(authors.translation)))
|
||||
item.raw_footer.append("{text}: {authors}".format(
|
||||
text=AuthorType.get_translated_type(AuthorType.Translation),
|
||||
authors=create_separated_list(authors.translation))
|
||||
)
|
||||
if song.copyright:
|
||||
item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol,
|
||||
song=song.copyright))
|
||||
|
@ -708,13 +712,13 @@ class SongMediaItem(MediaManagerItem):
|
|||
'alternate_title': song.alternate_title,
|
||||
'authors_none_label': translate('OpenLP.Ui', 'Written by'),
|
||||
'authors_none': authors.none,
|
||||
'authors_words_label': AuthorType.Types[AuthorType.Words],
|
||||
'authors_words_label': AuthorType.get_translated_type(AuthorType.Words),
|
||||
'authors_words': authors.words,
|
||||
'authors_music_label': AuthorType.Types[AuthorType.Music],
|
||||
'authors_music_label': AuthorType.get_translated_type(AuthorType.Music),
|
||||
'authors_music': authors.music,
|
||||
'authors_words_music_label': AuthorType.Types[AuthorType.WordsAndMusic],
|
||||
'authors_words_music_label': AuthorType.get_translated_type(AuthorType.WordsAndMusic),
|
||||
'authors_words_music': authors.words_music,
|
||||
'authors_translation_label': AuthorType.Types[AuthorType.Translation],
|
||||
'authors_translation_label': AuthorType.get_translated_type(AuthorType.Translation),
|
||||
'authors_translation': authors.translation,
|
||||
'authors_words_all': authors.words + authors.words_music,
|
||||
'authors_music_all': authors.music + authors.words_music,
|
||||
|
|
|
@ -194,13 +194,15 @@ class SongsTab(SettingsTab):
|
|||
['alternate_title', translate('SongsPlugin.SongsTab', 'Alternate Title'), True, False],
|
||||
['written_by', const.format(translate('SongsPlugin.SongsTab', 'Written By')), True, False],
|
||||
['authors_none', translate('SongsPlugin.SongsTab', 'Authors when type is not set'), False, True],
|
||||
['authors_words_label', const.format(AuthorType.Types[AuthorType.Words]), False, False],
|
||||
['authors_words_label', const.format(AuthorType.get_translated_type(AuthorType.Words)), False, False],
|
||||
['authors_words', translate('SongsPlugin.SongsTab', 'Authors (Type "Words")'), False, True],
|
||||
['authors_music_label', const.format(AuthorType.Types[AuthorType.Music]), False, False],
|
||||
['authors_music_label', const.format(AuthorType.get_translated_type(AuthorType.Music)), False, False],
|
||||
['authors_music', translate('SongsPlugin.SongsTab', 'Authors (Type "Music")'), False, True],
|
||||
['authors_words_music_label', const.format(AuthorType.Types[AuthorType.WordsAndMusic]), False, False],
|
||||
['authors_words_music_label', const.format(AuthorType.get_translated_type(AuthorType.WordsAndMusic)),
|
||||
False, False],
|
||||
['authors_words_music', translate('SongsPlugin.SongsTab', 'Authors (Type "Words and Music")'), False, True],
|
||||
['authors_translation_label', const.format(AuthorType.Types[AuthorType.Translation]), False, False],
|
||||
['authors_translation_label', const.format(AuthorType.get_translated_type(AuthorType.Translation)),
|
||||
False, False],
|
||||
['authors_translation', translate('SongsPlugin.SongsTab', 'Authors (Type "Translation")'), False, True],
|
||||
['authors_words_all', translate('SongsPlugin.SongsTab', 'Authors (Type "Words" & "Words and Music")'),
|
||||
False, True],
|
||||
|
|
|
@ -113,7 +113,7 @@ def test_get_author_type_from_translated_text():
|
|||
Test getting an author type from translated text
|
||||
"""
|
||||
# GIVEN: A string with an author type
|
||||
author_type_name = AuthorType.Types[AuthorType.Words]
|
||||
author_type_name = AuthorType.get_translated_type(AuthorType.Words)
|
||||
|
||||
# WHEN: We call the method
|
||||
author_type = AuthorType.from_translated_text(author_type_name)
|
||||
|
|
Loading…
Reference in New Issue