-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add translation switcher to website #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
71dae96
14d0c9c
dc5c2cf
50c459f
c7a598a
7e8de2c
f44f181
fdee3d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,198 @@ | ||||||
| import type { TooltipProps } from "../components/ui/Tooltip"; | ||||||
| import type { TranslationComponent, TranslationObject } from "./"; | ||||||
|
|
||||||
| export const translation: TranslationObject = { | ||||||
| htmlLang: () => "en", | ||||||
| documentationTitle: () => "Typst Documentation (English)", | ||||||
| close: () => "Close", | ||||||
| closeMenu: () => "Close menu", | ||||||
| closeSearch: () => "Close search", | ||||||
| openMenu: () => "Open menu", | ||||||
| openSearch: () => "Open search", | ||||||
| showInformation: (props: { name: string }) => | ||||||
| `Show details for ${props.name}`, | ||||||
| tooltipKind: (props: { kind: TooltipProps["kind"] }) => { | ||||||
| switch (props.kind) { | ||||||
| case "element": | ||||||
| return "Element"; | ||||||
| case "contextual": | ||||||
| return "Context"; | ||||||
| case "definitions": | ||||||
| return "Definition"; | ||||||
| case "parameters": | ||||||
| return "Parameter"; | ||||||
| case "variadic": | ||||||
| return "Variadic"; | ||||||
| case "settable": | ||||||
| return "Settable"; | ||||||
| case "positional": | ||||||
| return "Positional"; | ||||||
| case "required": | ||||||
| return "Required"; | ||||||
| default: | ||||||
| return props.kind; | ||||||
| } | ||||||
| }, | ||||||
| } as const; | ||||||
|
|
||||||
| export const Translation: TranslationComponent = (props) => { | ||||||
| switch (props.translationKey) { | ||||||
| case "definition": | ||||||
| return <>Definition</>; | ||||||
| case "constructor": | ||||||
| return <>Constructor</>; | ||||||
| case "definitionOf": | ||||||
| return ( | ||||||
| <> | ||||||
| <code>{props.name}</code> Definition | ||||||
| </> | ||||||
| ); | ||||||
| case "search": | ||||||
| return <>Search</>; | ||||||
| case "defaultValue": | ||||||
| return <>Default value:</>; | ||||||
| case "stringValues": | ||||||
| return <>Available string values:</>; | ||||||
| case "showExample": | ||||||
| return <>Show example</>; | ||||||
| case "tableOfContents": | ||||||
| return <>On this page</>; | ||||||
| case "nextPage": | ||||||
| return <>Next page</>; | ||||||
| case "previousPage": | ||||||
| return <>Previous page</>; | ||||||
| case "referenceDescription": | ||||||
| return ( | ||||||
| <> | ||||||
| Detailed reference for all Typst syntax, concepts, types, and | ||||||
| functions. | ||||||
| </> | ||||||
| ); | ||||||
| case "tutorialDescription": | ||||||
| return <>Learn how to use Typst step by step.</>; | ||||||
| case "tutorial": | ||||||
| return <>Tutorial</>; | ||||||
| case "openOfficialDocs": | ||||||
| return <>Open official docs</>; | ||||||
| case "reference": | ||||||
| return <>Reference</>; | ||||||
| case "typstOfficialDocs": | ||||||
| return <>Typst official docs</>; | ||||||
| case "typstOfficialWebsite": | ||||||
| return <>Typst official website</>; | ||||||
| case "untranslated": | ||||||
| return <>Untranslated</>; | ||||||
| case "untranslatedMessage": | ||||||
| return ( | ||||||
| <> | ||||||
| This page has not been translated yet. The original content is shown. | ||||||
| </> | ||||||
| ); | ||||||
| case "communityContent": | ||||||
| return <>Community original content</>; | ||||||
| case "contentAddedByCommunity": | ||||||
| return ( | ||||||
| <> | ||||||
| This page contains content that is not part of the official | ||||||
| documentation, added independently by the community. | ||||||
| </> | ||||||
| ); | ||||||
| case "partiallyTranslated": | ||||||
| return <>Partially translated</>; | ||||||
| case "partiallyTranslatedMessage": | ||||||
| return ( | ||||||
| <> | ||||||
| This page is partially translated. Some original content is included. | ||||||
| </> | ||||||
| ); | ||||||
| case "translated": | ||||||
| return <>Translated</>; | ||||||
| case "translatedMessage": | ||||||
| return <>This page has been translated into English.</>; | ||||||
|
||||||
| return <>This page has been translated into English.</>; | |
| return <>This page is in English.</>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also find this a bit odd, but in the first place, the original (English) version shouldn’t need to display translation status, nor should it. Since en-US.tsx is just a sample for i18n support, I think it’s fine to leave it as is.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import type { FC } from "hono/jsx"; | ||
| import type { TooltipProps } from "../components/ui/Tooltip"; | ||
|
|
||
| /** | ||
| * Translation dictionary for UI attributes and aria labels. | ||
| * | ||
| * @example | ||
| * translation.closeMenu() | ||
| * translation.showInformation({ name: "foo" }) | ||
| */ | ||
| export type TranslationObject = { | ||
| htmlLang: () => string; | ||
| documentationTitle: () => string; | ||
| close: () => string; | ||
| closeMenu: () => string; | ||
| closeSearch: () => string; | ||
| openMenu: () => string; | ||
| openSearch: () => string; | ||
| showInformation: (props: { name: string }) => string; | ||
| tooltipKind: (props: { kind: TooltipProps["kind"] }) => string; | ||
| }; | ||
|
|
||
| type TranslationComponentKey = | ||
| | "definition" | ||
| | "constructor" | ||
| | "tableOfContents" | ||
| | "untranslated" | ||
| | "untranslatedMessage" | ||
| | "document" | ||
| | "langVersion" | ||
| | "elementFunction" | ||
| | "elementFunctionDescription" | ||
| | "contextFunction" | ||
| | "contextFunctionDescription" | ||
| | "definitionTooltip" | ||
| | "definitionTooltipDescription" | ||
| | "variadic" | ||
| | "translationRate" | ||
| | "variadicDescription" | ||
| | "typstOfficialDocs" | ||
| | "typstOfficialWebsite" | ||
| | "communityContent" | ||
| | "contentAddedByCommunity" | ||
| | "partiallyTranslated" | ||
| | "partiallyTranslatedMessage" | ||
| | "translated" | ||
| | "translatedMessage" | ||
| | "siteNoticeBannerTitle" | ||
| | "siteNoticeBannerDescription" | ||
| | "tutorial" | ||
| | "tutorialDescription" | ||
| | "referenceDescription" | ||
| | "reference" | ||
| | "openOfficialDocs" | ||
| | "search" | ||
| | "argument" | ||
| | "argumentDescription" | ||
| | "required" | ||
| | "requiredDescription" | ||
| | "positional" | ||
| | "positionalDescription" | ||
| | "defaultValue" | ||
| | "stringValues" | ||
| | "showExample" | ||
| | "settable" | ||
| | "settableDescription" | ||
| | "previousPage" | ||
| | "nextPage"; | ||
|
|
||
| export type TranslationComponentProps = | ||
| | { translationKey: TranslationComponentKey } | ||
| | { translationKey: "definitionOf"; name: string }; | ||
|
|
||
| /** | ||
| * Translation component for UI text, descriptions, and other content to be embedded as JSX. | ||
| * | ||
| * @example | ||
| * <Translation translationKey="definition" /> | ||
| */ | ||
| export type TranslationComponent = FC<TranslationComponentProps>; | ||
|
|
||
| /** | ||
| * Switch translation language here. | ||
| */ | ||
| export { translation, Translation } from "./ja-JP"; |
Uh oh!
There was an error while loading. Please reload this page.