12559f518a
* main: (21 commits) web: bump API Client version (#7964) release: 2023.10.5 web: bump API Client version (#7962) providers/scim: use lock for sync (#7948) stages/email: prevent authentik emails from being marked as spam (also add text template support) (#7949) website/docs: prepare 2023.10.5 (#7947) web: bump the sentry group in /web with 2 updates (#7955) web: bump the wdio group in /tests/wdio with 4 updates (#7957) core: bump goauthentik.io/api/v3 from 3.2023104.4 to 3.2023104.5 (#7958) web: bump API Client version (#7953) events: add ASN Database reader (#7793) translate: Updates for file web/xliff/en.xlf in fr (#7951) website/docs: add expression example for geoip (#7739) website: fix hosted API browser (#7946) core: bump github.com/redis/go-redis/v9 from 9.3.0 to 9.3.1 (#7942) web: bump the sentry group in /web with 2 updates (#7944) web: bump the storybook group in /web with 7 updates (#7945) core: bump goauthentik.io/api/v3 from 3.2023104.3 to 3.2023104.4 (#7943) providers/scim: set timeout based on page and page count (#7941) translate: Updates for file web/xliff/en.xlf in zh_CN (#7928) ...
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
import { readFileSync } from "fs";
|
|
import path from "path";
|
|
import pseudolocale from "pseudolocale";
|
|
import { fileURLToPath } from "url";
|
|
|
|
import { makeFormatter } from "@lit/localize-tools/lib/formatters/index.js";
|
|
import type { Message, ProgramMessage } from "@lit/localize-tools/lib/messages.d.ts";
|
|
import { sortProgramMessages } from "@lit/localize-tools/lib/messages.js";
|
|
import { TransformLitLocalizer } from "@lit/localize-tools/lib/modes/transform.js";
|
|
import type { Config } from "@lit/localize-tools/lib/types/config.d.ts";
|
|
import type { Locale } from "@lit/localize-tools/lib/types/locale.d.ts";
|
|
import type { TransformOutputConfig } from "@lit/localize-tools/lib/types/modes.d.ts";
|
|
|
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
const pseudoLocale: Locale = "pseudo-LOCALE" as Locale;
|
|
const targetLocales: Locale[] = [pseudoLocale];
|
|
const baseConfig = JSON.parse(readFileSync(path.join(__dirname, "../lit-localize.json"), "utf-8"));
|
|
|
|
// Need to make some internal specifications to satisfy the transformer. It doesn't actually matter
|
|
// which Localizer we use (transformer or runtime), because all of the functionality we care about
|
|
// is in their common parent class, but I had to pick one. Everything else here is just pure
|
|
// exploitation of the lit/localize-tools internals.
|
|
|
|
const config: Config = {
|
|
...baseConfig,
|
|
baseDir: path.join(__dirname, ".."),
|
|
targetLocales,
|
|
output: {
|
|
...baseConfig,
|
|
mode: "transform",
|
|
},
|
|
resolve: (path: string) => path,
|
|
} as Config;
|
|
|
|
const pseudoMessagify = (message: ProgramMessage) => ({
|
|
name: message.name,
|
|
contents: message.contents.map((content) =>
|
|
typeof content === "string" ? pseudolocale(content, { prepend: "", append: "" }) : content,
|
|
),
|
|
});
|
|
|
|
const localizer = new TransformLitLocalizer(config as Config & { output: TransformOutputConfig });
|
|
const { messages } = localizer.extractSourceMessages();
|
|
const translations = messages.map(pseudoMessagify);
|
|
const sorted = sortProgramMessages([...messages]);
|
|
const formatter = makeFormatter(config);
|
|
formatter.writeOutput(sorted, new Map<Locale, Message[]>([[pseudoLocale, translations]]));
|