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

+112
View File
@@ -1,4 +1,5 @@
namespace Locale
@locale
enum NavBar
Profile = "Profile"
@@ -12,11 +13,14 @@ namespace Locale
@locale
enum Buttons
OK = "OK"
Activate = "Activate"
InUse = "In Use"
Login = "Login"
Logout = "Logout"
Close = "Close"
exit = "Exit"
Cancel = "Cancel"
Filters = "Filters"
Edit = "Edit"
Save = "Save"
@@ -25,6 +29,7 @@ namespace Locale
Unsubscribe = "Unsubscribe"
MoveUp = "Move up"
MoveDown = "Move down"
Refresh = "Refresh"
end enum
@locale
@@ -57,5 +62,112 @@ namespace Locale
InvidiousCustomInstance = "Invidious custom instance"
InvidiousOr = "Or"
InvidiousPublicInstances = "Invidious public instances"
Name = "name"
Version = "version"
Users = "users"
SignUp = "signup"
Location = "location"
Health = "health"
end enum
@locale
enum Genetic
Yes = "Yes"
No = "No"
end enum
@locale
enum InvidiousTesting
Test = "Test"
TestingInstance = "Testing %1"
Status = "Status"
TestDuration = "Test duration"
Details = "Details"
ValidUrl = "Valid URL"
InstanceReachable = "Instance reachable"
FetchVideoDetails = "Fetch video details"
FetchVideoComments = "Fetch video comments"
FetchVideoCaptions = "Fetch video captions"
FetchVideoThumbnails = "Fetch video thumbnails"
PressOkForDetails = "Press 'OK' for details"
UrlMustStartWith = "Url must start with http:// or https://"
UrlMustNotEndWith = "Url must not end with /"
UrlSeemsValid = "The url seems to be of a valid format"
InvalidJsonFrom = "Invalid JSON from %1"
InvalidJsonFromCouldntRead = "Invalid json from %1 (couldn't read %2)"
TheInstanceIsReachableAndRunning = "The instance is reachable and running %1 version %2"
TheInstanceCanFetchVideoDetails = "The instance can fetch video details for ID %1 (%2)"
TheInstanceCanFetchVideoComments = "The instance can fetch video comments for ID %1 (%2 comments)"
InvalidCaptionDataContentType = "Invalid caption data from %1 (Content-Type is not text/vtt)"
InvalidCaptionDataNotWebVtt = "Invalid caption data from %1 (response is not a valid vtt file)"
ExpectedTextNotFoundInCaptionData = "Did not find expected text in caption data from %1"
TheInstanceCanFetchVideoCaptions = "The instance can fetch video %1 captions for ID %2"
NoThumbnailsFoundInJson = "No thumbnails found in json from %1"
ThumbnailNotReachable = "%1 is not reachable"
InvalidThumbnailData = "Invalid thumbnail data %1 (Content-Type is not image/*)"
TheInstanceCanFetchVideoThumbnails = "The instance can fetch video thumbnail for ID %1 (%2)"
Passed = "Passed"
Failed = "Failed"
end enum
@locale
enum RowCell
ZeroSubscribers = "0 subscribers"
OneSubscriber = "1 subscriber"
NSubscribers = "^n subscribers"
ZeroVideos = "0 videos"
OneVideo = "1 video"
NVideos = "^n videos"
ZeroViews = "0 views"
OneView = "1 view"
NViews = "^n views"
UpdatedZeroSecondsAgo = "Updated 0 seconds ago"
UpdatedOneSecondAgo = "Updated 1 second ago"
UpdatedNSecondsAgo = "Updated ^n seconds ago"
UpdatedOneMinuteAgo = "Updated 1 minute ago"
UpdatedNMinutesAgo = "Updated ^n minutes ago"
UpdatedOneHourAgo = "Updated 1 hour ago"
UpdatedNHoursAgo = "Updated ^n hours ago"
UpdatedOneDayAgo = "Updated 1 day ago"
UpdatedNDaysAgo = "Updated ^n days ago"
UpdatedOneWeekAgo = "Updated 1 week ago"
UpdatedNWeeksAgo = "Updated ^n weeks ago"
UpdatedOneMonthAgo = "Updated 1 month ago"
UpdatedNMonthsAgo = "Updated ^n months ago"
UpdatedOneYearAgo = "Updated 1 year ago"
UpdatedNYearsAgo = "Updated ^n years ago"
OneYearAgo = "1 year ago"
NYearsAgo = "^n years ago"
OneMonthAgo = "1 month ago"
NMonthsAgo = "^n months ago"
OneWeekAgo = "1 week ago"
NWeeksAgo = "^n weeks ago"
NDaysAgo = "^n days ago"
OneHourAgo = "1 hour ago"
NHoursAgo = "^n hours ago"
OneMinuteAgo = "1 minute ago"
NMinutesAgo = "^n minutes ago"
PremieringNow = "Premiering now"
PremieresInOneSecond = "Premieres in 1 second"
PremieresInNSeconds = "Premieres in ^n seconds"
PremieresInOneMinute = "Premieres in 1 minute"
PremieresInNMinutes = "Premieres in ^n minutes"
PremieresInOneHour = "Premieres in 1 hour"
PremieresInNHours = "Premieres in ^n hours"
PremieresInOneDay = "Premieres in 1 day"
PremieresInNDays = "Premieres in ^n days"
Live = "LIVE"
Upcoming = "UPCOMING"
end enum
end namespace
@@ -0,0 +1,46 @@
' TODO:P2 Translations left
' - Some error messages
' - Settings file
' - Remote screen
' - Web app
' - Loading messages
import "pkg:/source/utils/MathUtils.bs"
namespace LocaleUtils
function GetPluralString(c as integer, zeroString as string, oneString as string, pluralString as string) as string
if c = 0
return Tr(zeroString)
else if c = 1
return Tr(oneString)
else
return Tr(pluralString).Replace("^n", c.toStr())
end if
end function
function GetFormattedPluralString(c as integer, zeroString as string, oneString as string, pluralString as string) as string
if c = 0
return Tr(zeroString)
else if c = 1
return Tr(oneString)
else
if c < 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr())
end if
c = c / 1000
if c < 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "K")
end if
c = c / 1000
if c < 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "M")
end if
c = c / 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "B")
end if
end function
end namespace
@@ -20,4 +20,12 @@ namespace MathUtils
return Max(Min(value, maxValue), minValue)
end function
function FormatFloat(X as float) as float
X = X * 10
X = X + 0.5
X = Fix(X)
X = X / 10
return X
end function
end namespace
-48
View File
@@ -34,54 +34,6 @@ namespace TimeUtils
return formattedTime
end function
function GetFormattedTimeLeft(unixTimestamp as dynamic) as string
if unixTimestamp = invalid
return "N/A"
end if
currentTime = TimeUtils.Now().AsSeconds()
timeLeft = unixTimestamp - currentTime
if timeLeft <= 0
return "now"
end if
if timeLeft < 60
result = `${timeLeft} second`
if timeLeft > 1
result += "s"
end if
return result
end if
timeLeft = timeLeft / 60.0
if timeLeft < 60
timeLeft = Cint(timeLeft)
result = `${timeLeft} minute`
if timeLeft > 1
result += "s"
end if
return result
end if
timeLeft = timeLeft / 60.0
if timeLeft < 24
timeLeft = Cint(timeLeft)
result = `${timeLeft} hour`
if timeLeft > 1
result += "s"
end if
return result
else
timeLeft = timeLeft / 24.0
timeLeft = Cint(timeLeft)
result = `${timeLeft} day`
if timeLeft > 1
result += "s"
end if
return result
end if
end function
function Now() as object
this = m.now
if this = invalid
@@ -17,22 +17,6 @@ namespace Tests
m.assertEqual(TimeUtils.GetFormattedTime(length), formattedString)
end function
@it("formats the time left correctly")
@params(invalid, "N/A")
@params(-1, "now")
@params(0, "now")
@params(1, "1 second")
@params(7, "7 seconds")
@params(8285, "2 hours")
@params(1282085, "15 days")
function _(length as dynamic, formattedString as string)
time = invalid
if length <> invalid
time = TimeUtils.Now().AsSeconds() + length
end if
m.assertEqual(TimeUtils.GetFormattedTimeLeft(time), formattedString)
end function
end class
end namespace