Add Quran.locales

This commit is contained in:
0x1eef 2024-05-15 21:47:38 -03:00
parent fcb7aa391a
commit deae96fc4b
3 changed files with 12 additions and 10 deletions

View file

@ -2,3 +2,5 @@
-/tmp/
-/build/
-/.gems/
-/packages/typescript/*/src/*.js
-/packages/typescript/*/src/**/*.js

View file

@ -20,6 +20,10 @@ class Quran {
locale: TLocale;
surahs: Surah[];
static get locales(): Array<TLocale> {
return ["ar", "en"];
}
constructor(self: TQuran) {
this.locale = self.locale;
this.surahs = self.surahs;

View file

@ -1,12 +1,8 @@
import { Quran, TLocale } from "Quran";
(function () {
const LOCALES = ["ar", "en"];
const DEFAULT_LOCALE = "en";
function getUserLocale() {
return (
navigator.languages
.map(s => s.slice(0, 2))
.find(s => LOCALES.includes(s)) || DEFAULT_LOCALE
);
}
location.replace(["", getUserLocale(), ""].join("/"));
const defaultl = "en";
const locale = navigator.languages
.map(s => s.slice(0, 2).toLowerCase())
.find(s => Quran.locales.includes(s as TLocale)) || defaultl;
location.replace(`/${locale}/`);
})();