| Name | Message | Date |
|---|---|---|
| 📁 assets | 1 month ago | |
| 📁 components | 1 month ago | |
| 📄 birdnet.worker.ts | 1 month ago | |
| 📄 history.ts | 1 month ago | |
| 📄 index.ts | 1 month ago | |
| 📄 labels.ts | 1 month ago | |
| 📄 types.ts | 1 month ago |
📄
src/lib/labels.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { readable } from "svelte/store";
import type { BirdLabel } from "./types";
const supportedLanguages = [
"af",
"ar",
"cs",
"da",
"de",
"en_uk",
"en_us",
"es",
"fi",
"fr",
"hu",
"it",
"ja",
"ko",
"nl",
"no",
"pl",
"pt",
"ro",
"ru",
"sk",
"sl",
"sv",
"th",
"tr",
"uk",
"zh",
] as const;
function resolveLocale(): Array<(typeof supportedLanguages)[number]> {
if (typeof navigator === "undefined") return ["en_us"];
const navigatorLanguages = navigator.languages.map((l) =>
l.replace("-", "_").toLowerCase()
);
const foundLanguages = navigatorLanguages.flatMap(
(n) => supportedLanguages.find((s) => s.startsWith(n)) ?? [],
);
if (!foundLanguages.includes("en_us")) {
foundLanguages.push("en_us");
}
return foundLanguages;
}
async function fetchLabels(
locale: (typeof supportedLanguages)[number],
): Promise<BirdLabel[]> {
const res = await fetch(`/models/birdnet/labels/${locale}.json`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json() as Promise<BirdLabel[]>;
}
export const labelsStore = readable<BirdLabel[]>([], (set) => {
(async () => {
const locales = resolveLocale();
for (const locale of locales) {
try {
const labels = await fetchLabels(locale);
set(labels);
return;
} catch (e) {
console.warn(e);
}
}
})();
});