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

+39
View File
@@ -1,5 +1,6 @@
import { tr } from "lib/Stores";
import { PlayletApi } from "./PlayletApi";
import { get } from "svelte/store";
export async function fetchLocale(locale: string) {
try {
@@ -35,3 +36,41 @@ export async function fetchLocale(locale: string) {
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">
import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores";
import { playletStateStore, tr } from "lib/Stores";
import ChannelThumbnail from "./ChannelThumbnail.svelte";
export let author: string | undefined = undefined;
@@ -47,16 +47,16 @@
<div class="flex flex-col">
<div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={openOnTv}>
Open on {tvName}
{$tr("Open on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious
{$tr("Open in Invidious")}
</button>
<button class="btn join-item hover:btn-accent">Cancel</button>
<button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div>
</div>
</form>
<form method="dialog" class="modal-backdrop">
<button>Close</button>
<button>{$tr("Close")}</button>
</form>
</dialog>
@@ -1,4 +1,5 @@
<script lang="ts">
import { getFormattedPluralString } from "lib/Api/Locale";
import ChannelCastDialog from "./ChannelCastDialog.svelte";
import ChannelThumbnail from "./ChannelThumbnail.svelte";
@@ -12,6 +13,19 @@
export let type: string = undefined;
let modal;
function getSubCountText() {
if (isNaN(subCount) || subCount < 0) {
return "";
}
return getFormattedPluralString(
subCount,
"0 subscribers",
"1 subscriber",
"^n subscribers"
);
}
</script>
<button class="w-60 p-2" on:click={modal.show()}>
@@ -19,7 +33,7 @@
<ChannelThumbnail bind:author bind:authorThumbnails />
<div class="card-body">
<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>
</div>
@@ -1,6 +1,6 @@
<script lang="ts">
import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores";
import { playletStateStore, tr } from "lib/Stores";
import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
export let title: string | undefined = undefined;
@@ -99,22 +99,22 @@
<div class="flex flex-col">
<div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={playOnTv}>
Play on {tvName}
{$tr("Play on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
Queue on {tvName}
{$tr("Queue on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={openOnTv}>
Open on {tvName}
{$tr("Open on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious
{$tr("Open in Invidious")}
</button>
<button class="btn join-item hover:btn-accent">Cancel</button>
<button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div>
</div>
</form>
<form method="dialog" class="modal-backdrop">
<button>Close</button>
<button>{$tr("Close")}</button>
</form>
</dialog>
@@ -1,7 +1,8 @@
<script lang="ts">
import { playletStateStore } from "lib/Stores";
import { playletStateStore, tr } from "lib/Stores";
import PlaylistCastDialog from "./PlaylistCastDialog.svelte";
import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
import { get } from "svelte/store";
export let title: string | undefined = undefined;
export let author: string | undefined = undefined;
@@ -21,7 +22,7 @@
invidiousInstance = value?.invidious?.current_instance;
});
function GetUpdatedText(updated) {
function getUpdatedText() {
if (typeof updated !== "number") {
return "";
}
@@ -31,34 +32,49 @@
return "";
}
let count = "";
const trFn = get(tr);
const totalDays = Math.floor(span / 86400);
if (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) {
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) {
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) {
count = `${totalDays} days`;
return trFn("Updated ^n days ago").replace("^n", totalDays.toString());
} else if (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) {
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 {
count = span > 1 ? `${span} seconds` : "1 second";
return trFn("Updated 1 minute ago");
}
if (count === "") {
return "";
}
return `Updated ${count} ago`;
}
</script>
@@ -74,7 +90,7 @@
<div class="card-body">
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
<div class="font-semibold">{author}</div>
<div>{GetUpdatedText(updated)}</div>
<div>{getUpdatedText()}</div>
</div>
</div>
</button>
@@ -1,4 +1,6 @@
<script lang="ts">
import { getPluralString } from "lib/Api/Locale";
export let title: string | undefined = undefined;
export let videoCount: number | undefined = undefined;
export let playlistThumbnail: string | undefined = undefined;
@@ -33,6 +35,14 @@
}
thumbnailUrl = url;
}
function getVideoCountText() {
if (isNaN(videoCount) || videoCount < 0) {
return "";
}
return getPluralString(videoCount, "0 videos", "1 video", "^n videos");
}
</script>
<figure class="relative">
@@ -47,6 +57,6 @@
<div
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>
</figure>
@@ -1,6 +1,6 @@
<script lang="ts">
import { PlayletApi } from "lib/Api/PlayletApi";
import { playletStateStore } from "lib/Stores";
import { playletStateStore, tr } from "lib/Stores";
import VideoStartAt from "./VideoStartAt.svelte";
import VideoThumbnail from "./VideoThumbnail.svelte";
@@ -109,19 +109,19 @@
/>
<div class="join join-vertical m-2">
<button class="btn join-item hover:btn-accent" on:click={playOnTv}>
Play on {tvName}
{$tr("Play on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
Queue on {tvName}
{$tr("Queue on %1").replace("%1", tvName)}
</button>
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
Open in Invidious
{$tr("Open in Invidious")}
</button>
<button class="btn join-item hover:btn-accent">Cancel</button>
<button class="btn join-item hover:btn-accent">{$tr("Cancel")}</button>
</div>
</div>
</form>
<form method="dialog" class="modal-backdrop">
<button>Close</button>
<button>{$tr("Close")}</button>
</form>
</dialog>
+117 -76
View File
@@ -1,14 +1,17 @@
<script lang="ts">
import { playletStateStore } from "lib/Stores";
import { playletStateStore, tr } from "lib/Stores";
import VideoCastDialog from "./VideoCastDialog.svelte";
import VideoThumbnail from "./VideoThumbnail.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 videoId: string | undefined = undefined;
export let author: string | undefined = undefined;
export let videoThumbnails: any[] | undefined = undefined;
export let viewCount: number | undefined = undefined;
export let published: number = undefined;
export let publishedText: string | undefined = undefined;
export let isUpcoming: boolean = undefined;
export let premiereTimestamp: number | undefined = undefined;
@@ -30,8 +33,6 @@
// svelte-ignore unused-export-let
export let viewCountText: string = undefined;
// svelte-ignore unused-export-let
export let published: number = undefined;
// svelte-ignore unused-export-let
export let premium: boolean = undefined;
// svelte-ignore unused-export-let
export let index: number = undefined;
@@ -47,10 +48,10 @@
});
function getViewCountDateText() {
if (isUpcoming) {
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`;
if (isUpcoming && premiereTimestamp) {
return getPremieresInText();
}
const pubText = publishedText || "";
const pubText = getPublishedText();
const viewCountText = formatViewCount(viewCount);
if (pubText === "" && viewCountText === "") {
@@ -60,82 +61,122 @@
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) {
if (isNaN(viewCount)) {
return "";
}
if (viewCount < 1000) {
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`;
return getFormattedPluralString(viewCount, "0 views", "1 view", "^n views");
}
function formatFloat(X) {
X = X * 10;
X = X + 0.5;
X = Math.floor(X);
X = X / 10;
return X;
function getPremieresInText() {
if (!isUpcoming || isNaN(premiereTimestamp)) {
return "";
}
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>
@@ -1,4 +1,6 @@
<script lang="ts">
import { tr } from "lib/Stores";
export let checked = false;
export let lengthSeconds = undefined;
export let timestamp = 0;
@@ -58,7 +60,7 @@
<div class="flex flex-row items-center">
<label class="label justify-start cursor-pointer">
<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>
<input
bind:this={textInputElemet}