Skip to content

Commit b472d56

Browse files
committed
feat: update translate docs workflow inputs
1 parent 0d47e77 commit b472d56

File tree

4 files changed

+106
-9
lines changed

4 files changed

+106
-9
lines changed

.github/actions/translate-docs/action.yml

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@ name: "Translate Documentation Action"
22
description: "Translates documentation files automatically using AI"
33

44
inputs:
5+
list_only:
6+
description: "Only list file status without updating docs"
7+
required: false
8+
default: "false"
9+
target_language:
10+
description: "Specify the target language code for translation (e.g., 'zh-hans', 'fr', 'es')"
11+
required: false
12+
default: ""
13+
pattern:
14+
description: "File pattern to match for updating (e.g., '*.mdx' or 'docs/**/*.mdx')"
15+
required: false
16+
default: ""
17+
max_files:
18+
description: "Maximum number of files to process in one batch (per language)"
19+
required: false
20+
default: ""
21+
concurrency:
22+
description: "Number of concurrent translation tasks"
23+
required: false
24+
default: ""
25+
model:
26+
description: "DeepSeek model to use: 'deepseek-chat' or 'deepseek-reasoner'"
27+
required: false
28+
default: ""
529
custom_arguments:
6-
description: "Custom arguments to pass to the translation package command"
30+
description: "Additional custom arguments to pass to the translation package command"
731
required: false
832
default: ""
933
github_token:
@@ -97,8 +121,39 @@ runs:
97121
if: steps.check_branch.outputs.exists == 'false'
98122
shell: bash
99123
run: |
100-
echo "Running translation with custom arguments: ${{ inputs.custom_arguments }}"
101-
${{ inputs.translation_command }} ${{ inputs.custom_arguments }}
124+
# Build command with individual arguments
125+
COMMAND="${{ inputs.translation_command }}"
126+
127+
if [ "${{ inputs.list_only }}" = "true" ]; then
128+
COMMAND="$COMMAND --list-only"
129+
fi
130+
131+
if [ -n "${{ inputs.target_language }}" ]; then
132+
COMMAND="$COMMAND --target-language ${{ inputs.target_language }}"
133+
fi
134+
135+
if [ -n "${{ inputs.pattern }}" ]; then
136+
COMMAND="$COMMAND --pattern ${{ inputs.pattern }}"
137+
fi
138+
139+
if [ -n "${{ inputs.max_files }}" ]; then
140+
COMMAND="$COMMAND --max ${{ inputs.max_files }}"
141+
fi
142+
143+
if [ -n "${{ inputs.concurrency }}" ]; then
144+
COMMAND="$COMMAND --concurrency ${{ inputs.concurrency }}"
145+
fi
146+
147+
if [ -n "${{ inputs.model }}" ]; then
148+
COMMAND="$COMMAND --model ${{ inputs.model }}"
149+
fi
150+
151+
if [ -n "${{ inputs.custom_arguments }}" ]; then
152+
COMMAND="$COMMAND ${{ inputs.custom_arguments }}"
153+
fi
154+
155+
echo "Running translation command: $COMMAND"
156+
eval $COMMAND
102157
env:
103158
OPENAI_API_KEY: ${{ inputs.api_key }}
104159

.github/workflows/translate-docs.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,38 @@ on:
1717
required: false
1818
type: string
1919
default: 'docs/update-translations'
20+
list_only:
21+
description: 'Only list file status without updating docs'
22+
required: false
23+
type: boolean
24+
default: false
25+
target_language:
26+
description: 'Specify the target language code for translation (e.g., "zh-hans", "fr", "es")'
27+
required: false
28+
type: string
29+
pattern:
30+
description: 'File pattern to match for updating (e.g., "*.mdx" or "docs/**/*.mdx")'
31+
required: false
32+
type: string
33+
max_files:
34+
description: 'Maximum number of files to process in one batch (per language)'
35+
required: false
36+
type: number
37+
concurrency:
38+
description: 'Number of concurrent translation tasks'
39+
required: false
40+
type: number
41+
default: 10
42+
model:
43+
description: 'DeepSeek model to use'
44+
required: false
45+
type: choice
46+
options:
47+
- deepseek-chat
48+
- deepseek-reasoner
49+
default: deepseek-chat
2050
custom_arguments:
21-
description: 'Custom arguments to pass to the translation package command. e.g., "-t zh-hans"'
51+
description: 'Additional custom arguments to pass to the translation package command'
2252
required: false
2353
type: string
2454

@@ -58,8 +88,15 @@ jobs:
5888
api_key: ${{ secrets.OPENAI_API_KEY }}
5989
# Optional inputs with their default values shown
6090
github_token: ${{ secrets.PAT_TOKEN }} # Use PAT instead of GITHUB_TOKEN
61-
custom_arguments: ${{ github.event.inputs.custom_arguments }}
6291
pr_branch: ${{ github.event.inputs.pr_branch || 'docs/update-translations' }}
92+
# Translation-specific inputs
93+
list_only: ${{ github.event.inputs.list_only }}
94+
target_language: ${{ github.event.inputs.target_language }}
95+
pattern: ${{ github.event.inputs.pattern }}
96+
max_files: ${{ github.event.inputs.max_files }}
97+
concurrency: ${{ github.event.inputs.concurrency }}
98+
model: ${{ github.event.inputs.model }}
99+
custom_arguments: ${{ github.event.inputs.custom_arguments }}
63100
# translation_command: 'pnpm run translate'
64101
base_branch: 'dev'
65102
# pr_branch: 'docs/update-translations'

packages/translate/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function main({
4949

5050
logger.divider();
5151
logger.info(
52-
`Translation for ${docsRoot} in languages: ${LANGUAGES.join(', ')} started!`,
52+
`Translation for ${docsRoot} in languages: ${LANGUAGES.join(', ')} using ${model} started!`,
5353
);
5454

5555
// Normalize paths and prepare patterns
@@ -157,6 +157,7 @@ export async function main({
157157
const { shouldUpdate, reason, chunks } = await getDocUpdateStatus({
158158
sourcePath,
159159
targetPath,
160+
model,
160161
});
161162

162163
if (verbose) {

packages/translate/src/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface LangConfig {
1818
interface CheckFileUpdateParams {
1919
sourcePath: string;
2020
targetPath: string;
21+
model?: DeepSeekModel;
2122
}
2223

2324
interface BuildTranslationContextParams {
@@ -60,6 +61,7 @@ export function getLastModifiedTimeFromGit(filePath: string): Date {
6061
export async function getDocUpdateStatus({
6162
sourcePath,
6263
targetPath,
64+
model = 'deepseek-chat',
6365
}: CheckFileUpdateParams): Promise<{
6466
shouldUpdate: boolean;
6567
chunks: 'N/A' | number;
@@ -75,8 +77,8 @@ export async function getDocUpdateStatus({
7577
}
7678

7779
const sourceContent = await fs$.readFile(sourcePath, 'utf8');
78-
const chunks = needsChunking(sourceContent)
79-
? splitIntoChunks(sourceContent).length
80+
const chunks = needsChunking(sourceContent, model)
81+
? splitIntoChunks(sourceContent, model).length
8082
: 1;
8183

8284
try {
@@ -179,7 +181,9 @@ export async function translateDoc({
179181
model = 'deepseek-chat',
180182
}: TranslateDocumentFileParams) {
181183
// Create directory if it doesn't exist
182-
logger.debug(`Translating ${sourcePath} to ${targetPath}`);
184+
logger.debug(
185+
`Translating ${sourcePath} to ${targetPath} using model ${model}`,
186+
);
183187
await fs$.mkdir(path.dirname(targetPath), { recursive: true });
184188

185189
// Read source file

0 commit comments

Comments
 (0)