Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions website/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "./metadata.schema.json",
"language": "ja-JP",
"version": "0.13.1",
"typstOfficialUrl": "https://typst.app",
"typstOfficialDocsUrl": "https://typst.app/docs/",
"githubOrganizationUrl": "https://github.com/typst-jp",
"githubRepositoryUrl": "https://github.com/typst-jp/docs",
"discordServerUrl": "https://discord.gg/9xF7k4aAuH",
"originUrl": "https://typst-jp.github.io/",
"basePath": "/docs/",
"displayTranslationStatus": true
}
66 changes: 66 additions & 0 deletions website/metadata.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"language": {
"type": "string",
"description": "The language of the documentation.",
"enum": ["ja-JP", "en-US"]
},
"version": {
"type": "string",
"description": "The version of the documentation, without a leading 'v'."
},
"typstOfficialUrl": {
"type": "string",
"format": "uri",
"description": "The official Typst website URL."
},
"typstOfficialDocsUrl": {
"type": "string",
"description": "The official Typst documentation base URL.",
"pattern": "^https?://.+/$"
},
"githubOrganizationUrl": {
"type": "string",
"format": "uri",
"description": "The GitHub organization URL."
},
"githubRepositoryUrl": {
"type": "string",
"format": "uri",
"description": "The GitHub repository URL."
},
"discordServerUrl": {
"type": "string",
"format": "uri",
"description": "The Discord server invite URL."
},
"originUrl": {
"type": "string",
"format": "uri",
"description": "The origin URL of the deployed site, used for metadata. Note that the base path should not be included."
},
"basePath": {
"type": "string",
"description": "The base public path for deployment. This must match the value used in typst-docs.",
"pattern": "^/([^/]+/)*$"
},
"displayTranslationStatus": {
"type": "boolean",
"description": "Indicates whether to display the translation status on the site. Community content is always displayed."
}
},
"required": [
"language",
"version",
"typstOfficialUrl",
"typstOfficialDocsUrl",
"githubOrganizationUrl",
"githubRepositoryUrl",
"discordServerUrl",
"originUrl",
"basePath",
"displayTranslationStatus"
]
}
1 change: 0 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"private": true,
"version": "0.13.1",
"type": "module",
"scripts": {
"dev": "vite dev",
Expand Down
39 changes: 27 additions & 12 deletions website/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { version } from "../package.json";
import metadataJson from "../metadata.json";

// TODO: The metadata will be configurable via a JSON configuration file.
type Metadata = {
language: "ja-JP" | "en-US";
version: string;
typstOfficialUrl: string;
typstOfficialDocsUrl: `http://${string}/` | `https://${string}/`;
githubOrganizationUrl: string;
githubRepositoryUrl: string;
discordServerUrl: string;
originUrl: string;
basePath: "/" | `/${string}/`;
displayTranslationStatus: boolean;
};

const metadata = metadataJson as Metadata;

/** The language of the documentation. */
export const language = metadata.language;
/** The version of the documentation, without a leading `v`. */
export { version };
export const version = metadata.version;
/** The official Typst website URL. */
export const typstOfficialUrl = "https://typst.app";
export const typstOfficialUrl = metadata.typstOfficialUrl;
/** The official Typst documentation base URL. */
export const typstOfficialDocsUrl: `http://${string}/` | `https://${string}/` =
"https://typst.app/docs/";
export const typstOfficialDocsUrl = metadata.typstOfficialDocsUrl;
/** The GitHub organization URL. */
export const githubOrganizationUrl = "https://github.com/typst-jp";
export const githubOrganizationUrl = metadata.githubOrganizationUrl;
/** The GitHub repository URL. */
export const githubRepositoryUrl = "https://github.com/typst-jp/docs";
export const githubRepositoryUrl = metadata.githubRepositoryUrl;
/** The Discord server invite URL. */
export const discordServerUrl = "https://discord.gg/9xF7k4aAuH";
export const discordServerUrl = metadata.discordServerUrl;
/** The origin URL of the deployed site, used for metadata. Note that the base path should not be included. */
export const originUrl = "https://typst-jp.github.io/";
export const originUrl = metadata.originUrl;
/** The base public path for deployment. This must match the value used in typst-docs. */
export const basePath: "/" | `/${string}/` = "/docs/";
export const basePath = metadata.basePath;
/** Indicates whether to display the translation status on the site. Community content is always displayed. */
export const displayTranslationStatus: boolean = true;
export const displayTranslationStatus = metadata.displayTranslationStatus;
25 changes: 21 additions & 4 deletions website/src/translation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type { FC } from "hono/jsx";
import type { TooltipProps } from "../components/ui/Tooltip";
import { language } from "../metadata";
import {
Translation as EnUSTranslation,
translation as enUSTranslation,
} from "./en-US";
import {
Translation as JaJPTranslation,
translation as jaJPTranslation,
} from "./ja-JP";

/**
* Translation dictionary for UI attributes and aria labels.
Expand Down Expand Up @@ -80,7 +89,15 @@ export type TranslationComponentProps =
*/
export type TranslationComponent = FC<TranslationComponentProps>;

/**
* Switch translation language here.
*/
export { Translation, translation } from "./ja-JP";
// Switch translation language.
const { Translation, translation } = (() => {
switch (language) {
case "ja-JP":
return { Translation: JaJPTranslation, translation: jaJPTranslation };
case "en-US":
return { Translation: EnUSTranslation, translation: enUSTranslation };
default:
throw new Error(`Unsupported language: ${language}`);
}
})();
export { Translation, translation };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If properly set up, then this can be simplified to await import(`./locales/${language}.tsx`). Not sure if it's worth it, though.

https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars

Properly set up:

  1. Enable top-level await for TypeScript.

    Add "target": "es2017" (or newer) to website/tsconfig.json

  2. Enable dynamic import for Vite.

    • Add a new dependency @rollup/plugin-dynamic-import-vars
    • Add dynamicImportVars({ include: "src/translation/", errorWhenNoFilesFound: true }) (or maybe just dynamicImportVars()) to defineConfig(plugins: [...]) in website/vite.config.ts
  3. Mitigate limitations.