-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtolgee.ts
45 lines (41 loc) · 1.03 KB
/
tolgee.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
import {
Tolgee,
DevTools,
type NsFallback,
getFallbackArray,
BackendFetch,
} from '@tolgee/vue';
import { FormatIcu } from '@tolgee/format-icu';
export const createTolgee = () => {
return Tolgee()
.use(DevTools())
.use(FormatIcu())
.use(BackendFetch())
.init({
availableLanguages: ['en', 'de', 'fr', 'cs'],
language: 'en',
apiUrl: import.meta.env.VITE_APP_TOLGEE_API_URL,
apiKey: import.meta.env.VITE_APP_TOLGEE_API_KEY,
});
};
export const getServerLocales = async (
locale: string | undefined,
ns?: NsFallback
) => {
const namespaces = ['', ...getFallbackArray(ns)];
const result: Record<string, any> = {};
if (locale) {
for (const namespace of namespaces) {
if (namespace) {
result[`${locale}:${namespace}`] = (
await import(`./public/i18n/${namespace}/${locale}.json`)
).default;
} else {
result[`${locale}`] = (
await import(`./public/i18n/${locale}.json`)
).default;
}
}
}
return result;
};