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");
}
}