Skip to content

Commit

Permalink
replaygain2: fix several issues with with call to window.set_statusba…
Browse files Browse the repository at this point in the history
…r_message

- N_() was used, even though this neither causes translation of strings
  nor are translations in plugins currently supported.
- Use of f-strings should be avoided here, as the function expects
  percent formatting (PICARD-2683)
- f-strings must also never be used in combination with translations
  • Loading branch information
phw committed Jul 25, 2023
1 parent c03c7f1 commit 71e5a52
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions plugins/replaygain2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
This plugin is based on the original ReplayGain plugin by Philipp Wolfer and Sophist.
'''
PLUGIN_VERSION = "1.2"
PLUGIN_VERSION = "1.3"
PLUGIN_API_VERSIONS = ["2.0"]
PLUGIN_LICENSE = "GPL-2.0"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html"
Expand Down Expand Up @@ -121,7 +121,7 @@
# Make sure the rsgain executable exists
def rsgain_found(rsgain_command, window):
if not os.path.exists(rsgain_command) and shutil.which(rsgain_command) is None:
window.set_statusbar_message(N_("Failed to locate rsgain. Enter the path in the plugin settings."))
window.set_statusbar_message("Failed to locate rsgain. Enter the path in the plugin settings.")
return False
return True

Expand Down Expand Up @@ -259,7 +259,7 @@ def calculate_replaygain(tracks, options):


class ScanTracks(BaseAction):
NAME = N_("Calculate Replay&Gain...")
NAME = "Calculate Replay&Gain..."

def callback(self, objs):
if not rsgain_found(self.config.setting["rsgain_command"], self.tagger.window):
Expand All @@ -269,11 +269,11 @@ def callback(self, objs):
num_tracks = len(tracks)
if num_tracks == 1:
self.tagger.window.set_statusbar_message(
N_(f"Calculating ReplayGain for {tracks[0].files[0].filename}...")
'Calculating ReplayGain for %s...', {tracks[0].files[0].filename}
)
else:
self.tagger.window.set_statusbar_message(
N_(f"Calculating ReplayGain for {num_tracks} tracks...")
'Calculating ReplayGain for %i tracks...', num_tracks
)
thread.run_task(
partial(calculate_replaygain, tracks, self.options),
Expand All @@ -286,17 +286,13 @@ def _replaygain_callback(self, tracks, result=None, error=None):
for file in track.files:
file.update()
track.update()
self.tagger.window.set_statusbar_message(
N_('ReplayGain successfully calculated.')
)
self.tagger.window.set_statusbar_message('ReplayGain successfully calculated.')
else:
self.tagger.window.set_statusbar_message(
N_('Could not calculate ReplayGain.')
)
self.tagger.window.set_statusbar_message('Could not calculate ReplayGain.')


class ScanAlbums(BaseAction):
NAME = N_("Calculate Replay&Gain...")
NAME = "Calculate Replay&Gain..."

def callback(self, objs):
if not rsgain_found(self.config.setting["rsgain_command"], self.tagger.window):
Expand All @@ -308,11 +304,11 @@ def callback(self, objs):
self.current = 0
if (self.num_albums == 1):
self.tagger.window.set_statusbar_message(
N_(f"Calculating ReplayGain for '{albums[0].metadata['album']}'...")
'Calculating ReplayGain for "%s"...', albums[0].metadata['album']
)
else:
self.tagger.window.set_statusbar_message(
N_(f"Calculating ReplayGain for {self.num_albums} albums...")
'Calculating ReplayGain for %i albums...', self.num_albums
)
for album in albums:
thread.run_task(
Expand All @@ -336,11 +332,19 @@ def _albumgain_callback(self, album, result=None, error=None):
track.update()
album.update()
self.tagger.window.set_statusbar_message(
N_(f"Successfully calculated ReplayGain for '{album.metadata['album']}'{progress}.")
'Successfully calculated ReplayGain for "%(album)s"%(progress)s.',
{
'album': album.metadata['album'],
'progress': progress,
}
)
else:
self.tagger.window.set_statusbar_message(
N_(f"Failed to calculate ReplayGain for '{album.metadata['album']}{progress}.'")
'Failed to calculate ReplayGain for "%(album)s"%(progress)s.',
{
'album': album.metadata['album'],
'progress': progress,
}
)

class ReplayGain2OptionsPage(OptionsPage):
Expand All @@ -366,13 +370,13 @@ def __init__(self, parent=None):
self.ui = Ui_ReplayGain2OptionsPage()
self.ui.setupUi(self)
self.ui.clip_mode.addItems([
N_("Disabled"),
N_("Enabled for positive gain values only"),
N_("Always enabled")
"Disabled",
"Enabled for positive gain values only",
"Always enabled"
])
self.ui.opus_mode.addItems([
N_("Write standard ReplayGain tags"),
N_("Write R128_*_GAIN tags")
"Write standard ReplayGain tags",
"Write R128_*_GAIN tags"
])
self.ui.rsgain_command_browse.clicked.connect(self.rsgain_command_browse)

Expand Down

0 comments on commit 71e5a52

Please sign in to comment.