Locale for context menu (#337)

This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-03-23 14:30:32 -04:00
1 parent 25330a6494
commit 615439650e
13 files changed
+180 -38

No files matched your search

@@ -217,6 +217,7 @@ function InitializeSortOptions()
end function
function CreateChannelFeed(title as string, endpoint as string, ucid as string, author as string) as object
title = Tr(title)
return {
title: title
feedSources: [{
@@ -257,7 +258,7 @@ function GetSortingContextMenuOptionsForItem(video as object) as object
return []
end if
title = Tr(Locale.Dialogs.SortFeedBy).replace("%1", feedContentNode.title)
title = Tr(Locale.Dialogs.SortFeedBy).replace("%1", `"${feedSource.title}"`)
sortOptions = m.sortOptions[endpoint]
return [ContextMenuUtils.CreateOption(title + "...", m.top, "ShowSortDialog", [title, sortOptions, feedContentNode])]
@@ -163,10 +163,10 @@ function GetContextMenuOptionsForItem(video as object) as object
end if
options = [
ContextMenuUtils.CreateOption("Play", m.videoQueue, "FuncPlayPlaylist", [playlist, index]),
ContextMenuUtils.CreateOption("Queue", m.videoQueue, "FuncAddToQueuePlaylist", [playlist])
ContextMenuUtils.CreateOption("Play video", m.videoQueue, "FuncPlayVideo", [video]),
ContextMenuUtils.CreateOption("Queue video", m.videoQueue, "FuncAddToQueueVideo", [video]),
ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.PlayPlaylist), m.videoQueue, "FuncPlayPlaylist", [playlist, index]),
ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.QueuePlaylist), m.videoQueue, "FuncAddToQueuePlaylist", [playlist])
ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.PlayVideo), m.videoQueue, "FuncPlayVideo", [video]),
ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.QueueVideo), m.videoQueue, "FuncAddToQueueVideo", [video]),
]
playlistAuthorId = playlist.authorId
@@ -174,13 +174,13 @@ function GetContextMenuOptionsForItem(video as object) as object
if not StringUtils.IsNullOrEmpty(playlistAuthorId) or not StringUtils.IsNullOrEmpty(videoAuthorId)
if playlistAuthorId = videoAuthorId
options.push(ContextMenuUtils.CreateOption("Open channel", m.top, "OpenPlaylistChannel", [playlist]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenChannel), m.top, "OpenPlaylistChannel", [playlist]))
else
if not StringUtils.IsNullOrEmpty(playlistAuthorId)
options.push(ContextMenuUtils.CreateOption("Open playlist channel", m.top, "OpenPlaylistChannel", [playlist]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenPlaylistChannel), m.top, "OpenPlaylistChannel", [playlist]))
end if
if not StringUtils.IsNullOrEmpty(videoAuthorId)
options.push(ContextMenuUtils.CreateOption("Open video channel", m.top, "OpenVideoChannel", [video]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenVideoChannel), m.top, "OpenVideoChannel", [video]))
end if
end if
end if
@@ -1,6 +1,7 @@
import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Types.bs"
function Init()
@@ -95,6 +96,6 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function
function GetContextMenuOptionsForItem(rowItem as object) as object
refreshItem = ContextMenuUtils.CreateOption("Refresh Bookmarks", m.top, "Refresh", [invalid])
refreshItem = ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.RefreshBookmarks), m.top, "Refresh", [invalid])
return [refreshItem]
end function
@@ -2,6 +2,7 @@ import "HomeScreenUtils.bs"
import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
function Init()
m.top.focusable = true
@@ -41,6 +42,6 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function
function GetContextMenuOptionsForItem(rowItem as object) as object
refresh = ContextMenuUtils.CreateOption("Refresh Home", m.rowList, "Refresh", [invalid])
refresh = ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.RefreshHome), m.rowList, "Refresh", [invalid])
return [refresh]
end function
@@ -4,6 +4,13 @@ namespace HomeScreenUtils
function GetFeed(feedFileName as string, preferences as object) as object
feed = ParseJson(ReadAsciiFile(feedFileName))
for each item in feed
item.title = Tr(item.title)
for each feedSource in item.feedSources
feedSource.title = Tr(feedSource.title)
end for
end for
homeLayout = preferences["misc.home_screen_layout"]
if not IsArray(homeLayout) or homeLayout.Count() = 0
@@ -1,14 +1,11 @@
import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
import "pkg:/source/utils/CryptoUtils.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RegistryUtils.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"
const VIDEOS_GROUP = "Videos"
const CHANNELS_GROUP = "Channels"
const PLAYLISTS_GROUP = "Playlists"
function Init()
m.top.content = m.top.findNode("content")
m.bookmarksString = ""
@@ -140,7 +137,7 @@ function AddPlaylistBookmarkWithSpread(id as string, groupName as string)
feedSource = {
"id": `inv_playlist_${id}`
"title": `${groupName} videos`
"title": `${groupName} ${Tr(Locale.Feed.Videos)}`
"apiType": "Invidious"
"endpoint": "playlist"
"pathParams": {
@@ -177,7 +174,7 @@ function AddChannelBookmarkWithSpread(id as string, groupName as string)
feedSource = {
"id": `inv_channel_videos_${id}`
"title": `${groupName} videos`
"title": `${groupName} ${Tr(Locale.Feed.Videos)}`
"apiType": "Invidious"
"endpoint": "channel_videos"
"pathParams": {
@@ -241,10 +238,14 @@ function GetMenuForVideo(videoNode as object) as object
isInBookmarks = bookmark <> invalid
if isInBookmarks
bookmarkGroup = bookmark.getParent()
item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [videoId])
title = Tr(Locale.ContextMenu.RemoveFromBookmarks).Replace("%1", `"${bookmarkGroup.title}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "RemoveBookmark", [videoId])
menu.push(item)
else
item = ContextMenuUtils.CreateOption(`Add to "${VIDEOS_GROUP}" bookmark`, m.top, "AddVideoBookmark", [videoId, VIDEOS_GROUP])
' "Videos" exists in feed
group = Tr(Locale.Feed.Videos)
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${group}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddVideoBookmark", [videoId, group])
menu.push(item)
end if
return menu
@@ -261,13 +262,18 @@ function GetMenuForPlaylist(playlistNode as object) as object
isInBookmarks = bookmark <> invalid
if isInBookmarks
bookmarkGroup = bookmark.getParent()
item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [playlistId])
title = Tr(Locale.ContextMenu.RemoveFromBookmarks).Replace("%1", `"${bookmarkGroup.title}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "RemoveBookmark", [playlistId])
menu.push(item)
else
item = ContextMenuUtils.CreateOption(`Add to "${PLAYLISTS_GROUP}" bookmark`, m.top, "AddPlaylistBookmark", [playlistId, PLAYLISTS_GROUP])
' "Playlists" exists in feed
group = Tr(Locale.Feed.Playlists)
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${group}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddPlaylistBookmark", [playlistId, group])
menu.push(item)
item = ContextMenuUtils.CreateOption(`Add to "${playlistNode.title}" bookmark`, m.top, "AddPlaylistBookmarkWithSpread", [playlistId, playlistNode.title])
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${playlistNode.title}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddPlaylistBookmarkWithSpread", [playlistId, playlistNode.title])
menu.push(item)
end if
return menu
@@ -284,13 +290,17 @@ function GetMenuForChannel(channelNode as object) as object
isInBookmarks = bookmark <> invalid
if isInBookmarks
bookmarkGroup = bookmark.getParent()
item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [authorId])
title = Tr(Locale.ContextMenu.RemoveFromBookmarks).Replace("%1", `"${bookmarkGroup.title}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "RemoveBookmark", [authorId])
menu.push(item)
else
item = ContextMenuUtils.CreateOption(`Add to "${CHANNELS_GROUP}" bookmark`, m.top, "AddChannelBookmark", [authorId, CHANNELS_GROUP])
group = Tr(Locale.Bookmarks.Channels)
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${group}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddChannelBookmark", [authorId, group])
menu.push(item)
item = ContextMenuUtils.CreateOption(`Add to "${channelNode._author}" bookmark`, m.top, "AddChannelBookmarkWithSpread", [authorId, channelNode._author])
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${channelNode._author}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddChannelBookmarkWithSpread", [authorId, channelNode._author])
menu.push(item)
end if
return menu
@@ -316,17 +326,19 @@ function GetMenuForParentFeedSource(itemNode as object) as object
return []
end if
title = feedSource.title
feedSourceTitle = feedSource.title
feedSourceId = feedSource.id
menu = []
isInBookmarks = m.top.content.findNode(feedSourceId) <> invalid
if isInBookmarks
item = ContextMenuUtils.CreateOption(`Remove "${feedSource.title}" from bookmarks`, m.top, "RemoveBookmark", [feedSourceId])
title = Tr(Locale.ContextMenu.RemoveFromBookmarks).Replace("%1", `"${feedSourceTitle}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "RemoveBookmark", [feedSourceId])
menu.push(item)
else
item = ContextMenuUtils.CreateOption(`Add to "${title}" bookmark`, m.top, "AddFeedSourceBookmark", [feedSource, feedSourceId, title])
title = Tr(Locale.ContextMenu.AddToBookmark).Replace("%1", `"${feedSourceTitle}"`)
item = ContextMenuUtils.CreateOption(title, m.top, "AddFeedSourceBookmark", [feedSource, feedSourceId, feedSourceTitle])
menu.push(item)
end if
return menu
@@ -145,25 +145,25 @@ function GetContextMenuOptionsForItem(rowItem as object) as object
options = []
if rowItem.type = "video"
options.push(ContextMenuUtils.CreateOption("Play", m.videoQueue, "FuncPlayVideo", [rowItem]))
options.push(ContextMenuUtils.CreateOption("Queue", m.videoQueue, "FuncAddToQueueVideo", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.PlayVideo), m.videoQueue, "FuncPlayVideo", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.QueueVideo), m.videoQueue, "FuncAddToQueueVideo", [rowItem]))
authorId = rowItem.authorId
if not StringUtils.IsNullOrEmpty(authorId)
options.push(ContextMenuUtils.CreateOption("Open channel", m.top, "OpenVideoChannel", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenChannel), m.top, "OpenVideoChannel", [rowItem]))
end if
else if rowItem.type = "playlist"
options.push(ContextMenuUtils.CreateOption("Play", m.videoQueue, "FuncPlayPlaylist", [rowItem, 0]))
options.push(ContextMenuUtils.CreateOption("Queue", m.videoQueue, "FuncAddToQueuePlaylist", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.PlayPlaylist), m.videoQueue, "FuncPlayPlaylist", [rowItem, 0]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.QueuePlaylist), m.videoQueue, "FuncAddToQueuePlaylist", [rowItem]))
options.push(ContextMenuUtils.CreateOption("Open playlist", m.top, "OpenPlaylist", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenPlaylist), m.top, "OpenPlaylist", [rowItem]))
authorId = rowItem.authorId
if not StringUtils.IsNullOrEmpty(authorId)
options.push(ContextMenuUtils.CreateOption("Open channel", m.top, "OpenPlaylistChannel", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenChannel), m.top, "OpenPlaylistChannel", [rowItem]))
end if
else if rowItem.type = "channel"
options.push(ContextMenuUtils.CreateOption("Open", m.top, "OpenChannel", [rowItem]))
options.push(ContextMenuUtils.CreateOption(Tr(Locale.ContextMenu.OpenChannel), m.top, "OpenChannel", [rowItem]))
else
LogWarn("Unknown long pressed item type:", rowItem.type)
return []
@@ -10,7 +10,7 @@ function VideoRowListContentTask(input as object)
for each feed in feeds
feedContentNode = CreateObject("roSGNode", "FeedContentNode")
feedContentNode.title = Tr(feed.title)
feedContentNode.title = feed.title
feedContentNode.feedSourcesIndex = 0
feedContentNode.loadState = FeedLoadState.None
feedSources = feed.feedSources