-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
32 lines (29 loc) · 1.08 KB
/
index.ts
File metadata and controls
32 lines (29 loc) · 1.08 KB
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
export interface LessifyReactI18nextConfig {
space: SpaceConfig;
}
export interface SpaceConfig {
spaceId: string;
environment: string;
apiKey: string;
beta?: boolean;
}
export function LessifyReactI18next(config: LessifyReactI18nextConfig): any {
if (config.space.spaceId == null || config.space.spaceId === '') {
throw new Error('Lessify Configuration Space can\'t be empty');
}
if (config.space.environment == null || config.space.environment === '') {
throw new Error('Lessify Configuration Environment can\'t be empty');
}
if (config.space.apiKey == null || config.space.apiKey === '') {
throw new Error('Lessify Configuration API Key can\'t be empty');
}
const url = (config.space.beta == null || config.space.beta === false) ? 'https://api.lessify.io' : 'https://dev-api.lessify.io';
return {
loadPath: `${url}/v1/spaces/${config.space.spaceId}/environments/${config.space.environment}/translations.{{lng}}.json`,
crossDomain: true,
withCredentials: true,
customHeaders: {
authorization: `Bearer ${config.space.apiKey}`,
},
}
}