Localization part 2 (#332)

* More localization work

* instance testing translation

* Row cell translations

* safety check
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-03-18 22:53:08 -04:00
1 parent 48993dd9f5
commit 9a7db6aab2
27 files changed
+1201 -270

No files matched your search

@@ -53,14 +53,15 @@ function Close()
end function
function RunTestsTask()
m.titleLabel.text = `Testing ${m.top.instance}`
instance = m.top.instance
m.titleLabel.text = Tr(Locale.InvidiousTesting.TestingInstance).Replace("%1", instance)
if m.testingTask <> invalid
m.testingTask.cancel = true
end if
m.testingTask = AsyncTask.Start(Tasks.InvidiousInstanceTestingTask, {
instance: m.top.instance
instance: instance
listNode: m.testList
})
end function
@@ -68,10 +69,21 @@ end function
function ShowTestDetails(event as object) as void
selected = m.testList.itemSelected
itemContent = m.testList.content.GetChild(selected)
if StringUtils.IsNullOrEmpty(itemContent.details)
details = itemContent.details
if StringUtils.IsNullOrEmpty(details)
return
end if
message = `Status: ${itemContent.state}\nTest duration: ${itemContent.duration}ms\nDetails: ${itemContent.details}`
DialogUtils.ShowDialog(message, `Test: ${itemContent.title}`)
state = itemContent.state
displayStates = {
"passed": Locale.InvidiousTesting.Passed
"failed": Locale.InvidiousTesting.Failed
}
message = Tr(Locale.InvidiousTesting.Status) + ": " + Tr(ValidString(displayStates[state])) + `\n`
message += Tr(Locale.InvidiousTesting.TestDuration) + ": " + `${itemContent.duration}ms\n`
message += Tr(Locale.InvidiousTesting.Details) + ": " + details
title = Tr(Locale.InvidiousTesting.Test) + ": " + itemContent.title
DialogUtils.ShowDialog(message, title)
end function
@@ -12,20 +12,20 @@
opacity="0.5">
</Rectangle>
<Rectangle
width="960"
width="1160"
height="600"
translation="[160,60]"
translation="[60,60]"
color="#242424">
<Label
id="titleLabel"
width="960"
width="1160"
horizAlign="center"
text=""
translation="[0,20]" />
<MarkupGrid
id="testList"
itemSize="[860,40]"
itemSize="[1060,40]"
itemSpacing="[0,20]"
numColumns="1"
numRows="7"
@@ -38,7 +38,7 @@
iconVisible="false"
anchor="[0.5,0.5]"
padding="[30,30]"
translation="[480,530]" />
translation="[580,530]" />
</Rectangle>
</children>
</component>
@@ -13,14 +13,16 @@
translation="[5,0]" />
<Label
id="nameLabel"
width="450"
width="660"
translation="[60,10]" />
<Label
id="detailsLabel"
visible="false"
horizAlign="right"
width="300"
width="400"
text="Press 'OK' for details"
translation="[560,10]" />
translation="[660,12]">
<Font role="font" uri="font:SystemFontFile" size="20" />
</Label>
</children>
</component>
@@ -2,6 +2,7 @@ import "pkg:/components/Services/Invidious/InvidiousService.bs"
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/StringUtils.bs"
@asynctask
@@ -25,12 +26,12 @@ function PrepareTests() as object
content = CreateObject("roSGNode", "ContentNode")
' TODO:P2 test if video data is reachable (head?)
' TODO:P2 test if video data is reachable in proxy mode (local=true)
content.AppendChild(CreateTestNode("Valid url", IsValidUrl))
content.AppendChild(CreateTestNode("Instance reachable", IsReachable))
content.AppendChild(CreateTestNode("Fetch video details", CanFetchVideoDetails))
content.AppendChild(CreateTestNode("Fetch video comments", CanFetchVideoComments))
content.AppendChild(CreateTestNode("Fetch video captions", CanFetchVideoCaptions))
content.AppendChild(CreateTestNode("Fetch video thumbnails", CanFetchVideoThumbails))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.ValidUrl), IsValidUrl))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.InstanceReachable), IsReachable))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.FetchVideoDetails), CanFetchVideoDetails))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.FetchVideoComments), CanFetchVideoComments))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.FetchVideoCaptions), CanFetchVideoCaptions))
content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.FetchVideoThumbnails), CanFetchVideoThumbails))
return content
end function
@@ -73,17 +74,17 @@ function IsValidUrl(instance as string, testNode as object, cancellation as obje
try
if not instance.StartsWith("http://") and not instance.StartsWith("https://")
testNode.state = "failed"
testNode.details = "Url must start with http:// or https://"
testNode.details = Tr(Locale.InvidiousTesting.UrlMustStartWith)
return
end if
if instance.EndsWith("/")
testNode.state = "failed"
testNode.details = "Url must not end with /"
testNode.details = Tr(Locale.InvidiousTesting.UrlMustNotEndWith)
return
end if
testNode.state = "passed"
testNode.details = "The url seems to be of a valid format"
testNode.details = Tr(Locale.InvidiousTesting.UrlSeemsValid)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)
@@ -103,33 +104,33 @@ function IsReachable(instance as string, testNode as object, cancellation as obj
json = response.Json()
if json = invalid
testNode.state = "failed"
testNode.details = `Invalid json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFrom).Replace("%1", url)
return
end if
software = json.software
if software = invalid
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read $.software)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.software")
return
end if
name = software.name
if not IsString(name)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read $.software.name)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.software.name")
return
end if
version = software.version
if not IsString(version)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read software.version)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.software.version")
return
end if
testNode.state = "passed"
testNode.details = `The instance is reachable and running ${name} version ${version}`
testNode.details = Tr(Locale.InvidiousTesting.TheInstanceIsReachableAndRunning).Replace("%1", name).Replace("%2", version)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)
@@ -152,19 +153,19 @@ function CanFetchVideoDetails(instance as string, testNode as object, cancellati
json = response.Json()
if json = invalid
testNode.state = "failed"
testNode.details = `Invalid json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFrom).Replace("%1", url)
return
end if
title = json.title
if not IsString(title)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read title)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.title")
return
end if
testNode.state = "passed"
testNode.details = `The instance can fetch video details for id "${videoId}" (${title})`
testNode.details = Tr(Locale.InvidiousTesting.TheInstanceCanFetchVideoDetails).Replace("%1", videoId).Replace("%2", title)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)
@@ -186,26 +187,26 @@ function CanFetchVideoComments(instance as string, testNode as object, cancellat
json = response.Json()
if json = invalid
testNode.state = "failed"
testNode.details = `Invalid json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFrom).Replace("%1", url)
return
end if
commentCount = json.commentCount
if not IsInt(commentCount)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read commentCount)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.commentCount")
return
end if
comments = json.comments
if not IsArray(comments)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read comments)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFromCouldntRead).Replace("%1", url).Replace("%2", "$.comments")
return
end if
testNode.state = "passed"
testNode.details = `The instance can fetch video comments for id "${videoId}" (${commentCount} comments)`
testNode.details = Tr(Locale.InvidiousTesting.TheInstanceCanFetchVideoComments).Replace("%1", videoId).Replace("%2", `${commentCount}`)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)
@@ -229,25 +230,25 @@ function CanFetchVideoCaptions(instance as string, testNode as object, cancellat
contentType = headers["Content-Type"]
if StringUtils.IsNullOrEmpty(contentType) or not contentType.StartsWith("text/vtt")
testNode.state = "failed"
testNode.details = `Invalid caption data ${url} (Content-Type is not text/vtt)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidCaptionDataContentType).Replace("%1", url)
return
end if
text = response.Text()
if StringUtils.IsNullOrEmpty(text) or not text.StartsWith("WEBVTT")
testNode.state = "failed"
testNode.details = `Invalid caption data from ${url} (response is not a valid vtt file)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidCaptionDataNotWebVtt).Replace("%1", url)
return
end if
if text.InStr(`All right, so here we are, in front of the\nelephants`) = -1
testNode.state = "failed"
testNode.details = `Did not find expected text in caption data from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.ExpectedTextNotFoundInCaptionData).Replace("%1", url)
return
end if
testNode.state = "passed"
testNode.details = `The instance can fetch video ${label} captions for id "${videoId}"`
testNode.details = Tr(Locale.InvidiousTesting.TheInstanceCanFetchVideoCaptions).Replace("%1", label).Replace("%2", videoId)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)
@@ -269,14 +270,14 @@ function CanFetchVideoThumbails(instance as string, testNode as object, cancella
json = response.Json()
if json = invalid
testNode.state = "failed"
testNode.details = `Invalid json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.InvalidJsonFrom).Replace("%1", url)
return
end if
videoThumbnails = json.videoThumbnails
if not IsArray(videoThumbnails) or videoThumbnails.Count() = 0
testNode.state = "failed"
testNode.details = `No thumbnails found in json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.NoThumbnailsFoundInJson).Replace("%1", url)
return
end if
@@ -284,7 +285,7 @@ function CanFetchVideoThumbails(instance as string, testNode as object, cancella
thumbnail = contentNode.thumbnail
if StringUtils.IsNullOrEmpty(thumbnail)
testNode.state = "failed"
testNode.details = `No thumbnail found in json from ${url}`
testNode.details = Tr(Locale.InvidiousTesting.NoThumbnailsFoundInJson).Replace("%1", url)
return
end if
@@ -293,19 +294,19 @@ function CanFetchVideoThumbails(instance as string, testNode as object, cancella
response = HttpClient.Get(thumbnail).NoCache().Cancellation(cancellation).Await()
if not response.IsSuccess()
testNode.state = "failed"
testNode.details = `${thumbnail} is not reachable\n${response.ErrorMessage(false)}`
testNode.details = Tr(Locale.InvidiousTesting.ThumbnailNotReachable).Replace("%1", thumbnail) + `\n` + response.ErrorMessage(false)
return
end if
contentType = response.Headers()["Content-Type"]
if StringUtils.IsNullOrEmpty(contentType) or not contentType.StartsWith("image/")
testNode.state = "failed"
testNode.details = `Invalid thumbnail data ${thumbnail} (Content-Type is not image/*)`
testNode.details = Tr(Locale.InvidiousTesting.InvalidThumbnailData).Replace("%1", thumbnail)
return
end if
testNode.state = "passed"
testNode.details = `The instance can fetch video thumbnail for id "${videoId}" (${thumbnail})`
testNode.details = Tr(Locale.InvidiousTesting.TheInstanceCanFetchVideoThumbnails).Replace("%1", videoId).Replace("%2", thumbnail)
catch e
testNode.state = "failed"
testNode.details = ErrorUtils.Format(e)