-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
37 lines (29 loc) · 906 Bytes
/
mod.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
import { Plugin } from "$fresh/server.ts";
import { Options, setup } from "./freshlate/shared.ts";
export type { Options };
export default function translate(options: Options): Plugin {
setup(options, undefined);
// Main script to run client-side
const main = `data:application/javascript,import hydrate from "${
new URL("./freshlate/main.ts", import.meta.url).href
}";
import opts from "${options.selfURL}";
export default function(state) { hydrate(opts, state); }
`;
return {
name: "translate",
entrypoints: { main: main },
render: (ctx) => {
const res = ctx.render();
const scripts = [];
const languages = options.languages;
if (res.requiresHydration) {
scripts.push({ entrypoint: "main", state: languages });
}
return {
scripts,
};
},
};
}
export {lang_svc as freshlate} from './freshlate/translation.ts'