Skip to content
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

feat: add i18n to docs #16

Draft
wants to merge 1 commit into
base: feature/sdk-2-0
Choose a base branch
from
Draft
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
36 changes: 34 additions & 2 deletions apps/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
import { defineConfig } from 'vitepress';

import { packagesNavItem, packagesSidebar } from './packages';
import { platformNavItem, platformSidebar } from './platform';
import { linkGenerator } from "./utils";

import packagesSidebarJson from "./packagesSidebar.json";
import platformSidebarJson from "./platformSidebar.json";

import { zh } from "./zh";

const { prefixNavItem: packagesNavItem, prefixSideBar: packagesSidebar } =
linkGenerator(
"/packages",
{
text: "Packages",
link: `/telegram-apps-sdk`,
},
packagesSidebarJson as any
);

const { prefixNavItem: platformNavItem, prefixSideBar: platformSidebar } =
linkGenerator(
"/platform",
{
text: "Platform",
link: `/about`,
},
platformSidebarJson
);

function withSlashes(value: string | undefined): string {
if (!value) {
Expand Down Expand Up @@ -32,6 +56,14 @@ export default defineConfig({
label: 'English',
lang: 'en',
},
zh: {
label: "中文",
...zh,
},
translate:{
label:"Help Us Translate",
link:"https://docs.ton.org/contribute/localization-program/overview"
}
},

// Show when each page content was last updated.
Expand Down
65 changes: 65 additions & 0 deletions apps/docs/.vitepress/packagesSidebar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"CLI": {
"@telegram-apps/create-mini-app": "telegram-apps-create-mini-app"
},
"TypeScript": {
"@telegram-apps/sdk": [
"telegram-apps-sdk",
{
"Components": [
"components",
{
"BackButton": "back-button",
"BiometryManager": "biometry-manager",
"ClosingBehavior": "closing-behavior",
"CloudStorage": "cloud-storage",
"HapticFeedback": "haptic-feedback",
"InitData": "init-data",
"Invoice": "invoice",
"MainButton": "main-button",
"MiniApp": "mini-app",
"Popup": "popup",
"QRScanner": "qr-scanner",
"SettingsButton": "settings-button",
"SwipeBehavior": "swipe-behavior",
"ThemeParams": "theme-params",
"Utils": "utils",
"Viewport": "viewport"
},
true
],
"Environment": "environment",
"Methods and Events": "methods-and-events",
"Launch Parameters": "launch-parameters",
"Theme Parameters": "theme-parameters",
"Init Data": [
"init-data",
{
"InitData": "init-data",
"Chat": "chat",
"User": "user"
},
true
],
"Navigation": [
"navigation",
{
"BrowserNavigator": "browser-navigator"
},
true
],
"CSS Variables": "css-variables"
}
],
"@telegram-apps/sdk-react": "/telegram-apps-sdk-react",
"@telegram-apps/sdk-solid": "/telegram-apps-sdk-solid",
"@telegram-apps/solid-router-integration": "/telegram-apps-solid-router-integration",
"@telegram-apps/react-router-integration": "/telegram-apps-react-router-integration"
},
"Node": {
"@telegram-apps/init-data-node": "telegram-apps-init-data-node"
},
"GoLang": {
"init-data-golang": "init-data-golang"
}
}
38 changes: 38 additions & 0 deletions apps/docs/.vitepress/platformSidebar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Introduction": {
"About Platform": "about"
},
"Functional Features": {
"Closing Behavior": "closing-behavior",
"Swipe Behavior": "swipe-behavior",
"Haptic Feedback": "haptic-feedback"
},
"Apps Communication": {
"Flow Definition": "apps-communication",
"Methods": "methods",
"Events": "events"
},
"Launch Parameters": {
"About": "launch-parameters",
"Start Parameter": "start-parameter",
"Init Data": "init-data"
},
"Development": {
"Debugging": "debugging",
"Test Environment": "test-environment"
},
"UI": {
"Back Button": "back-button",
"Main Button": "main-button",
"Popup": "popup",
"Settings Button": "settings-button",
"Theming": "theming",
"Viewport": "viewport"
},
"Guides": {
"Authorizing User": "authorizing-user",
"Creating New App": "creating-new-app",
"Getting App Link": "getting-app-link",
"Sticky App": "sticky-app"
}
}
33 changes: 32 additions & 1 deletion apps/docs/.vitepress/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@ export function sectionGen(prefix: string) {
return (text: string, items: Items) => {
return section(text, items, prefix);
};
}
}

type navItem = {
text: string;
link: string;
};

export type LinkJson = Record<string, Items>;

export const linkGenerator = (
prefix: string,
navItem: navItem,
linkJson: LinkJson
) => {
const section = sectionGen(prefix);

const prefixNavItem = {
...navItem,
link: prefix + navItem?.link,
};

const prefixSideBar = {
[prefix]: Object.entries(linkJson).map(([key, value]: [string, Items]) =>
section(key, value)
),
};

return {
prefixNavItem,
prefixSideBar,
};
};
112 changes: 112 additions & 0 deletions apps/docs/.vitepress/zh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { defineConfig } from "vitepress";

import packagesSidebarJson from "./packagesSidebar.json";
import platformSidebarJson from "./platformSidebar.json";

import { linkGenerator } from "./utils";

const LANG_PREFIX = "/zh";

function withSlashes(value: string | undefined): string {
if (!value) {
return '/';
}
if (!value.startsWith('/')) {
value = '/' + value;
}
if (!value.endsWith('/')) {
value += '/';
}
return value;
}

const { prefixNavItem: packagesNavItem, prefixSideBar: packagesSidebar } =
linkGenerator(
LANG_PREFIX + "/packages",
{
text: "Packages",
link: `/telegram-apps-sdk`,
},
packagesSidebarJson as any
);

const { prefixNavItem: platformNavItem, prefixSideBar: platformSidebar } =
linkGenerator(
LANG_PREFIX + "/platform",
{
text: "Platform",
link: `/about`,
},
platformSidebarJson
);

export const zh = defineConfig({
lang: "zh-Hans",
title: 'Telegram Mini Apps',
description: 'Documentation covering all aspects of Telegram platform - Telegram Mini Apps.',

// The base URL the site will be deployed at.
// https://vitepress.dev/reference/site-config#base
base: withSlashes(process.env.DOCS_BASE_URL),

// Show when each page content was last updated.
// https://vitepress.dev/reference/default-theme-last-updated#last-updated
lastUpdated: true,

// We don't want .html to be in the end of each route.
// https://vitepress.dev/guide/routing#generating-clean-url
cleanUrls: true,

// Enable sitemap generation.
// https://vitepress.dev/guide/sitemap-generation#sitemap-generation
sitemap: {
hostname: 'https://docs.telegram-mini-apps.com',
},

// Configure <head/>.
// https://vitepress.dev/reference/site-config#head
head: [
// Add favicon.
// https://vitepress.dev/reference/site-config#example-adding-a-favicon
['link', { rel: 'icon', href: '/favicon.ico' }],
// Add Mixpanel analytics:
// https://docs.mixpanel.com/docs/quickstart/connect-your-data?sdk=javascript
['script', { async: '', src: '/analytics.js' }],
],

themeConfig: {
logo: '/logo.db0268ac.png',

// https://vitepress.dev/reference/default-theme-footer#footer
footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2022-present Vladislav Kibenko and Contributors',
},

editLink: {
text: 'Edit this page on GitHub',
pattern: 'https://github.com/telegram-mini-apps/telegram-apps/edit/master/apps/docs/:path',
},

nav: [
{ text: "Home", link: LANG_PREFIX },
platformNavItem,
packagesNavItem,
],

// https://vitepress.dev/reference/default-theme-sidebar
sidebar: {
...packagesSidebar,
...platformSidebar,
},

socialLinks: [{
icon: 'github',
link: 'https://github.com/telegram-mini-apps',
}],

search: {
provider: 'local',
},
},
});
26 changes: 26 additions & 0 deletions apps/docs/zh/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
layout: home
title: Home
description: 文档主页。
hero:
name: Telegram 迷你应用程序
text: Telegram 内成熟的网络应用程序
tagline: 简单、灵活、类似本机的网络应用程序,提升用户体验
actions:
- theme: brand
text: 平台
link: /zh/platform/about
- theme: alt
text: 包
link: /zh/packages/telegram-apps-sdk
features:
- icon: 💻
title: 多平台
details: 适用于所有 Telegram 官方应用程序,包括网络版和桌面版
- icon: 🌐
title: 基于网络
details: 平台仅要求了解基于网络的技术
- icon: 🧑
title: 更好的用户体验
details: 简化用户与 Telegram 项目的沟通
---
Loading