More translation work

This commit is contained in:
Brahim Hadriche committed 2024-03-23 00:19:15 -04:00
1 parent 37e429f648
commit 25330a6494
13 files changed
+293 -177

No files matched your search

+20 -12
View File
@@ -472,18 +472,6 @@
<source>^n views</source> <source>^n views</source>
<translation>^n views</translation> <translation>^n views</translation>
</message> </message>
<message>
<source>Updated 0 seconds ago</source>
<translation>Updated 0 seconds ago</translation>
</message>
<message>
<source>Updated 1 second ago</source>
<translation>Updated 1 second ago</translation>
</message>
<message>
<source>Updated ^n seconds ago</source>
<translation>Updated ^n seconds ago</translation>
</message>
<message> <message>
<source>Updated 1 minute ago</source> <source>Updated 1 minute ago</source>
<translation>Updated 1 minute ago</translation> <translation>Updated 1 minute ago</translation>
@@ -1048,5 +1036,25 @@
<source>Drop a YouTube link here</source> <source>Drop a YouTube link here</source>
<translation>Drop a YouTube link here</translation> <translation>Drop a YouTube link here</translation>
</message> </message>
<message>
<source>Play on %1</source>
<translation>Play on %1</translation>
</message>
<message>
<source>Queue on %1</source>
<translation>Queue on %1</translation>
</message>
<message>
<source>Open on %1</source>
<translation>Open on %1</translation>
</message>
<message>
<source>Open in Invidious</source>
<translation>Open in Invidious</translation>
</message>
<message>
<source>Start at</source>
<translation>Start at</translation>
</message>
</context> </context>
</TS> </TS>
+20 -12
View File
@@ -469,18 +469,6 @@
<source>^n views</source> <source>^n views</source>
<translation>^n vues</translation> <translation>^n vues</translation>
</message> </message>
<message>
<source>Updated 0 seconds ago</source>
<translation>Mis à jour il y a 0 seconde</translation>
</message>
<message>
<source>Updated 1 second ago</source>
<translation>Mis à jour il y a 1 seconde</translation>
</message>
<message>
<source>Updated ^n seconds ago</source>
<translation>Mis à jour il y a ^n secondes</translation>
</message>
<message> <message>
<source>Updated 1 minute ago</source> <source>Updated 1 minute ago</source>
<translation>Mis à jour il y a 1 minute</translation> <translation>Mis à jour il y a 1 minute</translation>
@@ -1046,5 +1034,25 @@
<source>Drop a YouTube link here</source> <source>Drop a YouTube link here</source>
<translation>Déposez un lien YouTube ici</translation> <translation>Déposez un lien YouTube ici</translation>
</message> </message>
<message>
<source>Play on %1</source>
<translation>Lire sur %1</translation>
</message>
<message>
<source>Queue on %1</source>
<translation>Mettre en file d'attente sur %1</translation>
</message>
<message>
<source>Open on %1</source>
<translation>Ouvrir sur %1</translation>
</message>
<message>
<source>Open in Invidious</source>
<translation>Ouvrir dans Invidious</translation>
</message>
<message>
<source>Start at</source>
<translation>Démarrer à</translation>
</message>
</context> </context>
</TS> </TS>
+5 -3
View File
@@ -156,9 +156,6 @@ namespace Locale
OneView = "1 view" OneView = "1 view"
NViews = "^n views" NViews = "^n views"
UpdatedZeroSecondsAgo = "Updated 0 seconds ago"
UpdatedOneSecondAgo = "Updated 1 second ago"
UpdatedNSecondsAgo = "Updated ^n seconds ago"
UpdatedOneMinuteAgo = "Updated 1 minute ago" UpdatedOneMinuteAgo = "Updated 1 minute ago"
UpdatedNMinutesAgo = "Updated ^n minutes ago" UpdatedNMinutesAgo = "Updated ^n minutes ago"
UpdatedOneHourAgo = "Updated 1 hour ago" UpdatedOneHourAgo = "Updated 1 hour ago"
@@ -356,6 +353,11 @@ namespace Locale
ErrorWithLogin = "Error with login, please refresh the page." ErrorWithLogin = "Error with login, please refresh the page."
Profiles = "Profiles" Profiles = "Profiles"
DropYouTubeLinkHere = "Drop a YouTube link here" DropYouTubeLinkHere = "Drop a YouTube link here"
PlayOn = "Play on %1"
QueueOn = "Queue on %1"
OpenOn = "Open on %1"
OpenInInvidious = "Open in Invidious"
StartAt = "Start at"
end enum end enum
end namespace end namespace
+12 -36
View File
@@ -1,32 +1,7 @@
' TODO:P2 Translations left: ' TODO:P2 Translations left:
' - Context menu ' - Context menu
' - Search filters ' - Search filters (App+Web)
' - Loading messages ' - Loading messages
' Web app:
' - Video publish text
' - Video video count
' - Video live/upcoming/premiere indicator
' - Playlist updated time
' - Playlist video count
' - Channel sub count
' - Video dialog options
' - Play on
' - Queue on
' - Open in Invidious
' - Cancel
' - Channel dialog options
' - Open on
' - Open in Invidious
' - Cancel
' - Playlist dialog options
' - Play on
' - Queue on
' - Open on
' - Open in Invidious
' - Cancel
import "pkg:/source/utils/MathUtils.bs" import "pkg:/source/utils/MathUtils.bs"
@@ -48,21 +23,22 @@ namespace LocaleUtils
else if c = 1 else if c = 1
return Tr(oneString) return Tr(oneString)
else else
if c < 1000 c! = c
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr()) if c! < 1000
return Tr(pluralString).Replace("^n", c!.toStr())
end if end if
c = c / 1000 c! = c! / 1000
if c < 1000 if c! < 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "K") return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c!).toStr() + " K")
end if end if
c = c / 1000 c! = c! / 1000
if c < 1000 if c! < 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "M") return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c!).toStr() + " M")
end if end if
c = c / 1000 c! = c! / 1000
return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c).toStr() + "B") return Tr(pluralString).Replace("^n", MathUtils.FormatFloat(c!).toStr() + " B")
end if end if
end function end function
+39
View File
@@ -1,5 +1,6 @@
import { tr } from "lib/Stores"; import { tr } from "lib/Stores";
import { PlayletApi } from "./PlayletApi"; import { PlayletApi } from "./PlayletApi";
import { get } from "svelte/store";
export async function fetchLocale(locale: string) { export async function fetchLocale(locale: string) {
try { try {
@@ -35,3 +36,41 @@ export async function fetchLocale(locale: string) {
console.error(error); console.error(error);
} }
} }
export function getPluralString(c: number, zeroString: string, oneString: string, pluralString: string) {
const trFn = get(tr);
c = c || 0;
if (c === 0) {
return trFn(zeroString);
} else if (c === 1) {
return trFn(oneString);
} else {
return trFn(pluralString).replace("^n", c.toString());
}
}
export function getFormattedPluralString(c: number, zeroString: string, oneString: string, pluralString: string) {
const trFn = get(tr);
c = c || 0;
if (c === 0) {
return trFn(zeroString);
} else if (c === 1) {
return trFn(oneString);
} else {
if (c < 1000) {
return trFn(pluralString).replace("^n", parseFloat(c.toFixed(1)).toString());
}
c = c / 1000;
if (c < 1000) {
return trFn(pluralString).replace("^n", parseFloat(c.toFixed(1)).toString() + " K");
}
c = c / 1000;
if (c < 1000) {
return trFn(pluralString).replace("^n", parseFloat(c.toFixed(1)).toString() + " M");
}
c = c / 1000;
return trFn(pluralString).replace("^n", parseFloat(c.toFixed(1)).toString() + " B");
}
}
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { PlayletApi } from "lib/Api/PlayletApi"; import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores"; import { playletStateStore, tr } from "lib/Stores";
import ChannelThumbnail from "./ChannelThumbnail.svelte"; import ChannelThumbnail from "./ChannelThumbnail.svelte";
export let author: string | undefined = undefined; export let author: string | undefined = undefined;
@@ -47,16 +47,16 @@
<div class="flex flex-col"> <div class="flex flex-col">
<div class="join join-vertical m-2"> <div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={openOnTv}> <button class="btn join-item hover:btn-accent" on:click={openOnTv}>
Open on {tvName} {$tr("Open on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}> <button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious {$tr("Open in Invidious")}
</button> </button>
<button class="btn join-item hover:btn-accent">Cancel</button> <button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div> </div>
</div> </div>
</form> </form>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button>Close</button> <button>{$tr("Close")}</button>
</form> </form>
</dialog> </dialog>
@@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getFormattedPluralString } from "lib/Api/Locale";
import ChannelCastDialog from "./ChannelCastDialog.svelte"; import ChannelCastDialog from "./ChannelCastDialog.svelte";
import ChannelThumbnail from "./ChannelThumbnail.svelte"; import ChannelThumbnail from "./ChannelThumbnail.svelte";
@@ -12,6 +13,19 @@
export let type: string = undefined; export let type: string = undefined;
let modal; let modal;
function getSubCountText() {
if (isNaN(subCount) || subCount < 0) {
return "";
}
return getFormattedPluralString(
subCount,
"0 subscribers",
"1 subscriber",
"^n subscribers"
);
}
</script> </script>
<button class="w-60 p-2" on:click={modal.show()}> <button class="w-60 p-2" on:click={modal.show()}>
@@ -19,7 +33,7 @@
<ChannelThumbnail bind:author bind:authorThumbnails /> <ChannelThumbnail bind:author bind:authorThumbnails />
<div class="card-body"> <div class="card-body">
<h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3> <h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3>
<div>{subCount} subscribers</div> <div>{getSubCountText()}</div>
<div>{channelHandle || ""}</div> <div>{channelHandle || ""}</div>
</div> </div>
</div> </div>
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { PlayletApi } from "lib/Api/PlayletApi"; import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores"; import { playletStateStore, tr } from "lib/Stores";
import PlaylistThumbnail from "./PlaylistThumbnail.svelte"; import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
export let title: string | undefined = undefined; export let title: string | undefined = undefined;
@@ -99,22 +99,22 @@
<div class="flex flex-col"> <div class="flex flex-col">
<div class="join join-vertical m-2"> <div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={playOnTv}> <button class="btn join-item hover:btn-accent" on:click={playOnTv}>
Play on {tvName} {$tr("Play on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}> <button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
Queue on {tvName} {$tr("Queue on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={openOnTv}> <button class="btn join-item hover:btn-accent" on:click={openOnTv}>
Open on {tvName} {$tr("Open on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}> <button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious {$tr("Open in Invidious")}
</button> </button>
<button class="btn join-item hover:btn-accent">Cancel</button> <button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div> </div>
</div> </div>
</form> </form>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button>Close</button> <button>{$tr("Close")}</button>
</form> </form>
</dialog> </dialog>
@@ -1,7 +1,8 @@
<script lang="ts"> <script lang="ts">
import { playletStateStore } from "lib/Stores"; import { playletStateStore, tr } from "lib/Stores";
import PlaylistCastDialog from "./PlaylistCastDialog.svelte"; import PlaylistCastDialog from "./PlaylistCastDialog.svelte";
import PlaylistThumbnail from "./PlaylistThumbnail.svelte"; import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
import { get } from "svelte/store";
export let title: string | undefined = undefined; export let title: string | undefined = undefined;
export let author: string | undefined = undefined; export let author: string | undefined = undefined;
@@ -21,7 +22,7 @@
invidiousInstance = value?.invidious?.current_instance; invidiousInstance = value?.invidious?.current_instance;
}); });
function GetUpdatedText(updated) { function getUpdatedText() {
if (typeof updated !== "number") { if (typeof updated !== "number") {
return ""; return "";
} }
@@ -31,34 +32,49 @@
return ""; return "";
} }
let count = ""; const trFn = get(tr);
const totalDays = Math.floor(span / 86400); const totalDays = Math.floor(span / 86400);
if (totalDays > 365) { if (totalDays > 365) {
const years = Math.floor(totalDays / 365); const years = Math.floor(totalDays / 365);
count = years > 1 ? `${years} years` : "1 year"; if (years === 1) {
return trFn("Updated 1 year ago");
} else {
return trFn("Updated ^n years ago").replace("^n", years.toString());
}
} else if (totalDays > 30) { } else if (totalDays > 30) {
const months = Math.floor(totalDays / 30); const months = Math.floor(totalDays / 30);
count = months > 1 ? `${months} months` : "1 month"; if (months === 1) {
return trFn("Updated 1 month ago");
} else {
return trFn("Updated ^n months ago").replace("^n", months.toString());
}
} else if (totalDays > 7) { } else if (totalDays > 7) {
const weeks = Math.floor(totalDays / 7); const weeks = Math.floor(totalDays / 7);
count = weeks > 1 ? `${weeks} weeks` : "1 week"; if (weeks === 1) {
return trFn("Updated 1 week ago");
} else {
return trFn("Updated ^n weeks ago").replace("^n", weeks.toString());
}
} else if (totalDays > 1) { } else if (totalDays > 1) {
count = `${totalDays} days`; return trFn("Updated ^n days ago").replace("^n", totalDays.toString());
} else if (span > 3600) { } else if (span > 3600) {
const hours = Math.floor(span / 3600); const hours = Math.floor(span / 3600);
count = hours > 1 ? `${hours} hours` : "1 hour"; if (hours === 1) {
return trFn("Updated 1 hour ago");
} else {
return trFn("Updated ^n hours ago").replace("^n", hours.toString());
}
} else if (span > 60) { } else if (span > 60) {
const minutes = Math.floor(span / 60); const minutes = Math.floor(span / 60);
count = minutes > 1 ? `${minutes} minutes` : "1 minute"; if (minutes === 1) {
return trFn("Updated 1 minute ago");
} else {
return trFn("Updated ^n minutes ago").replace("^n", minutes.toString());
}
} else { } else {
count = span > 1 ? `${span} seconds` : "1 second"; return trFn("Updated 1 minute ago");
} }
if (count === "") {
return "";
}
return `Updated ${count} ago`;
} }
</script> </script>
@@ -74,7 +90,7 @@
<div class="card-body"> <div class="card-body">
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3> <h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
<div class="font-semibold">{author}</div> <div class="font-semibold">{author}</div>
<div>{GetUpdatedText(updated)}</div> <div>{getUpdatedText()}</div>
</div> </div>
</div> </div>
</button> </button>
@@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getPluralString } from "lib/Api/Locale";
export let title: string | undefined = undefined; export let title: string | undefined = undefined;
export let videoCount: number | undefined = undefined; export let videoCount: number | undefined = undefined;
export let playlistThumbnail: string | undefined = undefined; export let playlistThumbnail: string | undefined = undefined;
@@ -33,6 +35,14 @@
} }
thumbnailUrl = url; thumbnailUrl = url;
} }
function getVideoCountText() {
if (isNaN(videoCount) || videoCount < 0) {
return "";
}
return getPluralString(videoCount, "0 videos", "1 video", "^n videos");
}
</script> </script>
<figure class="relative"> <figure class="relative">
@@ -47,6 +57,6 @@
<div <div
class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2" class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2"
> >
{videoCount} videos {getVideoCountText()}
</div> </div>
</figure> </figure>
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { PlayletApi } from "lib/Api/PlayletApi"; import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores"; import { playletStateStore, tr } from "lib/Stores";
import VideoStartAt from "./VideoStartAt.svelte"; import VideoStartAt from "./VideoStartAt.svelte";
import VideoThumbnail from "./VideoThumbnail.svelte"; import VideoThumbnail from "./VideoThumbnail.svelte";
@@ -109,19 +109,19 @@
/> />
<div class="join join-vertical m-2"> <div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={playOnTv}> <button class="btn join-item hover:btn-accent" on:click={playOnTv}>
Play on {tvName} {$tr("Play on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}> <button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
Queue on {tvName} {$tr("Queue on %1").replace("%1", tvName)}
</button> </button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}> <button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious {$tr("Open in Invidious")}
</button> </button>
<button class="btn join-item hover:btn-accent">Cancel</button> <button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div> </div>
</div> </div>
</form> </form>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button>Close</button> <button>{$tr("Close")}</button>
</form> </form>
</dialog> </dialog>
+117 -76
View File
@@ -1,14 +1,17 @@
<script lang="ts"> <script lang="ts">
import { playletStateStore } from "lib/Stores"; import { playletStateStore, tr } from "lib/Stores";
import VideoCastDialog from "./VideoCastDialog.svelte"; import VideoCastDialog from "./VideoCastDialog.svelte";
import VideoThumbnail from "./VideoThumbnail.svelte"; import VideoThumbnail from "./VideoThumbnail.svelte";
import ChannelCastDialog from "./ChannelCastDialog.svelte"; import ChannelCastDialog from "./ChannelCastDialog.svelte";
import { get } from "svelte/store";
import { getFormattedPluralString } from "lib/Api/Locale";
export let title: string | undefined = undefined; export let title: string | undefined = undefined;
export let videoId: string | undefined = undefined; export let videoId: string | undefined = undefined;
export let author: string | undefined = undefined; export let author: string | undefined = undefined;
export let videoThumbnails: any[] | undefined = undefined; export let videoThumbnails: any[] | undefined = undefined;
export let viewCount: number | undefined = undefined; export let viewCount: number | undefined = undefined;
export let published: number = undefined;
export let publishedText: string | undefined = undefined; export let publishedText: string | undefined = undefined;
export let isUpcoming: boolean = undefined; export let isUpcoming: boolean = undefined;
export let premiereTimestamp: number | undefined = undefined; export let premiereTimestamp: number | undefined = undefined;
@@ -30,8 +33,6 @@
// svelte-ignore unused-export-let // svelte-ignore unused-export-let
export let viewCountText: string = undefined; export let viewCountText: string = undefined;
// svelte-ignore unused-export-let // svelte-ignore unused-export-let
export let published: number = undefined;
// svelte-ignore unused-export-let
export let premium: boolean = undefined; export let premium: boolean = undefined;
// svelte-ignore unused-export-let // svelte-ignore unused-export-let
export let index: number = undefined; export let index: number = undefined;
@@ -47,10 +48,10 @@
}); });
function getViewCountDateText() { function getViewCountDateText() {
if (isUpcoming) { if (isUpcoming && premiereTimestamp) {
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`; return getPremieresInText();
} }
const pubText = publishedText || ""; const pubText = getPublishedText();
const viewCountText = formatViewCount(viewCount); const viewCountText = formatViewCount(viewCount);
if (pubText === "" && viewCountText === "") { if (pubText === "" && viewCountText === "") {
@@ -60,82 +61,122 @@
return `${pubText} • ${viewCountText}`; return `${pubText} • ${viewCountText}`;
} }
function getFormattedTimeLeft(unixTimestamp) {
if (unixTimestamp === "invalid") {
return "N/A";
}
const currentTime = Math.floor(Date.now() / 1000);
let timeLeft = unixTimestamp - currentTime;
if (timeLeft <= 0) {
return "now";
}
if (timeLeft < 60) {
let result = `${timeLeft} second`;
if (timeLeft > 1) {
result += "s";
}
return result;
}
timeLeft = timeLeft / 60.0;
if (timeLeft < 60) {
timeLeft = Math.floor(timeLeft);
let result = `${timeLeft} minute`;
if (timeLeft > 1) {
result += "s";
}
return result;
}
timeLeft = timeLeft / 60.0;
if (timeLeft < 24) {
timeLeft = Math.floor(timeLeft);
let result = `${timeLeft} hour`;
if (timeLeft > 1) {
result += "s";
}
return result;
} else {
timeLeft = timeLeft / 24.0;
timeLeft = Math.floor(timeLeft);
let result = `${timeLeft} day`;
if (timeLeft > 1) {
result += "s";
}
return result;
}
}
function formatViewCount(viewCount) { function formatViewCount(viewCount) {
if (isNaN(viewCount)) { if (isNaN(viewCount)) {
return ""; return "";
} }
if (viewCount < 1000) { return getFormattedPluralString(viewCount, "0 views", "1 view", "^n views");
return `${formatFloat(viewCount)} views`;
}
viewCount = viewCount / 1000;
if (viewCount < 1000) {
return `${formatFloat(viewCount)}K views`;
}
viewCount = viewCount / 1000;
if (viewCount < 1000) {
return `${formatFloat(viewCount)}M views`;
}
viewCount = viewCount / 1000;
return `${formatFloat(viewCount)}B views`;
} }
function formatFloat(X) { function getPremieresInText() {
X = X * 10; if (!isUpcoming || isNaN(premiereTimestamp)) {
X = X + 0.5; return "";
X = Math.floor(X); }
X = X / 10;
return X; const trFn = get(tr);
const currentTime = Math.floor(Date.now() / 1000);
let timeLeft = premiereTimestamp - currentTime;
if (timeLeft <= 0) {
return trFn("Premiering now");
}
if (timeLeft < 60) {
if (timeLeft === 1) {
return trFn("Premieres in 1 second");
} else {
return trFn("Premieres in ^n seconds").replace(
"^n",
timeLeft.toString()
);
}
}
if (timeLeft < 3600) {
const minutes = Math.floor(timeLeft / 60);
if (minutes === 1) {
return trFn("Premieres in 1 minute");
} else {
return trFn("Premieres in ^n minutes").replace(
"^n",
minutes.toString()
);
}
}
if (timeLeft < 86400) {
const hours = Math.floor(timeLeft / 3600);
if (hours === 1) {
return trFn("Premieres in 1 hour");
} else {
return trFn("Premieres in ^n hours").replace("^n", hours.toString());
}
}
const days = Math.floor(timeLeft / 86400);
if (days === 1) {
return trFn("Premieres in 1 day");
} else {
return trFn("Premieres in ^n days").replace("^n", days.toString());
}
}
function getPublishedText() {
if (isNaN(published)) {
return "";
}
const trFn = get(tr);
const currentTime = Math.floor(Date.now() / 1000);
const span = currentTime - published;
if (span < 1) {
return publishedText || "";
}
const totalDays = Math.floor(span / 86400);
if (totalDays > 365) {
const years = Math.floor(totalDays / 365);
if (years === 1) {
return trFn("1 year ago");
} else {
return trFn("^n years ago").replace("^n", years.toString());
}
} else if (totalDays > 30) {
const months = Math.floor(totalDays / 30);
if (months === 1) {
return trFn("1 month ago");
} else {
return trFn("^n months ago").replace("^n", months.toString());
}
} else if (totalDays > 7) {
const weeks = Math.floor(totalDays / 7);
if (weeks === 1) {
return trFn("1 week ago");
} else {
return trFn("^n weeks ago").replace("^n", weeks.toString());
}
} else if (totalDays > 0) {
if (totalDays === 1) {
return trFn("1 day ago");
} else {
return trFn("^n days ago").replace("^n", totalDays.toString());
}
} else if (span > 3600) {
const hours = Math.floor(span / 3600);
if (hours === 1) {
return trFn("1 hour ago");
} else {
return trFn("^n hours ago").replace("^n", hours.toString());
}
} else if (span > 60) {
const minutes = Math.floor(span / 60);
if (minutes === 1) {
return trFn("1 minute ago");
} else {
return trFn("^n minutes ago").replace("^n", minutes.toString());
}
} else {
return trFn("1 minute ago");
}
} }
</script> </script>
@@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import { tr } from "lib/Stores";
export let checked = false; export let checked = false;
export let lengthSeconds = undefined; export let lengthSeconds = undefined;
export let timestamp = 0; export let timestamp = 0;
@@ -58,7 +60,7 @@
<div class="flex flex-row items-center"> <div class="flex flex-row items-center">
<label class="label justify-start cursor-pointer"> <label class="label justify-start cursor-pointer">
<input type="checkbox" bind:checked class="checkbox" /> <input type="checkbox" bind:checked class="checkbox" />
<span class="label-text m-2">Start at</span> <span class="label-text m-2">{$tr("Start at")}</span>
</label> </label>
<input <input
bind:this={textInputElemet} bind:this={textInputElemet}