Fix missing translations

This commit is contained in:
Chris Witterholt 2024-03-18 06:13:26 +00:00 committed by Raoul Snyman
parent a53e20864c
commit 6ea889b974
18 changed files with 55 additions and 57 deletions

View File

@ -309,15 +309,15 @@ class Ui_EditSongDialog(object):
self.verse_delete_button.setText(UiStrings().Delete)
self.song_tab_widget.setTabText(self.song_tab_widget.indexOf(self.lyrics_tab),
translate('SongsPlugin.EditSongForm', 'Title && Lyrics'))
self.authors_group_box.setTitle(SongStrings.Authors)
self.authors_group_box.setTitle(SongStrings().Authors)
self.author_add_button.setText(translate('SongsPlugin.EditSongForm', '&Add to Song'))
self.author_edit_button.setText(translate('SongsPlugin.EditSongForm', '&Edit Author Type'))
self.author_remove_button.setText(translate('SongsPlugin.EditSongForm', '&Remove'))
self.maintenance_button.setText(translate('SongsPlugin.EditSongForm', '&Manage Authors, Topics, Songbooks'))
self.topics_group_box.setTitle(SongStrings.Topics)
self.topics_group_box.setTitle(SongStrings().Topics)
self.topic_add_button.setText(translate('SongsPlugin.EditSongForm', 'A&dd to Song'))
self.topic_remove_button.setText(translate('SongsPlugin.EditSongForm', 'R&emove'))
self.songbook_group_box.setTitle(SongStrings.SongBooks)
self.songbook_group_box.setTitle(SongStrings().SongBooks)
self.songbook_add_button.setText(translate('SongsPlugin.EditSongForm', 'Add &to Song'))
self.songbook_remove_button.setText(translate('SongsPlugin.EditSongForm', 'Re&move'))
self.song_tab_widget.setTabText(self.song_tab_widget.indexOf(self.authors_tab),
@ -325,7 +325,7 @@ class Ui_EditSongDialog(object):
self.theme_group_box.setTitle(UiStrings().Theme)
self.theme_add_button.setText(translate('SongsPlugin.EditSongForm', 'New &Theme'))
self.rights_group_box.setTitle(translate('SongsPlugin.EditSongForm', 'Copyright Information'))
self.copyright_insert_button.setText(SongStrings.CopyrightSymbol)
self.copyright_insert_button.setText(SongStrings().CopyrightSymbol)
self.ccli_label.setText(UiStrings().CCLISongNumberLabel)
self.comments_group_box.setTitle(translate('SongsPlugin.EditSongForm', 'Comments'))
self.song_tab_widget.setTabText(self.song_tab_widget.indexOf(self.theme_tab),

View File

@ -911,7 +911,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
"""
text = self.copyright_edit.text()
pos = self.copyright_edit.cursorPosition()
sign = SongStrings.CopyrightSymbol
sign = SongStrings().CopyrightSymbol
text = text[:pos] + sign + text[pos:]
self.copyright_edit.setText(text)
self.copyright_edit.setFocus()

View File

@ -141,10 +141,10 @@ class Ui_SongMaintenanceDialog(object):
"""
Translate the UI on the fly.
"""
song_maintenance_dialog.setWindowTitle(SongStrings.SongMaintenance)
self.authors_list_item.setText(SongStrings.Authors)
self.topics_list_item.setText(SongStrings.Topics)
self.books_list_item.setText(SongStrings.SongBooks)
song_maintenance_dialog.setWindowTitle(SongStrings().SongMaintenance)
self.authors_list_item.setText(SongStrings().Authors)
self.topics_list_item.setText(SongStrings().Topics)
self.books_list_item.setText(SongStrings().SongBooks)
self.add_author_button.setText(UiStrings().Add)
self.edit_author_button.setText(UiStrings().Edit)
self.delete_author_button.setText(UiStrings().Delete)
@ -154,7 +154,7 @@ class Ui_SongMaintenanceDialog(object):
self.add_book_button.setText(UiStrings().Add)
self.edit_book_button.setText(UiStrings().Edit)
self.delete_book_button.setText(UiStrings().Delete)
type_list_width = max(self.fontMetrics().width(SongStrings.Authors),
self.fontMetrics().width(SongStrings.Topics),
self.fontMetrics().width(SongStrings.SongBooks))
type_list_width = max(self.fontMetrics().width(SongStrings().Authors),
self.fontMetrics().width(SongStrings().Topics),
self.fontMetrics().width(SongStrings().SongBooks))
self.type_list_widget.setFixedWidth(type_list_width + self.type_list_widget.iconSize().width() + 32)

View File

@ -384,7 +384,7 @@ def clean_song(manager, song):
song.search_lyrics = ' '.join([clean_string(remove_tags(verse[1], True)) for verse in verses])
# The song does not have any author, add one.
if not song.authors_songs:
name = SongStrings.AuthorUnknown
name = SongStrings().AuthorUnknown
author = manager.get_object_filtered(Author, Author.display_name == name)
if author is None:
author = Author(display_name=name, last_name='', first_name='')

View File

@ -56,7 +56,7 @@ class DatasoulImport(SongImport):
tree = objectify.parse(str(file_path), parser)
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
song_xml = tree.getroot()
if song_xml.tag != 'Song':

View File

@ -93,16 +93,16 @@ class DreamBeamImport(SongImport):
parsed_file = etree.parse(xml_file, parser)
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
except UnicodeDecodeError:
log.exception('Unreadable characters in {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
file_str = etree.tostring(parsed_file)
if not file_str:
log.exception('Could not find XML in file {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
xml = file_str.decode()
song_xml = objectify.fromstring(xml)
@ -151,7 +151,7 @@ class DreamBeamImport(SongImport):
author_copyright = song_xml.Text2.Text.text
if author_copyright:
author_copyright = str(author_copyright)
if author_copyright.find(SongStrings.CopyrightSymbol) >= 0:
if author_copyright.find(SongStrings().CopyrightSymbol) >= 0:
self.add_copyright(author_copyright)
else:
self.parse_author(author_copyright)

View File

@ -54,16 +54,16 @@ class EasySlidesImport(SongImport):
parsed_file = etree.parse(xml_file, parser)
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {name}'.format(name=self.import_source))
self.log_error(self.import_source, SongStrings.XMLSyntaxError)
self.log_error(self.import_source, SongStrings().XMLSyntaxError)
return
except UnicodeDecodeError:
log.exception('Unreadable characters in {name}'.format(name=self.import_source))
self.log_error(self.import_source, SongStrings.XMLSyntaxError)
self.log_error(self.import_source, SongStrings().XMLSyntaxError)
return
file_str = etree.tostring(parsed_file)
if not file_str:
log.exception('Could not find XML in file {name}'.format(name=self.import_source))
self.log_error(self.import_source, SongStrings.XMLSyntaxError)
self.log_error(self.import_source, SongStrings().XMLSyntaxError)
return
xml = file_str.decode()
song_xml = objectify.fromstring(xml)

View File

@ -125,7 +125,7 @@ class FoilPresenterImport(SongImport):
xml = etree.tostring(parsed_file).decode()
self.foil_presenter.xml_to_song(xml)
except etree.XMLSyntaxError:
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
log.exception('XML syntax error in file {path}'.format(path=file_path))
except AttributeError:
self.log_error(file_path, translate('SongsPlugin.FoilPresenterSongImport',

View File

@ -72,7 +72,7 @@ class LiveWorshipImport(SongImport):
try:
self.root = etree.fromstring(xml_content, parser)
except etree.XMLSyntaxError:
self.log_error(self.dump_file, SongStrings.XMLSyntaxError)
self.log_error(self.dump_file, SongStrings().XMLSyntaxError)
log.exception('XML syntax error in file {path}'.format(path=str(self.dump_file)))
def extract_songs(self):

View File

@ -73,7 +73,7 @@ class OpenLyricsImport(SongImport):
self.open_lyrics.xml_to_song(xml)
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {path}'.format(path=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
except OpenLyricsError as exception:
log.exception('OpenLyricsException {error:d} in file {name}: {text}'.format(error=exception.type,
name=file_path,

View File

@ -129,7 +129,7 @@ class OpenSongImport(SongImport):
try:
tree = objectify.parse(file)
except (etree.Error, etree.LxmlError):
self.log_error(file.name, SongStrings.XMLSyntaxError)
self.log_error(file.name, SongStrings().XMLSyntaxError)
log.exception('Error parsing XML')
return
root = tree.getroot()

View File

@ -50,11 +50,11 @@ class PowerPraiseImport(SongImport):
root = objectify.parse(xml_file).getroot()
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
except UnicodeDecodeError:
log.exception('Unreadable characters in {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
self.process_song(root, file_path)

View File

@ -54,11 +54,11 @@ class ProPresenterImport(SongImport):
root = objectify.parse(xml_file).getroot()
except etree.XMLSyntaxError:
log.exception('XML syntax error in file {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
except UnicodeDecodeError:
log.exception('Unreadable characters in {name}'.format(name=file_path))
self.log_error(file_path, SongStrings.XMLSyntaxError)
self.log_error(file_path, SongStrings().XMLSyntaxError)
continue
try:
self.process_song(root, file_path)

View File

@ -104,7 +104,7 @@ class SongImport(QtCore.QObject):
self.verse_counts = {}
self.copyright_string = translate('SongsPlugin.SongImport', 'copyright')
def log_error(self, file_path, reason=SongStrings.SongIncomplete):
def log_error(self, file_path, reason=SongStrings().SongIncomplete):
"""
This should be called, when a song could not be imported.
@ -151,11 +151,11 @@ class SongImport(QtCore.QObject):
:param text: Some text
"""
lines = text.split('\n')
if text.lower().find(self.copyright_string) >= 0 or text.find(str(SongStrings.CopyrightSymbol)) >= 0:
if text.lower().find(self.copyright_string) >= 0 or text.find(str(SongStrings().CopyrightSymbol)) >= 0:
copyright_found = False
for line in lines:
if (copyright_found or line.lower().find(self.copyright_string) >= 0 or
line.find(str(SongStrings.CopyrightSymbol)) >= 0):
line.find(str(SongStrings().CopyrightSymbol)) >= 0):
copyright_found = True
self.add_copyright(line)
else:

View File

@ -124,7 +124,7 @@ class SongMediaItem(MediaManagerItem):
def retranslate_ui(self):
self.search_text_label.setText('{text}:'.format(text=UiStrings().Search))
self.search_text_button.setText(UiStrings().Search)
self.maintenance_action.setText(SongStrings.SongMaintenance)
self.maintenance_action.setText(SongStrings().SongMaintenance)
self.maintenance_action.setToolTip(translate('SongsPlugin.MediaItem',
'Maintain the lists of authors, topics and books.'))
@ -145,11 +145,11 @@ class SongMediaItem(MediaManagerItem):
(SongSearch.Lyrics, UiIcons().search_lyrics,
translate('SongsPlugin.MediaItem', 'Lyrics'),
translate('SongsPlugin.MediaItem', 'Search Lyrics...')),
(SongSearch.Authors, UiIcons().user, SongStrings.Authors,
(SongSearch.Authors, UiIcons().user, SongStrings().Authors,
translate('SongsPlugin.MediaItem', 'Search Authors...')),
(SongSearch.Topics, UiIcons().light_bulb, SongStrings.Topics,
(SongSearch.Topics, UiIcons().light_bulb, SongStrings().Topics,
translate('SongsPlugin.MediaItem', 'Search Topics...')),
(SongSearch.Books, UiIcons().address, SongStrings.SongBooks,
(SongSearch.Books, UiIcons().address, SongStrings().SongBooks,
translate('SongsPlugin.MediaItem', 'Search Songbooks...')),
(SongSearch.Themes, UiIcons().theme, UiStrings().Themes, UiStrings().SearchThemes),
(SongSearch.Copyright, UiIcons().copyright,
@ -673,7 +673,7 @@ class SongMediaItem(MediaManagerItem):
authors=create_separated_list(authors.translation))
)
if song.copyright:
item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol,
item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings().CopyrightSymbol,
song=song.copyright))
if song.songbook_entries:
item.raw_footer.append(", ".join(songbooks))

View File

@ -32,18 +32,19 @@ class SongStrings(object):
"""
Provide standard strings for use throughout the songs plugin.
"""
# These strings should need a good reason to be retranslated elsewhere.
Author = translate('OpenLP.Ui', 'Author', 'Singular')
Authors = translate('OpenLP.Ui', 'Authors', 'Plural')
AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used to populate the database.
CopyrightSymbol = '\xa9'
SongBook = translate('OpenLP.Ui', 'Songbook', 'Singular')
SongBooks = translate('OpenLP.Ui', 'Songbooks', 'Plural')
SongIncomplete = translate('OpenLP.Ui', 'Title and/or verses not found')
SongMaintenance = translate('OpenLP.Ui', 'Song Maintenance')
Topic = translate('OpenLP.Ui', 'Topic', 'Singular')
Topics = translate('OpenLP.Ui', 'Topics', 'Plural')
XMLSyntaxError = translate('OpenLP.Ui', 'XML syntax error')
def __init__(self):
# These strings should need a good reason to be retranslated elsewhere.
self.Author = translate('OpenLP.Ui', 'Author', 'Singular')
self.Authors = translate('OpenLP.Ui', 'Authors', 'Plural')
self.AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used to populate the database.
self.CopyrightSymbol = '\xa9'
self.SongBook = translate('OpenLP.Ui', 'Songbook', 'Singular')
self.SongBooks = translate('OpenLP.Ui', 'Songbooks', 'Plural')
self.SongIncomplete = translate('OpenLP.Ui', 'Title and/or verses not found')
self.SongMaintenance = translate('OpenLP.Ui', 'Song Maintenance')
self.Topic = translate('OpenLP.Ui', 'Topic', 'Singular')
self.Topics = translate('OpenLP.Ui', 'Topics', 'Plural')
self.XMLSyntaxError = translate('OpenLP.Ui', 'XML syntax error')
def show_key_warning(parent):

View File

@ -107,8 +107,7 @@
</column>
<item row="0" column="0">
<property name="text">
<string>
Authors</string>
<string>Authors</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
@ -120,8 +119,7 @@ Authors</string>
</item>
<item row="1" column="0">
<property name="text">
<string>
Topics</string>
<string>Topics</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
@ -133,8 +131,7 @@ Topics</string>
</item>
<item row="2" column="0">
<property name="text">
<string>
Books/Hymnals</string>
<string>Books/Hymnals</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>

View File

@ -111,14 +111,14 @@ def test_can_parse_file_having_a_processing_instruction(mocked_logger: MagicMock
# otherwise we don't care about it now (but should in other tests...)
assert ex is not etree.XMLSyntaxError
# THEN: the importer's log_error method was never called with SongStrings.XMLSyntaxError as its second
# THEN: the importer's log_error method was never called with SongStrings().XMLSyntaxError as its second
# positional argument
if importer.log_error.called:
for call_args in importer.log_error.call_args_list:
args = call_args[0]
# there are at least two positional arguments
if len(args) > 1:
assert args[1] is not SongStrings.XMLSyntaxError
assert args[1] is not SongStrings().XMLSyntaxError
# THEN: the logger's 'exception' method was never called with a first positional argument
# which is a string and starts with 'XML syntax error in file'