Localization part 3 (#333)

* TODO

* TODO

* Add some translations

* Remote screen and settings

* Video player and http client
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-03-19 23:16:39 -04:00
1 parent 9a7db6aab2
commit 7330b321a5
19 files changed
+837 -85

No files matched your search

@@ -126,7 +126,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
return true
end if
end if
dialog = DialogUtils.ShowDialogButtons("Do you want to exit Playlet?", Tr(Locale.Buttons.exit), [Tr(Locale.Buttons.exit), Tr(Locale.Buttons.Cancel)])
dialog = DialogUtils.ShowDialogButtons(Tr(Locale.Dialogs.ExitPlayletQuestion), Tr(Locale.Buttons.exit), [Tr(Locale.Buttons.exit), Tr(Locale.Buttons.Cancel)])
dialog.observeField("buttonSelected", FuncName(OnExitDialog), ["buttonSelected"])
return true
end if
@@ -12,7 +12,7 @@ function Init()
m.top.observeFieldScoped("buttonSelected", FuncName(Close))
scanLabel = m.top.findNode("scanLabel")
scanLabel.text = Tr(Locale.LoginDialog.ScanTheQrCode)
scanLabel.text = Tr(Locale.Dialogs.ScanTheQrCode)
end function
function OnNodeReady()
@@ -21,7 +21,7 @@ function OnNodeReady()
if isValidAddress
m.top.url = `${address}/invidious/login`
else
m.urlLabel.text = Tr(Locale.LoginDialog.IpAddressNotAvailable)
m.urlLabel.text = Tr(Locale.Dialogs.IpAddressNotAvailable)
end if
m.invidious.observeFieldScoped("authToken", FuncName(OnAuthTokenChange))
@@ -7,14 +7,26 @@
</interface>
<children>
<Group id="noBookmarks" visible="false">
<Label
height="720"
width="1280"
font="font:MediumBoldSystemFont"
horizAlign="center"
vertAlign="center"
text="You currently have no bookmarks.&#xA;&#xA;To add bookmarks, long-press 'OK' on a video, playlist or channel.&#xA;&#xA;Please note that Bookmarks is an experimental feature."
wrap="true" />
<LayoutGroup vertAlignment="center" itemSpacings="[25,25]" translation="[180,360]">
<Label
width="920"
horizAlign="center"
font="font:SmallSystemFont"
text="You currently have no bookmarks."
wrap="true" />
<Label
width="920"
horizAlign="center"
font="font:SmallSystemFont"
text="To add bookmarks, long-press 'OK' on a video, playlist or channel."
wrap="true" />
<Label
width="920"
horizAlign="center"
font="font:SmallSystemFont"
text="Please note that Bookmarks is an experimental feature."
wrap="true" />
</LayoutGroup>
</Group>
<Group id="yesBookmarks" visible="false">
<VideoRowList
@@ -4,7 +4,9 @@ import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/MathUtils.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init()
@@ -64,6 +66,11 @@ function OnNodeReady()
m.linkWithWifiPanel.visible = false
m.linkWithTvPanel.observeField("visible", FuncName(OnLinkWithTvPanelVisibleChanged))
m.linkWithTvPanel.visible = false
m.webAppButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
m.linkWithWifiButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
m.linkWithTvButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
OnButtonSizeChange()
end function
function OnFocusChange() as void
@@ -86,6 +93,18 @@ function OnUrlSet()
m.webAppQrCodePoster.text = url
end function
function OnButtonSizeChange()
width1 = m.webAppButton.contentWidth
width2 = m.linkWithWifiButton.contentWidth
width3 = m.linkWithTvButton.contentWidth
width = MathUtils.Max(width1, MathUtils.Max(width2, width3))
m.webAppButton.minimumWidth = width
m.linkWithWifiButton.minimumWidth = width
m.linkWithTvButton.minimumWidth = width
end function
function OnkeyEvent(key as string, press as boolean) as boolean
navigation = NavigationKeyHandler(key, press)
if navigation.handled
@@ -134,12 +153,13 @@ function OnLinkWithWifiPanelVisibleChanged() as void
if connectionInfo.type = "WiFiConnection"
m.wifiNameLabel.text = connectionInfo.ssid
else if connectionInfo.type = "WiredConnection"
m.wifiNameLabel.text = "Wired connection"
m.wifiNameLabel.text = Tr(Locale.RemoteScreen.WiredConnection)
else
m.wifiNameLabel.text = "N/A"
end if
m.wifiInstructionWithDeviceNameLabel.text = `Tap the cast icon and select <Bold>"${m.loungeService.deviceName}"</Bold>`
deviceName = `<Bold>"${m.loungeService.deviceName}"</Bold>`
m.wifiInstructionWithDeviceNameLabel.text = Tr(Locale.RemoteScreen.WifiInstruction3).Replace("%1", deviceName)
end function
function OnLinkWithTvPanelVisibleChanged()
@@ -159,7 +179,7 @@ function GeneratePairingCode()
m.linkCodeTask.cancel = true
end if
m.linkCodeLabel.text = "Loading..."
m.linkCodeLabel.text = Tr(Locale.RemoteScreen.Loading)
m.linkCodeTask = AsyncTask.Start(Tasks.LoungeGenerateManualPairingCodeTask, {
loungeService: m.loungeService
loungeToken: m.loungeService.loungeToken
@@ -187,8 +207,8 @@ function OnLoungeGenerateManualPairingCodeTaskResult(output as object) as void
error = ErrorUtils.Format(error)
LogError(error)
message = `Failed to generate manual pairing code\n${error}`
DialogUtils.ShowDialog(message, "Get TV code fail", true)
message = Tr(Locale.RemoteScreen.FailedToGeneratePairingCode) + `\n${error}`
DialogUtils.ShowDialog(message, Tr(Locale.RemoteScreen.TvCodeError), true)
return
end if
@@ -10,11 +10,13 @@
<Group id="noInternet" visible="false">
<Label
height="720"
width="1280"
font="font:MediumBoldSystemFont"
width="920"
font="font:SmallSystemFont"
horizAlign="center"
vertAlign="center"
text="Could not get IP address: are we connected to the internet?"
wrap="true"
translation="[180,0]"
/>
</Group>
<Group id="yesInternet" visible="false">
@@ -97,23 +99,23 @@
wrap="true"
text="Tap the cast icon and select this device." />
</LayoutGroup>
<Label
text="Roku connected to:"
translation="[0,220]">
<Font role="font" uri="font:SystemFontFile" size="20" />
</Label>
<Label
id="WifiNameLabel"
color="#4287f5"
translation="[0,250]">
<Font role="font" uri="font:BoldSystemFontFile" size="28" />
</Label>
</LayoutGroup>
<Label
text="Roku connected to:"
translation="[0,220]">
<Font role="font" uri="font:SystemFontFile" size="20" />
</Label>
<Label
id="WifiNameLabel"
color="#4287f5"
translation="[0,250]">
<Font role="font" uri="font:BoldSystemFontFile" size="28" />
</Label>
</Group>
<Group id="LinkWithTvPanel"
translation="[700,220]">
<LayoutGroup itemSpacings="[12]">
<LayoutGroup itemSpacings="[12,12,25]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
@@ -132,7 +134,7 @@
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Tap the Chromecast icon." />
text="Tap the cast icon." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
@@ -142,18 +144,15 @@
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Tap &quot;Link with TV code&quot; and enter the code below." />
text="Tap 'Link with TV code' and enter the code below." />
</LayoutGroup>
<Label
id="LinkCodeLabel"
font="font:LargeBoldSystemFont"
color="#4287f5">
<Font role="font" uri="font:BoldSystemFontFile" size="48" />
</Label>
</LayoutGroup>
<Label
id="LinkCodeLabel"
font="font:LargeBoldSystemFont"
color="#4287f5"
translation="[-30,180]"
width="460"
horizAlign="center">
<Font role="font" uri="font:BoldSystemFontFile" size="48" />
</Label>
</Group>
</Group>
</children>
@@ -1,7 +1,9 @@
import "pkg:/source/utils/MathUtils.bs"
import "pkg:/source/utils/Types.bs"
function Init()
m.top.observeField("checkedState", FuncName(OnCheckedStateChange))
m.minItemWidth = m.top.itemSize[0]
end function
function OnValueChange()
@@ -15,3 +17,19 @@ function OnCheckedStateChange() as void
end if
m.top.value = checkedState[0]
end function
function OnTitleChange()
title = m.top.title
' TODO:P2 FIX THIS
' This is a gross estimate of the width of the text, because there isn't
' a simple way to measure using the font, and accurately estimate the width
' of the checkbox. I hate it, but I currently don't have the patience to
' do something else.
' The risks are, if the checkbox is too big, it will look ugly, and if it's
' too small, the text will be scrolling. Either way, it will be usable.
' A better way is to create a Checkbox from scratch, instead of using the CheckList
size = title.len() * 14 - 30
size = MathUtils.Max(size, m.minItemWidth)
m.top.itemSize = [size, m.top.itemSize[1]]
end function
@@ -1,6 +1,6 @@
<component name="Checkbox" extends="CheckList">
<interface>
<field id="title" type="string" alias="checkboxNode.title" />
<field id="title" type="string" alias="checkboxNode.title" onChange="OnTitleChange" />
<field id="value" type="boolean" onChange="OnValueChange" />
</interface>
<children>
@@ -1,6 +1,7 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
function Init()
m.top.focusable = true
@@ -22,5 +23,5 @@ end function
function OnButtonSelected()
SearchHistoryUtils.Clear()
DialogUtils.ShowDialog("Search history cleared.", "Success")
DialogUtils.ShowDialog(Tr(Locale.Settings.SearchHistoryCleared), Tr(Locale.Generic.Success))
end function
@@ -57,7 +57,7 @@ function OnOptionsChange()
for i = 0 to options.Count() - 1
option = options[i].displayText
node = CreateObject("roSGNode", "ContentNode")
node.title = option
node.title = Tr(option)
m.radioButtonListContent.appendChild(node)
end for
@@ -1,3 +1,4 @@
import "pkg:/source/utils/MathUtils.bs"
import "pkg:/source/utils/Types.bs"
function Init()
@@ -21,7 +22,10 @@ function Resize()
width = rect.width + m.top.padding * 2
height = rect.height + m.top.padding * 2
m.top.minWidth = width < m.top.minimumWidth ? m.top.minimumWidth : width
m.top.contentWidth = width
m.top.contentHeight = height
m.top.minWidth = MathUtils.Max(m.top.minimumWidth, width)
m.top.height = height
m.container.translation = [m.top.padding, m.top.padding]
@@ -1,7 +1,9 @@
<component name="SettingCategory" extends="Button">
<interface>
<field id="padding" type="integer" value="15" onChange="Resize" />
<field id="minimumWidth" type="integer" value="280" onChange="Resize" />
<field id="padding" type="float" value="15" onChange="Resize" />
<field id="minimumWidth" type="float" value="280" onChange="Resize" />
<field id="contentWidth" type="float" />
<field id="contentHeight" type="float" />
<field id="displayText" type="string" alias="DisplayTextLabel.text" onChange="Resize" />
<field id="description" type="string" alias="DescriptionLabel.text" onChange="Resize" />
<field id="textColor2" type="Color" value="0xb4b4b4ff" />
@@ -9,13 +11,11 @@
</interface>
<children>
<LayoutGroup id="Container" itemSpacings="[5]">
<SimpleLabel
id="DisplayTextLabel"
fontUri="font:SystemFontFile"
fontSize="34" />
<SimpleLabel id="DescriptionLabel"
fontUri="font:SystemFontFile"
fontSize="18"
<Label id="DisplayTextLabel">
<Font role="font" uri="font:SystemFontFile" size="34" />
</Label>
<Label id="DescriptionLabel"
font="font:SmallestSystemFont"
translation="[0,42]" />
</LayoutGroup>
</children>
@@ -20,7 +20,7 @@ function OnNodeReady()
startX = 150
startY = 100
controlsX = 400
controlsX = 450
categorySpacing = 80
controlSpacing = 30
@@ -73,8 +73,8 @@ end function
function CreateCategoryNode(item as object, container as object, startX as integer, startY as integer) as object
node = container.createChild("SettingCategory")
node.translation = [startX, startY]
node.displayText = item.displayText
node.description = item.description
node.displayText = Tr(item.displayText)
node.description = Tr(item.description)
return {
node: node
rect: node.boundingRect()
@@ -152,30 +152,30 @@ end function
function CreateBooleanControl(item as object, container as object) as object
node = container.createChild("BooleanControl")
node.displayText = item.displayText
node.description = item.description
node.displayText = Tr(item.displayText)
node.description = Tr(item.description)
return node
end function
function CreateRadioControl(item as object, container as object) as object
node = container.createChild("RadioControl")
node.displayText = item.displayText
node.description = item.description
node.displayText = Tr(item.displayText)
node.description = Tr(item.description)
node.options = item.options
return node
end function
function CreateStringControl(item as object, container as object) as object
node = container.createChild("StringControl")
node.displayText = item.displayText
node.description = item.description
node.displayText = Tr(item.displayText)
node.description = Tr(item.description)
return node
end function
function CreateNumberComponent(item as object, container as object) as object
node = container.createChild("NumberControl")
node.displayText = item.displayText
node.description = item.description
node.displayText = Tr(item.displayText)
node.description = Tr(item.description)
if IsInt(item.min)
node.min = item.min
end if
@@ -188,10 +188,10 @@ end function
function CreateRokuComponent(item as object, container as object) as object
node = container.createChild(item.rokuComponent)
if node.hasField("displayText")
node.displayText = item.displayText
node.displayText = Tr(item.displayText)
end if
if node.hasField("description")
node.description = item.description
node.description = Tr(item.description)
end if
return node
end function
@@ -128,9 +128,12 @@ function OnVideoContentTaskResults(output as object) as void
error = ErrorUtils.Format(error)
LogError(error)
videoId = output.task.input.content.videoId
message = `Failed to load video information for ${videoId}\n${error}`
dialog = DialogUtils.ShowTimedDialogButtons(message, "Video load fail", ["Play next video", "Cancel"], 0, 10, true)
title = Tr(Locale.VideoPlayer.VideoLoadError)
message = Tr(Locale.VideoPlayer.VideoLoadErrorMessage).Replace("%1", videoId) + `\n${error}`
buttons = [Tr(Locale.Buttons.PlayNextVideo), Tr(Locale.Buttons.Cancel)]
dialog = DialogUtils.ShowTimedDialogButtons(message, title, buttons, 0, 10, true)
dialog.observeFieldScoped("wasClosed", FuncName(OnVideoContentTaskErrorDialogResponse))
Lounge.SendOnStateChange()
@@ -186,7 +189,7 @@ function Close(_unused as dynamic)
try
m.top.control = "stop"
catch error
DialogUtils.ShowDialog(ErrorUtils.Format(error), "Error closing video", true)
DialogUtils.ShowDialog(ErrorUtils.Format(error), Tr(Locale.VideoPlayer.ErrorClosingVideo), true)
end try
m.top.content = invalid
@@ -263,10 +266,12 @@ function OnVideoPlayerStateChange() as void
end for
end if
title = `Error playing video ${content.videoId}`
title = Tr(Locale.VideoPlayer.ErrorPlayingVideo).Replace("%1", content.videoId)
LogError(title, messageLines)
dialog = DialogUtils.ShowTimedDialogButtons(messageLines, title, ["Play next video", "Cancel"], 0, 10, true)
buttons = [Tr(Locale.Buttons.PlayNextVideo), Tr(Locale.Buttons.Cancel)]
dialog = DialogUtils.ShowTimedDialogButtons(messageLines, title, buttons, 0, 10, true)
dialog.observeFieldScoped("wasClosed", FuncName(OnVideoContentTaskErrorDialogResponse))
m.ignoreNextFinishedState = true
end if