-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshapes.ts
More file actions
46 lines (42 loc) · 1.47 KB
/
Copy pathshapes.ts
File metadata and controls
46 lines (42 loc) · 1.47 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import picomatch from 'picomatch';
import * as z from 'zod';
export const Message = z.object({
message: z.string(),
translation: z.string().optional(),
id: z.string().optional(),
context: z.string().optional(),
comments: z.string().array(),
references: z.string().array(),
});
export type Message = z.infer<typeof Message>;
export const Formatter = z.object({
extension: z.templateLiteral(['.', z.string()]),
parse: z.custom<(content: string, context: { locale: string }) => Promise<Message[]>>(
(v) => typeof v === 'function',
),
stringify: z.custom<(messages: Message[], context: { locale: string }) => Promise<string>>(
(v) => typeof v === 'function',
),
});
export type Formatter = z.infer<typeof Formatter>;
export const Bucket = z
.object({
include: z.array(z.string()),
exclude: z.array(z.string()).optional(),
output: z.templateLiteral([z.string(), '{locale}', z.string(), '.{extension}']),
formatter: Formatter,
})
.transform((v) => ({
...v,
match: picomatch(v.include, { ignore: v.exclude }),
}));
export type Bucket = z.infer<typeof Bucket>;
export const Configuration = z
.object({
sourceLocale: z.string(),
locales: z.tuple([z.string()], z.string()),
fallbackLocales: z.record(z.string(), z.array(z.string())).optional(),
buckets: z.array(Bucket),
})
.refine((c) => c.sourceLocale === c.locales[0], 'sourceLocale must be the same as locales[0]');
export type Configuration = z.infer<typeof Configuration>;