diff --git a/src/js/lib/t.ts b/src/js/lib/t.ts index bd95f7a..8c525c8 100644 --- a/src/js/lib/t.ts +++ b/src/js/lib/t.ts @@ -18,11 +18,18 @@ export function T(phrases: PhraseMap): TFunction { } export function formatNumber( - locale: TLocale, + locale: TLocale | string, num: number, options = {}, ): string { - const numl = locale.name === "ar" ? "ar-SA" : locale.name; + const name = (() => { + if (typeof locale === "string") { + return locale; + } else { + return locale.name; + } + })(); + const numl = name === "ar" ? "ar-SA" : name; return new Intl.NumberFormat(numl, { maximumFractionDigits: 1, ...options, diff --git a/src/js/loaders/SurahIndexLoader.ts b/src/js/loaders/SurahIndexLoader.ts index 867709d..b160014 100644 --- a/src/js/loaders/SurahIndexLoader.ts +++ b/src/js/loaders/SurahIndexLoader.ts @@ -3,20 +3,13 @@ import { formatNumber } from "~/lib/t"; (function () { const doc = document.documentElement; - const rev = doc - .querySelector("meta[name='revision']")! - .getAttribute("content")!; - const locale = { - name: doc.lang, - direction: doc.dir as "rtl" | "ltr", - displayName: "", - }; - - /* Postman */ const loader: HTMLElement = doc.querySelector(".postman.loader")!; const style: HTMLStyleElement = doc.querySelector(".css.postman")!; const progressBar: HTMLProgressElement = loader.querySelector("progress")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; + const rev = doc + .querySelector("meta[name='revision']")! + .getAttribute("content")!; const fonts = (() => { if (doc.dir === "rtl") { return [ @@ -27,6 +20,7 @@ import { formatNumber } from "~/lib/t"; return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")]; } })(); + postman( item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }), item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }), @@ -34,7 +28,7 @@ import { formatNumber } from "~/lib/t"; item.progress((percent: number) => { progressBar.value = percent; progressNumber.innerText = formatNumber( - locale, + doc.lang, Number(percent.toFixed(0)), ); }), diff --git a/src/js/loaders/SurahStreamLoader.ts b/src/js/loaders/SurahStreamLoader.ts index 623940f..6c008fa 100644 --- a/src/js/loaders/SurahStreamLoader.ts +++ b/src/js/loaders/SurahStreamLoader.ts @@ -3,21 +3,14 @@ import { formatNumber } from "~/lib/t"; (function () { const doc = document.documentElement; - const rev = doc - .querySelector("meta[name='revision']")! - .getAttribute("content")!; - const { surahId } = document.querySelector(".root")!.dataset; - const locale = { - name: doc.lang, - direction: doc.dir as "rtl" | "ltr", - displayName: "", - }; - - /* Postman */ const loader = doc.querySelector(".postman.loader")!; const style = doc.querySelector(".css.postman")!; const progressBar = loader.querySelector("progress")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; + const { surahId } = document.querySelector(".root")!.dataset; + const rev = doc + .querySelector("meta[name='revision']")! + .getAttribute("content")!; const fonts = (() => { if (doc.dir === "rtl") { return [ @@ -29,6 +22,7 @@ import { formatNumber } from "~/lib/t"; return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")]; } })(); + postman( item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }), item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }), @@ -41,7 +35,7 @@ import { formatNumber } from "~/lib/t"; item.progress((percent: number) => { progressBar.value = percent; progressNumber.innerText = formatNumber( - locale, + doc.lang, Number(percent.toFixed(0)), ); }),