-
-
Notifications
You must be signed in to change notification settings - Fork 27
Adds translate support #815
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f59fb7c
Adds translate support
huangdijia 6fd17ee
ci: 优化翻译文档工作流,移除冗余依赖安装步骤
huangdijia 3cedccd
修正文档路径中的语言代码分隔符,从 'zh-CN' 更改为 'zh_CN'
huangdijia 88a5351
恢复对繁体中文和香港中文的支持,更新文档翻译配置
huangdijia 25604d7
Update docs and translate
huangdijia 38a3a64
Revert "Update docs and translate"
huangdijia dd1fbd7
新增简体中文文档,包含常见问题、入门指南、组件说明及相关支持文档
huangdijia 1e009a1
新增简体中文、繁体中文和台湾中文的配置和导航文件,删除旧的中文文件
huangdijia 843a22a
Update docs and translate
huangdijia 86126f2
更新配置文件,新增简体中文、繁体中文(港)、繁体中文(台)支持,并恢复英文配置
huangdijia 55d9c35
更新繁体中文(港)和繁体中文(台)文档链接,确保导航和组件链接指向正确的语言版本
huangdijia fb5c8b4
更新文档翻译工作流,排除主分支的推送触发
huangdijia 18acce0
更新文档翻译工作流,仅在文档目录下的更改时触发
huangdijia 1992bc1
更新文档翻译工作流,移除对主分支的推送触发限制
huangdijia d1e9c8b
重构文档工作流,合并翻译和拆分功能,移除旧的工作流配置
huangdijia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| $targetTranslatedPath = $targetDir . $fileInfo->getRelativePathname(); | ||
| @copy($fileInfo->getRealPath(), $targetTranslatedPath); | ||
| } | ||
| } | ||
| opencc_close($od); | ||
| } | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
docs/.vitepress/src/zh/nav.ts → docs/.vitepress/src/zh-cn/nav.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
建议添加错误处理逻辑
在使用
@file_put_contents与@copy时,为避免忽略潜在错误(如磁盘空间不足、权限不足等),建议去掉@并加上异常捕获或判定写入和复制结果是否成功,以便及时发现并处理异常情况。Also applies to: 59-59