Skip to content

Commit

Permalink
locale for web app (#334)
Browse files Browse the repository at this point in the history
* locale for web app

* more translations

* Rename profiles service to avoid locale conflict

* More translation work

* Lint fix

---------

Co-authored-by: github-action linter <[email protected]>
  • Loading branch information
iBicha and github-action linter authored Mar 22, 2024
1 parent 019fde1 commit 42dadec
Show file tree
Hide file tree
Showing 54 changed files with 538 additions and 151 deletions.
2 changes: 2 additions & 0 deletions docs/playlet-web-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ components:
type: string
friendly_name:
type: string
current_locale:
type: string
invidious:
type: object
properties:
Expand Down
5 changes: 3 additions & 2 deletions playlet-lib/src/components/ContentNode/ChannelContentNode.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "pkg:/components/VideoFeed/FeedLoadState.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"

function LoadChannel(invidiousNode as object) as void
Expand Down Expand Up @@ -39,8 +40,8 @@ function OnChannelContentTaskResult(output as object) as void
error = ErrorUtils.Format(error)
LogError(error)
authorId = output.task.input.content.authorId
message = `Failed to load channel ${authorId}\n${error}`
DialogUtils.ShowDialog(message, "Channel load fail", true)
message = Tr(Locale.Dialogs.FailedToLoadChannel).Replace("%1", authorId) + `\n${error}`
DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.ChannelLoadError), true)
return
end if
end function
5 changes: 3 additions & 2 deletions playlet-lib/src/components/ContentNode/PlaylistContentNode.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "pkg:/components/VideoFeed/FeedLoadState.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"

function LoadPlaylistPage(invidiousNode as object) as void
Expand Down Expand Up @@ -48,8 +49,8 @@ function OnPlaylistContentTaskResult(output as object) as void
error = ErrorUtils.Format(error)
LogError(error)
playlistId = output.task.input.content.playlistId
message = `Failed to load playlist ${playlistId}\n${error}`
DialogUtils.ShowDialog(message, "Playlist load fail", true)
message = Tr(Locale.Dialogs.FailedToLoadPlaylist).Replace("%1", playlistId) + `\n${error}`
DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.PlaylistLoadError), true)
return
end if
end function
2 changes: 1 addition & 1 deletion playlet-lib/src/components/MainScene.transpiled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<Preferences id="Preferences" />
<BookmarksService id="BookmarksService" />
<SearchHistory id="SearchHistory" />
<Profiles id="Profiles" />
<ProfilesService id="ProfilesService" />
<Invidious id="Invidious" />
<PlayletWebServer id="WebServer" port="8888" />
<DialServer id="DialServer" />
Expand Down
6 changes: 3 additions & 3 deletions playlet-lib/src/components/MainScene.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@
<SearchHistory id="SearchHistory"
preferences="bind:../Preferences" />

<Profiles id="Profiles"
<ProfilesService id="ProfilesService"
invidious="bind:../Invidious" />

<Invidious id="Invidious"
webServer="bind:../WebServer"
applicationInfo="bind:../ApplicationInfo"
preferences="bind:../Preferences"
profiles="bind:../Profiles" />
profilesService="bind:../ProfilesService" />

<!-- Tasks -->
<PlayletWebServer id="WebServer"
port="8888"
appController="bind:/AppController"
applicationInfo="bind:../ApplicationInfo"
invidious="bind:../Invidious"
profiles="bind:../Profiles"
profilesService="bind:../ProfilesService"
preferences="bind:../Preferences"
videoQueue="bind:../VideoQueue"
bookmarksService="bind:../BookmarksService"
Expand Down
6 changes: 3 additions & 3 deletions playlet-lib/src/components/MainScene_bindings.transpiled.brs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ function InitializeBindings()
"SearchHistory": {
"preferences": "../Preferences"
},
"Profiles": {
"ProfilesService": {
"invidious": "../Invidious"
},
"Invidious": {
"webServer": "../WebServer",
"applicationInfo": "../ApplicationInfo",
"preferences": "../Preferences",
"profiles": "../Profiles"
"profilesService": "../ProfilesService"
},
"WebServer": {
"appController": "/AppController",
"applicationInfo": "../ApplicationInfo",
"invidious": "../Invidious",
"profiles": "../Profiles",
"profilesService": "../ProfilesService",
"preferences": "../Preferences",
"videoQueue": "../VideoQueue",
"bookmarksService": "../BookmarksService",
Expand Down
10 changes: 5 additions & 5 deletions playlet-lib/src/components/NavBar/ProfileIconButton.bs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function Init()
m.top.observeField("width", FuncName(onWidthChanged))
m.top.observeField("padding", FuncName(onPaddingChanged))

profiles = m.top.getScene().findNode("Profiles")
if profiles <> invalid
m.profiles = profiles
profiles.observeField("currentProfile", FuncName(OnCurrentProfile))
profilesService = m.top.getScene().findNode("ProfilesService")
if profilesService <> invalid
m.profilesService = profilesService
profilesService.observeField("currentProfile", FuncName(OnCurrentProfile))
OnCurrentProfile()
end if
end function
Expand Down Expand Up @@ -91,7 +91,7 @@ function onPaddingChanged()
end function

function OnCurrentProfile() as void
currentProfile = m.profiles.currentProfile
currentProfile = m.profilesService.currentProfile
if currentProfile = invalid
m.circlePoster.visible = false
m.buttonIcon.visible = true
Expand Down
12 changes: 6 additions & 6 deletions playlet-lib/src/components/ProfileView/ProfileView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function OnNodeReady()
SetNavigation(m.closeButton, "up", m.logoutButton)
SetNavigation(m.logoutButton, "up", m.activateButton)

DisposableObserveFieldScoped(m.profiles, "currentProfile", FuncName(OnCunrrentProfileChanged))
DisposableObserveFieldScoped(m.profiles, "onProfileLogout", FuncName(OnProfileLogout))
DisposableObserveFieldScoped(m.profilesService, "currentProfile", FuncName(OnCunrrentProfileChanged))
DisposableObserveFieldScoped(m.profilesService, "onProfileLogout", FuncName(OnProfileLogout))
end function

function OnContentSet() as void
Expand Down Expand Up @@ -81,13 +81,13 @@ function Activate() as void
return
end if

profile = m.profiles.content.getChild(0).findNode(content.id)
profile = m.profilesService.content.getChild(0).findNode(content.id)
if profile = invalid
return
end if

m.top.content = invalid
m.profiles@.SetCurrentProfile(profile)
m.profilesService@.SetCurrentProfile(profile)
Close()
end function

Expand All @@ -98,7 +98,7 @@ function Logout() as void
end if

m.top.content = invalid
m.profiles@.LogoutWithProfile(content)
m.profilesService@.LogoutWithProfile(content)
Close()
end function

Expand Down Expand Up @@ -127,7 +127,7 @@ function OnProfileLogout() as void
return
end if

profile = m.profiles.content.getChild(0).findNode(content.id)
profile = m.profilesService.content.getChild(0).findNode(content.id)
if profile = invalid
Close()
end if
Expand Down
2 changes: 1 addition & 1 deletion playlet-lib/src/components/ProfileView/ProfileView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field id="crownVisible" type="boolean" alias="CrownPoster.visible" />

<field id="appController" type="node" bind="/AppController" />
<field id="profiles" type="node" bind="/Profiles" />
<field id="profilesService" type="node" bind="/ProfilesService" />
</interface>
<children>
<Rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function OnNodeReady()
SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar)

m.profileRowList.content = m.profiles.content
m.profileRowList.content = m.profilesService.content
m.profileRowList.observeFieldScoped("rowItemSelected", FuncName(OnRowItemSelected))
m.profiles.observeFieldScoped("currentProfile", FuncName(OnCurrentProfileChanged))
m.profilesService.observeFieldScoped("currentProfile", FuncName(OnCurrentProfileChanged))
end function

function OnFocusChange() as void
Expand Down Expand Up @@ -47,7 +47,7 @@ function OnRowItemSelected() as void
end function

function OnCurrentProfileChanged() as void
currentProfile = m.profiles.currentProfile
currentProfile = m.profilesService.currentProfile
if currentProfile = invalid
return
end if
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProfileScreen" extends="Group" includes="AutoBind,Focus">
<interface>
<field id="navBar" type="node" bind="/NavBar" />
<field id="profiles" type="node" bind="/Profiles" />
<field id="profilesService" type="node" bind="/ProfilesService" />
<field id="appController" type="node" bind="/AppController" />
</interface>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function OnSearchContentReady() as void
m.rowlist.UnobserveFieldScoped("someContentReady")

if not m.rowlist.someContentReady
DialogUtils.ShowDialog("We didn't find any results for your search. Please try again with a different query or different filters.", "No results found")
DialogUtils.ShowDialog(Tr(Locale.Dialogs.NoResultsFoundMessage), Tr(Locale.Dialogs.NoResultsFound))
m.rowlist.feeds = invalid
m.rowlist.focusable = false
HideLoadingScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function OnInvidiousPublicInstancesTaskResults(output as object) as void
error = ErrorUtils.Format(error)
LogError(output.error)

message = `Failed to load Invidious public instances\n${error}`
DialogUtils.ShowDialog(message, "Invidious public instances load error", true)
message = Tr(Locale.Dialogs.FailedToLoadInvidiousPublicInstances) + `\n${error}`
DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.InvidiousPublicInstancesLoadError), true)

m.failedLabel.visible = true
m.refreshButton.visible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<field id="applicationInfo" type="node" />
<field id="preferences" type="node" />
<field id="webServer" type="node" />
<field id="profiles" type="node" />
<field id="profilesService" type="node" />

<field id="authToken" type="assocarray" onChange="OnAuthTokenChange" />
<field id="apiDefinitions" type="assocarray" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ namespace Invidious
end if

LogInfo("Deleting Invidious token...")
m.invidiousNode.profiles@.LogoutWithAccessToken(authToken.token)
m.invidiousNode.profilesService@.LogoutWithAccessToken(authToken.token)
end function

function VerifyTokenScope(token as string) as boolean
Expand Down
20 changes: 10 additions & 10 deletions playlet-lib/src/components/Services/LoungeService/LoungeApi.bs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ class LoungeApi

response = request.Await()
if not response.IsSuccess()
error = `Failed to get screen id. Please restart playlet to use the cast function.\n${response.ErrorMessage()}`
error = Tr(Locale.Dialogs.LoungeFailedToGetScreenId) + `\n${response.ErrorMessage()}`
LogError(error)
DialogUtils.ShowDialog(error, "Lounge service setup error")
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError))
return invalid
end if

id = response.Text()
if not IsString(id)
error = `Failed to get screen id. Please restart playlet to use the cast function.\nNot a valid screen id: ${id}`
error = Tr(Locale.Dialogs.LoungeFailedToGetScreenId) + `\n` = Tr(Locale.Dialogs.LoungeNotAValidScreenId).Replace("%1", `${id}`)
LogError(error)
DialogUtils.ShowDialog(error, "Lounge service setup error")
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError))
return invalid
end if

Expand All @@ -132,18 +132,18 @@ class LoungeApi

response = request.Await()
if not response.IsSuccess()
error = `Failed to get lounge token. Please restart playlet to use the cast function.\n${response.ErrorMessage()}`
error = Tr(Locale.Dialogs.LoungeFailedToGetLoungeToken) + `\n${response.ErrorMessage()}`
LogError(error)
DialogUtils.ShowDialog(error, "Lounge service setup error")
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError))
return invalid
end if

json = response.Json()
screens = json.screens
if not IsArray(screens) or screens.Count() <> 1
error = `Failed to get lounge token. Please restart playlet to use the cast function.\nInvalid response: ${json}`
error = Tr(Locale.Dialogs.LoungeFailedToGetLoungeToken) + `\n` + Tr(Locale.Dialogs.LoungeInvalidResponse).Replace("%1", `${json}`)
LogError(error)
DialogUtils.ShowDialog(error, "Lounge service setup error")
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError))
return invalid
end if

Expand Down Expand Up @@ -178,9 +178,9 @@ class LoungeApi

response = request.Await()
if not response.IsSuccess()
error = `Failed to get session data. Please restart playlet to use the cast function.\n${response.ErrorMessage()}`
error = Tr(Locale.Dialogs.LoungeFailedToGetSessionData) + `\n${response.ErrorMessage()}`
LogError(error)
DialogUtils.ShowDialog(error, "Lounge service setup error")
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError))
return false
end if

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function LoadProfilesFromRegistry()

if profileNodes.Count() > 0
AsyncTask.Start(Tasks.ProfilesVerifyTokensTask, {
profiles: m.top
profilesService: m.top
invidious: m.invidious
profileNodes: profileNodes
})
Expand Down Expand Up @@ -220,7 +220,6 @@ function LogoutWithProfile(profile as object) as void
m.top.onProfileLogout = true

AsyncTask.Start(Tasks.ProfilesInvidiousUnregisterTokenTask, {
profiles: m.top
invidious: m.invidious
profileNodes: [profile]
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="Profiles" extends="Node" includes="AutoBind">
<component name="ProfilesService" extends="Node" includes="AutoBind">
<interface>
<!--
The version of the profiles. This is used to determine if the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "pkg:/components/Services/Invidious/InvidiousService.bs"

@asynctask
function ProfilesVerifyTokensTask(input as object) as object
profilesNode = input.profiles
profilesNode = input.profilesService
invidiousNode = input.invidious
profileContentNodes = input.profileNodes

Expand All @@ -27,12 +27,8 @@ function ProfilesVerifyTokensTask(input as object) as object
end for
profileNames = profileNames.join(", ")

message = `It looks like you are logged in to Invidious, but do not have the required permissions.
For that reason, we have logged you out from the following profiles: ${profileNames}
Please log in again.
This can happen when Playlet is updated with new features.
We apologize for the inconvenience.`
DialogUtils.ShowDialog(message, "User logged out")
message = Tr(Locale.Dialogs.UserLoggedOutMessage).Replace("\n", `\n`).Replace("%1", profileNames)
DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.UserLoggedOut))

return invalid
end function
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ function HandleFeedLoadErrorDialog(error as object, rowList as object) as void
if rowList.hasField("dispose") and rowList.dispose
return
end if
DialogUtils.ShowDialog(error, "Failed to load feed", true)
DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.FailedToLoadFeed), true)
end function
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Http
super()

task = server.task
m.profilesNode = task.profiles
m.profilesNode = task.profilesService
m.invidiousNode = task.invidious
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode)
end function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Http
function new(server as object)
super()

m.profilesNode = server.task.profiles
m.profilesNode = server.task.profilesService
m.profilesContent = m.profilesNode.content.getChild(0)
end function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Http
m.applicationInfoNode = task.applicationInfo
m.invidiousNode = task.invidious
m.preferencesNode = task.preferences
m.profilesNode = task.profiles
m.profilesNode = task.profilesService
end function

@get("/api/state")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function SetupRoutes(server as object)
etags = new Http.EtagUtils()
server.UseRouter(new Http.HttpStaticFilesRouter("/", "libpkg:/www", etags, { staticFiles: true }))
server.UseRouter(new Http.HttpStaticFilesRouter("/config", "libpkg:/config", etags, { staticFiles: true }))
server.UseRouter(new Http.HttpStaticFilesRouter("/locale", "libpkg:/locale", etags, { staticFiles: true }))
server.UseRouter(new Http.HttpStaticFilesRouter("/logs", "cachefs:/logs", etags, { fsCheck: true }))
#if DEBUG
server.UseRouter(new Http.RegistryRouter())
Expand Down
Loading

0 comments on commit 42dadec

Please sign in to comment.