Skip to content

Commit

Permalink
Merge pull request #30 from CrazyTapok-bit/develop
Browse files Browse the repository at this point in the history
Added Chine translation
  • Loading branch information
CrazyTapok-bit authored Apr 19, 2024
2 parents 305e930 + 61e566e commit 399609c
Show file tree
Hide file tree
Showing 23 changed files with 567 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default defineUserConfig({
lang: "en-US",
title: "The PHP library for validate Telegram users"
},
"/zh/": {
lang: "zh-CN",
title: "用于验证 Telegram 用户的 PHP 库"
},
},

theme,
Expand Down
1 change: 1 addition & 0 deletions src/.vuepress/navbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./uk.js";
export * from "./en.js";
export * from "./zh.js";
16 changes: 16 additions & 0 deletions src/.vuepress/navbar/zh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { navbar } from "vuepress-theme-hope";

export const zhNavbar = navbar([
"/zh/",
{
text: "文档",
icon: "book",
link: "/zh/docs/README.md",
activeMatch: "^/zh/docs/$"
},
{
text: "完整示例",
icon: "bolt",
link: "/zh/docs/example/README.md"
}
]);
1 change: 1 addition & 0 deletions src/.vuepress/sidebar/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./uk.js";
export * from "./en.js";
export * from "./zh.js";
13 changes: 13 additions & 0 deletions src/.vuepress/sidebar/zh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sidebar } from "vuepress-theme-hope";

export const zhSidebar = sidebar({
"/zh/": [
{
text: "文档",
icon: "laptop-code",
prefix: "zh/docs/",
children: "structure",
},
],
"/zh/docs/": "structure",
});
20 changes: 18 additions & 2 deletions src/.vuepress/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hopeTheme } from "vuepress-theme-hope";
import { enNavbar, ukNavbar } from "./navbar/index.js";
import { ukSidebar, enSidebar } from "./sidebar/index.js";
import { enNavbar, ukNavbar, zhNavbar } from "./navbar/index.js";
import { ukSidebar, enSidebar, zhSidebar } from "./sidebar/index.js";

const DOCSEARCH_APPID = process.env.DOCSEARCH_APPID || ""
const DOCSEARCH_APIKEY = process.env.DOCSEARCH_APIKEY || ""
Expand Down Expand Up @@ -43,6 +43,11 @@ export default hopeTheme({
sidebar: enSidebar,
displayFooter: true
},
"/zh/": {
navbar: zhNavbar,
sidebar: zhSidebar,
displayFooter: true
}
},

plugins: {
Expand Down Expand Up @@ -89,6 +94,17 @@ export default hopeTheme({
link: "https://www.patreon.com/user?u=99188087"
}
]
},
{
path: "/zh/",
title: "他们说我们很酷😎",
content: `⭐️ 支持我们,在 <a target="_blank" rel="noopener noreferrer" href="https://github.com/${repo}">GitHub</a> 上为我们加注星标并成为我们的赞助商 😊`,
actions: [
{
text: "赞助商💰",
link: "https://www.patreon.com/user?u=99188087"
}
]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/en/docs/example/login-winget.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ try {
* which checks the data received from the Telegram Login Widget
*/
$user = $bot->validateLoginWidget(
user: [/** Дані користувача */]
user: [/** User data */]
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/en/docs/validator/login-widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ If set to `true`, the library will throw an exception if validation fails.
:::warning
Be sure to use `try/catch` if you plan to handle exceptions :wink:

If exceptions are enabled, you will get a [ValidationException] exception after a validation failure(../exception/validation.md). Otherwise, `false' will be returned.
If exceptions are enabled, you will get a [ValidationException] exception after a validation failure(../exception/validation.md). Otherwise, `false` will be returned.
:::
2 changes: 1 addition & 1 deletion src/en/docs/validator/mini-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ If set to `true`, the library will throw an exception if validation fails.
:::warning
Be sure to use `try/catch' if you plan to handle exceptions :wink:

If exceptions are enabled, you will get a [ValidationException](../exception/validation.md) exception after a validation failure. Otherwise, `false' will be returned.
If exceptions are enabled, you will get a [ValidationException](../exception/validation.md) exception after a validation failure. Otherwise, `false` will be returned.
:::
51 changes: 51 additions & 0 deletions src/zh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
home: true
icon: home
title:
head:
- - meta
- name: description
content: TgWebValid 库是使用 PHP 验证网站上的 Telegram Login Widget 和 Telegram Mini App 用户的简单方法。
sitemap:
priority: 1
heroImage: /logo.svg
heroAlt: 徽标 TgWebValid
bgImage: /assets/bg/main-light.svg
bgImageDark: /assets/bg/main-dark.svg
bgImageStyle:
background-attachment: fixed
heroText: TgWebValid
tagline: 使用 PHP 检查网站上的 Telegram Login Widget 和 Telegram Mini App 用户的简单方法
actions:
- text: 开始使用
icon: signs-post
link: /zh/docs/
type: primary

- text: 例子
link: /zh/docs/example/

highlights:
- header: 我们的特色
description: 成功工作的主要好处
features:
- title: 速度
icon: rocket
details: 专注于尽可能最快的数据处理

- title: 自动完成
icon: wand-magic-sparkles
details: 我们和您一样喜欢清晰干净的代码

- title: 测试
icon: vial-circle-check
details: 我们通过测试提供 100% 的 PHPUnit 功能覆盖

- title: 多机器人
icon: gem
details: 与不同的机器人同时工作

- title: 可靠性
icon: check-double
details: 在高流量聊天机器人上进行测试
---
36 changes: 36 additions & 0 deletions src/zh/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: 文档
index: false
icon: book
---

[![Testing Status](https://github.com/CrazyTapok-bit/tgWebValid/workflows/PHP%20CI/badge.svg)](https://github.com/CrazyTapok-bit/tgWebValid/actions)
[![Minimum PHP Version](https://img.shields.io/packagist/dependency-v/tg/tgwebvalid/php)](https://packagist.org/packages/tg/tgwebvalid)
[![Latest version](https://img.shields.io/packagist/v/tg/tgWebValid)](https://packagist.org/packages/tg/tgwebvalid)
[![Total Downloads](https://img.shields.io/packagist/dt/tg/tgwebvalid)](https://packagist.org/packages/tg/tgwebvalid)
[![Total Stars](https://img.shields.io/packagist/stars/tg/tgwebvalid)](https://packagist.org/packages/tg/tgwebvalid)
[![License](https://img.shields.io/packagist/l/tg/tgwebvalid)](https://packagist.org/packages/tg/tgwebvalid)

[![StandWithUkraine](https://raw.githubusercontent.com/CrazyTapok-bit/tgWebValid/4.x/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
[![StandWithUkraine](https://raw.githubusercontent.com/CrazyTapok-bit/tgWebValid/4.x/badges/RussianWarship.svg)](https://stand-with-ukraine.pp.ua)

[![StandWithUkraine](https://raw.githubusercontent.com/CrazyTapok-bit/tgWebValid/4.x/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)

## 关于 TgWebValid {#about}

我们的库轻量、快速:rocket:、现代化,并且具有 `100%` 自动完成功能来获取用户数据。 同时,我们使其成为自治的,因此无论是否在任何框架中都可以使用它。

最重要的是,我们的库旨在验证 PHP 上的 [Telegram Mini App](https://core.telegram.org/bots/webapps)[Telegram Login Widget](https://core.telegram.org/widgets/login) 的用户

通过加密接收到的原始用户数据并将其与 Telegram 提供的哈希值进行比较来进行身份验证。

:::info 推荐
提供对敏感用户数据的访问 **仅在身份验证成功后**
:::

**开始快速、安全地验证用户。**

:::tip 注意
在您的项目中部署 TgWebValid 库的平均时间 **仅 ~ 1 分钟**
:::

9 changes: 9 additions & 0 deletions src/zh/docs/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: 完整示例
icon: bolt
index: false
dir:
order: 5
---

<Catalog />
67 changes: 67 additions & 0 deletions src/zh/docs/example/login-winget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: 登录小部件
icon: right-to-bracket
order: 2
head:
- - meta
- name: description
content: 如何验证通过 Telegram Login Widget 收到的数据 - PHP
---

我们尝试展示尽可能完整的示例,您很可能会使用该示例。

```php
<?php

use TgWebValid\TgWebValid;
use TgWebValid\Exceptions\BotException;
use TgWebValid\Exceptions\ValidationException;
use Exception;

include './vendor/autoload.php';

try {
/**
* 我指定令牌设置并启用异常处理
*/
$tgWebValid = new TgWebValid(
token: 'TELEGRAM_BOT_TOKEN',
throw: true
);

/** 我将设置另一个额外的机器人来与他们合作 */
$tgWebValid->addBot(
name: 'secondary',
token: 'TELEGRAM_BOT_TOKEN_2'
);

/** 我使用默认机器人 */
$bot = $tgWebValid->bot();

/** 或者,指定我想要使用哪个机器人 */
$bot = $tgWebValid->bot(
name: 'secondary'
);

/**
* 调用 validateLoginWidget 方法,
* 检查从 Telegram Login Widget 收到的数据
*/
$user = $bot->validateLoginWidget(
user: [/** 用户数据 */]
);

/**
* 如果检查成功,
* 我将显示包含所有用户数据的 LoginWidget 实体
*/
var_dump($user);

} catch (ValidationException $e) {
// 如果检查失败,我将收到验证异常
} catch (BotException $e) {
// 由于机器人名称错误,我会捕获此异常
} catch (Exception $e) {
// 如果有其他错误我会处理
}
```
67 changes: 67 additions & 0 deletions src/zh/docs/example/mini-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: 迷你应用程序
icon: tablet-screen-button
order: 1
head:
- - meta
- name: description
content: 如何验证通过 Telegram Web 应用程序收到的数据 - PHP
---

我们尝试展示尽可能完整的示例,您很可能会使用该示例。

```php
<?php

use TgWebValid\TgWebValid;
use TgWebValid\Exceptions\BotException;
use TgWebValid\Exceptions\ValidationException;
use Exception;

include './vendor/autoload.php';

try {
/**
* 我指定令牌设置并启用异常处理
*/
$tgWebValid = new TgWebValid(
token: 'TELEGRAM_BOT_TOKEN',
throw: true
);

/** 我将设置另一个额外的机器人来与他们合作 */
$tgWebValid->addBot(
name: 'secondary',
token: 'TELEGRAM_BOT_TOKEN_2'
);

/** 我使用默认机器人 */
$bot = $tgWebValid->bot();

/** 或者,指定我想要使用哪个机器人 */
$bot = $tgWebValid->bot(
name: 'secondary'
);

/**
* 调用 validateInitData 方法,
* 检查从 Telegram Mini 应用程序收到的数据
*/
$initData = $bot->validateInitData(
initData: 'query_id=...'
);

/**
* 如果检查成功,
* 我将输出包含所有用户数据的 InitData 实体
*/
var_dump($initData);

} catch (ValidationException $e) {
// 如果检查失败,我将收到验证异常
} catch (BotException $e) {
// 由于机器人名称错误,我会捕获此异常
} catch (Exception $e) {
// 如果有其他错误我会处理
}
```
13 changes: 13 additions & 0 deletions src/zh/docs/exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: 例外情况
icon: bomb
order: 4
---

如果您确定验证数据正确,但仍然出现此异常,请检查设置中指定的令牌的正确性。

## BotException
您尝试[应用](./get-started/usage.md)的机器人名称不正确,或者添加的列表中不存在该机器人。

## ValidationException
无法使用[可用验证器](./validator/) 之一验证用户。 它可能表明存在黑客攻击和/或绕过系统的威胁。
10 changes: 10 additions & 0 deletions src/zh/docs/get-started/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: 开始使用
icon: lightbulb
index: false
dir:
order: 1
collapsible: false
---

<Catalog />
Loading

0 comments on commit 399609c

Please sign in to comment.