Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f59fb7c
Adds translate support
huangdijia Dec 26, 2024
6fd17ee
ci: 优化翻译文档工作流,移除冗余依赖安装步骤
huangdijia Dec 26, 2024
3cedccd
修正文档路径中的语言代码分隔符,从 'zh-CN' 更改为 'zh_CN'
huangdijia Dec 26, 2024
88a5351
恢复对繁体中文和香港中文的支持,更新文档翻译配置
huangdijia Dec 26, 2024
25604d7
Update docs and translate
huangdijia Dec 26, 2024
38a3a64
Revert "Update docs and translate"
huangdijia Dec 26, 2024
dd1fbd7
新增简体中文文档,包含常见问题、入门指南、组件说明及相关支持文档
huangdijia Dec 26, 2024
1e009a1
新增简体中文、繁体中文和台湾中文的配置和导航文件,删除旧的中文文件
huangdijia Dec 26, 2024
843a22a
Update docs and translate
huangdijia Dec 26, 2024
86126f2
更新配置文件,新增简体中文、繁体中文(港)、繁体中文(台)支持,并恢复英文配置
huangdijia Dec 26, 2024
55d9c35
更新繁体中文(港)和繁体中文(台)文档链接,确保导航和组件链接指向正确的语言版本
huangdijia Dec 26, 2024
fb5c8b4
更新文档翻译工作流,排除主分支的推送触发
huangdijia Dec 26, 2024
18acce0
更新文档翻译工作流,仅在文档目录下的更改时触发
huangdijia Dec 26, 2024
1992bc1
更新文档翻译工作流,移除对主分支的推送触发限制
huangdijia Dec 26, 2024
d1e9c8b
重构文档工作流,合并翻译和拆分功能,移除旧的工作流配置
huangdijia Dec 26, 2024
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
75 changes: 75 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Split Docs

on:
push:
paths:
- 'docs/**'
branches:
- main
workflow_dispatch:

jobs:
translate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: phpize
extensions: swoole, redis
ini-values: extension=opencc

- name: Install OpenCC
run: |
sudo apt-get install libopencc-dev -y

- name: Build opencc4php
run: |
git clone https://github.com/nauxliu/opencc4php.git --depth 1
cd opencc4php
phpize
./configure
make
sudo make install
php --ri opencc
cd ..
rm -rf opencc4php

- name: Setup Dependencies
run: composer install

- name: Start Translate
run: php bin/doc-translate

- name: Commit Updated
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update docs and translate
split:
needs: translate
name: Split on branch ${{ github.ref }}
if: github.repository == 'friendsofhyperf/components'
runs-on: ubuntu-22.04
env:
SSH_PRIVATE_KEY: ${{ secrets.SPLIT_PRIVATE_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Private Key
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Split And Push
run: |
git config pull.rebase true
git config --global user.email "huangdijia@gmail.com"
git config --global user.name "Deeka Wong"
./bin/split-docs.sh
34 changes: 0 additions & 34 deletions .github/workflows/split-docs.yaml

This file was deleted.

63 changes: 63 additions & 0 deletions bin/doc-translate
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact huangdijia@gmail.com
*/
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));

require BASE_PATH . '/vendor/autoload.php';

use Symfony\Component\Finder\Finder;

$config = [
'zh-tw' => [
'targetDir' => BASE_PATH . '/docs/zh-tw/',
'rule' => 's2twp.json',
],
'zh-hk' => [
'targetDir' => BASE_PATH . '/docs/zh-hk/',
'rule' => 's2hk.json',
],
// 'en' => [
// 'targetDir' => BASE_PATH . '/docs/en/',
// 'rule' => 's2en.json',
// ],
];

$finder = new Finder();
$finder->files()->in(BASE_PATH . '/docs/zh-cn');

foreach ($config as $key => $item) {
$od = opencc_open($item['rule']);
foreach ($finder as $fileInfo) {
$targetDir = $item['targetDir'];
$targetPath = $targetDir . $fileInfo->getRelativePath();
$isCreateDir = false;
if (! is_dir($targetPath)) {
mkdir($targetPath, 0777, true);
chmod($targetPath, 0777);
$isCreateDir = true;
}
if (! is_writable($targetPath)) {
echo sprintf('Target path %s is not writable.' . PHP_EOL, $targetPath);
}
if ($fileInfo->getExtension() === 'md') {
$translated = opencc_convert($fileInfo->getContents(), $od);
$translated = str_replace('](zh-cn/', '](' . $key . '/', $translated);
$translated = str_replace('](/zh-cn/', '](/' . $key . '/', $translated);
$translated = str_replace('](./zh-cn/', '](./' . $key . '/', $translated);
$targetTranslatedPath = $targetDir . $fileInfo->getRelativePathname();
@file_put_contents($targetTranslatedPath, $translated);
} else {
Comment on lines +50 to +57
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议添加错误处理逻辑
在使用 @file_put_contents@copy 时,为避免忽略潜在错误(如磁盘空间不足、权限不足等),建议去掉 @ 并加上异常捕获或判定写入和复制结果是否成功,以便及时发现并处理异常情况。

Also applies to: 59-59

$targetTranslatedPath = $targetDir . $fileInfo->getRelativePathname();
@copy($fileInfo->getRealPath(), $targetTranslatedPath);
}
}
opencc_close($od);
}
Empty file modified bin/generate-repository-doc.sh
100644 → 100755
Empty file.
53 changes: 46 additions & 7 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { defineConfig } from 'vitepress'

import enGetConfig from "./src/en/config";
import enGetNavs from "./src/en/nav";
import enGetSidebar from "./src/en/sidebars";
import zhGetConfig from "./src/zh/config";
import zhGetNavs from "./src/zh/nav";
import zhGetSidebar from "./src/zh/sidebars";

import cnGetConfig from "./src/zh-cn/config";
import cnGetNavs from "./src/zh-cn/nav";
import cnGetSidebar from "./src/zh-cn/sidebars";

import hkGetConfig from "./src/zh-hk/config";
import hkGetNavs from "./src/zh-hk/nav";
import hkGetSidebar from "./src/zh-hk/sidebars";

import twGetConfig from "./src/zh-tw/config";
import twGetNavs from "./src/zh-tw/nav";
import twGetSidebar from "./src/zh-tw/sidebars";

import taskLists from 'markdown-it-task-lists'

// https://vitepress.dev/reference/site-config
Expand Down Expand Up @@ -40,9 +51,37 @@ export default defineConfig({
],
locales:{
root:{
label:"中文",
label:"简体中文",
lang:"zh",
...zhGetConfig,
...cnGetConfig,
},
"zh-hk":{
label:"繁體中文(港)",
lang:"zh-hk",
link:"/zh-hk/index",
...hkGetConfig,
themeConfig:{
logo: '/logo.svg',
nav: hkGetNavs,
sidebar:hkGetSidebar,
outline:{
level:[2 ,4],
},
}
},
"zh-tw":{
label:"繁體中文(臺)",
lang:"zh-tw",
link:"/zh-tw/index",
...twGetConfig,
themeConfig:{
logo: '/logo.svg',
nav: twGetNavs,
sidebar:twGetSidebar,
outline:{
level:[2 ,4],
},
}
},
en:{
label:"English",
Expand Down Expand Up @@ -128,9 +167,9 @@ export default defineConfig({
i18nRouting:false,
// https://vitepress.dev/reference/default-theme-config

nav: zhGetNavs,
nav: cnGetNavs,

sidebar: zhGetSidebar,
sidebar: cnGetSidebar,

socialLinks: [
{ icon: 'github', link: 'https://github.com/friendsofhyperf/components' },
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {DefaultTheme} from "vitepress";

const nav:DefaultTheme.NavItem[] = [
// { text: '入门', link: '/zh_CN/guide/' },
{ text: '组件', link: '/zh_CN/components/' },
{ text: 'FAQ', link: '/zh_CN/faq/index' },
{ text: '组件', link: '/zh-cn/components/' },
{ text: 'FAQ', link: '/zh-cn/faq/index' },
{ text: '更多', items:[
{ text: 'Hyperf', link: 'https://hyperf.wiki/' },
{ text: 'MineAdmin', link: 'https://www.mineadmin.com/' }
Expand Down
Loading
Loading