From dd92d64143ca84eeb78eb59cf19ba72fea174866 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 5 Jan 2025 13:31:45 -0800 Subject: [PATCH] add translations for playlist add toast --- res/translations/de.json | 7 ++++++- res/translations/en.json | 7 ++++++- res/translations/es.json | 7 ++++++- res/translations/fr.json | 7 ++++++- res/translations/it.json | 7 ++++++- res/translations/ja.json | 7 ++++++- res/translations/pl.json | 7 ++++++- res/translations/pt_BR.json | 7 ++++++- res/translations/ro.json | 7 ++++++- res/translations/zh.json | 7 ++++++- res/translations/zhHans.json | 7 ++++++- ui/controller/controller.go | 15 +++++++++------ ui/toastoverlay.go | 11 ++++++++--- 13 files changed, 83 insertions(+), 20 deletions(-) diff --git a/res/translations/de.json b/res/translations/de.json index 6c9c9ed2..09691c8b 100644 --- a/res/translations/de.json +++ b/res/translations/de.json @@ -239,5 +239,10 @@ "Sept": "Sept", "Oct": "Okt", "Nov": "Nov", - "Dec": "Dec" + "Dec": "Dec", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/en.json b/res/translations/en.json index b84bb009..b793e6e5 100644 --- a/res/translations/en.json +++ b/res/translations/en.json @@ -242,5 +242,10 @@ "Sept": "Sept", "Oct": "Oct", "Nov": "Nov", - "Dec": "Dec" + "Dec": "Dec", + + "playlist.addedtracks": { + "one": "Added one track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/es.json b/res/translations/es.json index 7830ff53..84589792 100644 --- a/res/translations/es.json +++ b/res/translations/es.json @@ -241,5 +241,10 @@ "Sept": "Set", "Oct": "Oct", "Nov": "Nov", - "Dec": "Dic" + "Dec": "Dic", + + "playlist.addedtracks": { + "one": "Se ha añadido una pista a la lista de reproducción", + "other": "Se han añadido {{.trackCount}} pistas a la lista de reproducción" + } } diff --git a/res/translations/fr.json b/res/translations/fr.json index e5729444..d886c167 100644 --- a/res/translations/fr.json +++ b/res/translations/fr.json @@ -240,5 +240,10 @@ "Sept": "Sept", "Oct": "Oct", "Nov": "Nov", - "Dec": "Déc" + "Dec": "Déc", + + "playlist.addedtracks": { + "one": "Une piste ajoutée à la liste de lecture", + "other": "{{.trackCount}} pistes ajoutées à la liste de lecture" + } } diff --git a/res/translations/it.json b/res/translations/it.json index 2d657f1a..a7023719 100644 --- a/res/translations/it.json +++ b/res/translations/it.json @@ -238,5 +238,10 @@ "Sept": "Set", "Oct": "Ott", "Nov": "Nov", - "Dec": "Dic" + "Dec": "Dic", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/ja.json b/res/translations/ja.json index 2898c57a..6d7eb543 100644 --- a/res/translations/ja.json +++ b/res/translations/ja.json @@ -228,5 +228,10 @@ "Remove from queue": "キューから削除", "Play song radio": "曲をラジオで再生", "to":"to", - "by":"by" + "by":"by", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/pl.json b/res/translations/pl.json index a920e603..edf39cc7 100644 --- a/res/translations/pl.json +++ b/res/translations/pl.json @@ -228,5 +228,10 @@ "Remove from queue": "Usuń z kolejki odtwarzania", "Play song radio": "Odtwórz mix utworów", "to":"do", - "by":"przez" + "by":"przez", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/pt_BR.json b/res/translations/pt_BR.json index 6555288d..4d63bbbe 100644 --- a/res/translations/pt_BR.json +++ b/res/translations/pt_BR.json @@ -228,5 +228,10 @@ "Remove from queue": "Remover da fila", "Play song radio": "Reproduzir rádio da faixa", "to":"a", - "by":"de" + "by":"de", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/ro.json b/res/translations/ro.json index cd0b9d79..dc075662 100644 --- a/res/translations/ro.json +++ b/res/translations/ro.json @@ -230,5 +230,10 @@ "Sept": "Sept", "Oct": "Oct", "Nov": "Noiem", - "Dec": "Dec" + "Dec": "Dec", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/zh.json b/res/translations/zh.json index a71f69b3..7102cff5 100644 --- a/res/translations/zh.json +++ b/res/translations/zh.json @@ -216,5 +216,10 @@ "Unset favorite": "取消收藏", "Remove from queue": "从队列中移除", "Size": "大小", - "Play song radio": "播放歌曲电台" + "Play song radio": "播放歌曲电台", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/res/translations/zhHans.json b/res/translations/zhHans.json index cb3e9b02..727b0f64 100644 --- a/res/translations/zhHans.json +++ b/res/translations/zhHans.json @@ -216,5 +216,10 @@ "Unset favorite": "取消收藏", "Remove from queue": "从队列中移除", "Size": "大小", - "Play song radio": "播放歌曲电台" + "Play song radio": "播放歌曲电台", + + "playlist.addedtracks": { + "one": "Added {{.trackCount}} track to playlist", + "other": "Added {{.trackCount}} tracks to playlist" + } } diff --git a/ui/controller/controller.go b/ui/controller/controller.go index fff66689..f67b9a98 100644 --- a/ui/controller/controller.go +++ b/ui/controller/controller.go @@ -11,6 +11,7 @@ import ( "net/url" "os" "path/filepath" + "strconv" "sync" "time" @@ -304,14 +305,18 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) { m.doModalClosed() }) sp.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string) { + notifySuccess := func(n int) { + msg := lang.LocalizePluralKey("playlist.addedtracks", + "Added tracks to playlist", n, map[string]string{"trackCount": strconv.Itoa(n)}) + m.ToastProvider.ShowSuccessToast(msg) + } pop.Hide() m.App.Config.Application.AddToPlaylistSkipDuplicates = sp.SkipDuplicates if id == "" /* creating new playlist */ { go func() { err := m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs) if err == nil { - // TODO: translate, adjust by plurality - m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(trackIDs))) + notifySuccess(len(trackIDs)) } }() } else { @@ -331,8 +336,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) { }) err := m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs) if err == nil { - // TODO: translate, adjust by plurality - m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(filterTrackIDs))) + notifySuccess(len(filterTrackIDs)) } } }() @@ -340,8 +344,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) { go func() { err := m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs) if err == nil { - // TODO: translate, adjust by plurality - m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(trackIDs))) + notifySuccess(len(trackIDs)) } }() } diff --git a/ui/toastoverlay.go b/ui/toastoverlay.go index 9a1e3c18..e78b3ec3 100644 --- a/ui/toastoverlay.go +++ b/ui/toastoverlay.go @@ -16,6 +16,11 @@ import ( "github.com/dweymouth/supersonic/ui/widgets" ) +const ( + toastAutoDismissalTime = 3 * time.Second + toastAnimationDuration = 100 * time.Millisecond +) + type ToastOverlay struct { widget.BaseWidget @@ -46,7 +51,7 @@ func (t *ToastOverlay) ShowSuccessToast(message string) { endPos := fyne.NewPos(s.Width-min.Width-pad, s.Height-min.Height-pad) startPos := fyne.NewPos(s.Width, endPos.Y) f := t.makeToastAnimFunc(endPos, false) - t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, 100*time.Millisecond, f) + t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, toastAnimationDuration, f) t.currentToastAnim.Curve = fyne.AnimationEaseOut t.currentToastAnim.Start() t.Refresh() @@ -54,7 +59,7 @@ func (t *ToastOverlay) ShowSuccessToast(message string) { ctx, cancel := context.WithCancel(context.Background()) t.dismissCancel = cancel // always canceled by dismissToast go func() { - time.Sleep(2 * time.Second) + time.Sleep(toastAutoDismissalTime) select { case <-ctx.Done(): return @@ -120,7 +125,7 @@ func (t *ToastOverlay) dismissToast() { startPos := fyne.NewPos(s.Width-min.Width-pad, s.Height-min.Height-pad) endPos := fyne.NewPos(s.Width, startPos.Y) f := t.makeToastAnimFunc(endPos, true) - t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, 100*time.Millisecond, f) + t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, toastAnimationDuration, f) t.currentToastAnim.Curve = fyne.AnimationEaseIn t.currentToastAnim.Start() }