mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
fix
This commit is contained in:
8
.github/workflows/sync_docs_execute.yml
vendored
8
.github/workflows/sync_docs_execute.yml
vendored
@@ -473,8 +473,8 @@ jobs:
|
||||
openapi_files_to_sync = sync_plan.get("openapi_files_to_sync", [])
|
||||
print(f"\nProcessing {len(openapi_files_to_sync)} OpenAPI files...")
|
||||
|
||||
# Import OpenAPI translation function
|
||||
from openapi import translate_openapi_file
|
||||
# Import OpenAPI translation function (async version)
|
||||
from openapi import translate_openapi_file_async
|
||||
|
||||
for file_info in openapi_files_to_sync[:5]: # Limit to 5 OpenAPI files
|
||||
file_path = file_info["path"]
|
||||
@@ -494,8 +494,8 @@ jobs:
|
||||
# Ensure target directory exists
|
||||
target_full_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Run OpenAPI translation pipeline
|
||||
success = translate_openapi_file(
|
||||
# Run OpenAPI translation pipeline (use await for async version)
|
||||
success = await translate_openapi_file_async(
|
||||
source_file=str(source_full_path),
|
||||
target_lang=target_lang,
|
||||
output_file=str(target_full_path),
|
||||
|
||||
@@ -14,9 +14,9 @@ from pathlib import Path
|
||||
import tempfile
|
||||
|
||||
|
||||
def translate_openapi_file(source_file: str, target_lang: str, output_file: str, dify_api_key: str = None) -> bool:
|
||||
async def translate_openapi_file_async(source_file: str, target_lang: str, output_file: str, dify_api_key: str = None) -> bool:
|
||||
"""
|
||||
Complete pipeline to translate an OpenAPI JSON file.
|
||||
Complete pipeline to translate an OpenAPI JSON file (async version).
|
||||
|
||||
Pipeline stages:
|
||||
1. Extract: Pull all translatable fields into markdown
|
||||
@@ -57,10 +57,10 @@ def translate_openapi_file(source_file: str, target_lang: str, output_file: str,
|
||||
print(f" ✓ Saved extraction map: {extraction_map_path}")
|
||||
print(f" ✓ Saved markdown for translation: {markdown_path}")
|
||||
|
||||
# Step 2: Translate via Dify API
|
||||
# Step 2: Translate via Dify API (use async version)
|
||||
print(f"\n🌐 Step 2/3: Translating to {target_lang}...")
|
||||
translator = OpenAPITranslator(markdown_path, target_lang, dify_api_key)
|
||||
translated_text = translator.translate()
|
||||
translated_text = await translator.translate_async()
|
||||
|
||||
translator.save_translation(translated_md_path, translated_text)
|
||||
print(f" ✓ Translation complete")
|
||||
@@ -107,5 +107,27 @@ def translate_openapi_file(source_file: str, target_lang: str, output_file: str,
|
||||
print(f"🗂️ Temp files kept for debugging: {temp_dir}")
|
||||
|
||||
|
||||
# Export main function
|
||||
__all__ = ['translate_openapi_file', 'OpenAPIExtractor', 'OpenAPITranslator', 'OpenAPIRehydrator']
|
||||
def translate_openapi_file(source_file: str, target_lang: str, output_file: str, dify_api_key: str = None) -> bool:
|
||||
"""
|
||||
Complete pipeline to translate an OpenAPI JSON file (sync wrapper).
|
||||
|
||||
Pipeline stages:
|
||||
1. Extract: Pull all translatable fields into markdown
|
||||
2. Translate: Send to Dify API for translation
|
||||
3. Re-hydrate: Merge translations back into JSON structure
|
||||
|
||||
Args:
|
||||
source_file: Path to source English OpenAPI JSON file
|
||||
target_lang: Target language code (cn, jp)
|
||||
output_file: Path to save translated JSON file
|
||||
dify_api_key: Optional Dify API key (if None, loads from env)
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
import asyncio
|
||||
return asyncio.run(translate_openapi_file_async(source_file, target_lang, output_file, dify_api_key))
|
||||
|
||||
|
||||
# Export main functions
|
||||
__all__ = ['translate_openapi_file', 'translate_openapi_file_async', 'OpenAPIExtractor', 'OpenAPITranslator', 'OpenAPIRehydrator']
|
||||
|
||||
@@ -23,7 +23,7 @@ from main import translate_text, load_md_mdx
|
||||
from json_formatter import save_json_with_preserved_format
|
||||
|
||||
# Import OpenAPI translation pipeline
|
||||
from openapi import translate_openapi_file
|
||||
from openapi import translate_openapi_file, translate_openapi_file_async
|
||||
|
||||
# Import security validator
|
||||
try:
|
||||
@@ -1370,8 +1370,8 @@ class DocsSynchronizer:
|
||||
# Ensure target directory exists
|
||||
target_full_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Run OpenAPI translation pipeline
|
||||
success = translate_openapi_file(
|
||||
# Run OpenAPI translation pipeline (use async version)
|
||||
success = await translate_openapi_file_async(
|
||||
source_file=str(source_full_path),
|
||||
target_lang=target_lang,
|
||||
output_file=str(target_full_path),
|
||||
|
||||
Reference in New Issue
Block a user