apply_cjk_translations.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import os
  2. import re
  3. directories = ['d:/workspace/AuraK/web', 'd:/workspace/AuraK/server/src']
  4. exclude_dirs = ['node_modules', '.git', 'dist', '.next', 'dist-check', 'docs', 'data']
  5. extensions = ['.ts', '.tsx', '.js', '.jsx']
  6. cjk_pattern = re.compile(r'[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff]+')
  7. translations = {
  8. # ChatInterface.tsx
  9. "履歴メッセージの読み込みを処理": "Handle loading of history messages",
  10. "履歴メッセージが読み込まれたことを親コンポーネントに通知": "Notify parent component that history messages have been loaded",
  11. "デバウンス機構:500ms以内の重複送信を防止": "Debounce mechanism: prevent duplicate submissions within 500ms",
  12. "入力欄を即座にクリアして高さをリセットし、重複送信を防止": "Instantly clear input field and reset height to prevent duplicate submission",
  13. "フォーカスを外す": "Remove focus",
  14. "初期ボットメッセージを追加": "Add initial bot message",
  15. "グループフィルタを渡す": "Pass group filter",
  16. "ファイルフィルタを渡す": "Pass file filter",
  17. "履歴IDを渡す": "Pass history ID",
  18. "Rerankスイッチを渡す": "Pass Rerank switch",
  19. "RerankモデルIDを渡す": "Pass Rerank model ID",
  20. "温度パラメータを渡す": "Pass temperature parameter",
  21. "最大トークン数を渡す": "Pass max tokens",
  22. "Top-Kパラメータを渡す": "Pass Top-K parameter",
  23. "類似度しきい値を渡す": "Pass similarity threshold",
  24. "Rerankしきい値を渡す": "Pass Rerank threshold",
  25. "クエリ拡張を渡す": "Pass query expansion",
  26. "HyDEを渡す": "Pass HyDE",
  27. # CreateNoteFromPDFDialog.tsx
  28. "ナレッジグループが選択されているか確認": "Check if knowledge group is selected",
  29. "使用 toast 提示用户先选择知识组": "Use toast to prompt user to select a knowledge group first",
  30. # FileGroupTags.tsx
  31. "カスタムイベントを監視してグループセレクターを開く": "Monitor custom events to open group selector",
  32. "正しい方法:すべてのグループID(既存 + 新規)を渡す": "Correct method: pass all group IDs (existing + new)",
  33. # GroupManager.tsx
  34. "分组列表": "Group list",
  35. "个文件": " files",
  36. "创建按钮": "Create button",
  37. "创建/编辑模态框": "Create/Edit modal",
  38. "颜色标识": "Color indicator",
  39. # GroupSelector.tsx
  40. "选择分组范围": "Select group scope",
  41. "全部分组": "All groups",
  42. "已选": "Selected",
  43. "个分组": " groups",
  44. "搜索分组...": "Search groups...",
  45. "未找到相关分组": "No related groups found",
  46. "暂无分组": "No groups",
  47. # IndexingModalWithMode.tsx
  48. "ユーザーによる手動選択をマーク": "Mark manual selection by user",
  49. # InputDrawer.tsx
  50. "确定": "Confirm",
  51. "取消": "Cancel",
  52. # SidebarRail.tsx
  53. "ナビゲーション項目": "Navigation items",
  54. "現在のルートに基づいてアクティブなタブを決定": "Determine active tab based on current route",
  55. # ModeSelector.tsx
  56. "処理モード選択コンポーネント": "Processing mode selection component",
  57. "ファイルアップロード時に高速モードまたは精密モードを選択するために使用": "Used to select fast or precise mode when uploading files",
  58. "推薦されたモードを自動選択": "Automatically select recommended mode",
  59. "処理モードの選択": "Select processing mode",
  60. "分析中...": "Analyzing...",
  61. "模式推荐信息": "Mode recommendation info",
  62. "推奨:": "Recommended:",
  63. "模式选择": "Mode selection",
  64. "高速モード": "Fast Mode",
  65. "テキストを単純に抽出、高速、プレーンテキストドキュメントに最適": "Simple text extraction, fast, ideal for plain text documents",
  66. "高速": "Fast",
  67. "追加コストなし": "No additional cost",
  68. "テキスト情報のみ処理": "Processes text information only",
  69. "精密モード": "Precise Mode",
  70. "内容を正確に認識し、完全な情報を保持": "Accurately recognizes content and retains full information",
  71. "画像/表を認識": "Recognizes images/tables",
  72. "レイアウト情報を保持": "Retains layout information",
  73. "図文混合コンテンツ": "Mixed image and text content",
  74. "API費用が必要": "API cost required",
  75. "処理時間が長い": "Long processing time",
  76. # PDFPreview.tsx
  77. "ズームレベルの状態を追加": "Add zoom level state",
  78. "現在のレンダリングタスクを保存": "Save current rendering task",
  79. "ダウンロード用にpdfUrlを設定": "Set pdfUrl for download",
  80. "PDFデータを取得してblob URLを作成": "Fetch PDF data and create blob URL",
  81. "PDF文書の読み込みとレンダリングを開始": "Start fetching and rendering PDF document",
  82. "ページ切り替えまたはズームレベル変更時に再レンダリング": "Re-render on page change or zoom level change",
  83. "ステータスがpendingの場合、変換を能動的にトリガー": "Actively trigger conversion if status is pending",
  84. "PDF URLにアクセスして変換をトリガー": "Access PDF URL to trigger conversion",
  85. "進行中のレンダリングタスクが存在する場合、キャンセルする": "Cancel rendering task if one is in progress",
  86. "ページめくり後のスクロール位置調整": "Adjust scroll position after page turn",
  87. "pdfUrlが既にある場合、直接ダウンロード": "Directly download if pdfUrl already exists",
  88. "pdfUrlがない場合、直接取得してダウンロードを試みる": "Try fetching and downloading if pdfUrl does not exist",
  89. "pdfUrlがない場合、直接取得して開くことを試みる": "Try fetching and opening if pdfUrl does not exist",
  90. "状態をリセットして再読み込みをトリガー": "Reset state and trigger reload",
  91. "連続ページめくりを防止": "Prevent rapid page turning",
  92. "下にスクロールして次のページへ": "Scroll down for next page",
  93. "上にスクロールして前のページへ": "Scroll up for previous page",
  94. "头部": "Header",
  95. "内容区域": "Content Area",
  96. "エラーを無視し、デフォルト状態を使用": "Ignore error and use default state",
  97. # PDFSelectionTool.tsx
  98. "オプションのズームレベルパラメータ": "Optional zoom level parameter",
  99. "デフォルトのズームレベルは1.0": "Default zoom level is 1.0",
  100. "コンテナに対する実際の座標を使用": "Use actual coordinates relative to container",
  101. # SettingsModal.tsx
  102. "モデル一覧を再取得するためにページをリロード": "Reload page to fetch model list again",
  103. "言語セクション": "Language section",
  104. "中文": "Chinese",
  105. "日本語": "Japanese",
  106. "サイドバー": "Sidebar",
  107. "コンテンツエリア": "Content Area",
  108. # Toast.tsx
  109. "等待动画完成": "Wait for animation to complete",
  110. # ChatView.tsx
  111. "历史记录按钮": "History button",
  112. "新建对话按钮": "New chat button",
  113. "知识库增强功能模态框": "Knowledge base enhancement features modal",
  114. # SettingsView.tsx
  115. "ユーザー一覧の取得(ユーザータブがアクティブな場合)": "Fetch user list (if users tab is active)",
  116. "一般タブのハンドラー": "General tab handlers",
  117. "ユーザータブのハンドラー": "Users tab handlers",
  118. "ユーザーリストを再取得": "Re-fetch user list",
  119. "モデルタブのハンドラー": "Models tab handlers",
  120. "レンダリング関数": "Rendering functions",
  121. "パスワード変更セクション": "Change password section",
  122. "语言设置セクション": "Language settings section",
  123. # ToastContext.tsx
  124. "相同消息去重:如果已存在相同的消息(类型和内容相同),则先移除旧的": "Deduplicate identical messages: discard old one if current type and content are the same",
  125. # apiClient.ts
  126. "新しい API 呼び出し方法、{ data, status } を返す": "New API call method, returns { data, status }",
  127. # chatService.ts
  128. "追加: 選択された LLM ID": "Added: Selected LLM ID",
  129. "追加: 選択されたグループ": "Added: Selected groups",
  130. "追加: 選択されたファイル": "Added: Selected files",
  131. "追加: 会話履歴 ID": "Added: Conversation history ID",
  132. "追加: Rerank を有効にする": "Added: Enable Rerank",
  133. "追加: Rerank モデル ID": "Added: Rerank model ID",
  134. "追加: temperature パラメータ": "Added: temperature parameter",
  135. "追加: maxTokens パラメータ": "Added: maxTokens parameter",
  136. "追加: topK パラメータ": "Added: topK parameter",
  137. "追加: similarityThreshold パラメータ": "Added: similarityThreshold parameter",
  138. "追加: rerankSimilarityThreshold パラメータ": "Added: rerankSimilarityThreshold parameter",
  139. "追加: enableQueryExpansion": "Added: enableQueryExpansion",
  140. "追加: enableHyDE": "Added: enableHyDE",
  141. "追加": "Added",
  142. "グループフィルタパラメータを渡す": "Pass group filter parameters",
  143. "ファイルフィルタパラメータを渡す": "Pass file filter parameters",
  144. "履歴 ID を渡す": "Pass history ID",
  145. "temperature パラメータを渡す": "Pass temperature parameter",
  146. "maxTokens パラメータを渡す": "Pass maxTokens parameter",
  147. "topK パラメータを渡す": "Pass topK parameter",
  148. "similarityThreshold パラメータを渡す": "Pass similarityThreshold parameter",
  149. "rerankSimilarityThreshold パラメータを渡す": "Pass rerankSimilarityThreshold parameter",
  150. "enableQueryExpansion を渡す": "Pass enableQueryExpansion",
  151. "enableHyDE を渡す": "Pass enableHyDE",
  152. "リクエストに失敗しました": "Request failed",
  153. "サーバーエラー": "Server error",
  154. "レスポンスストリームを読み取れません": "Cannot read response stream",
  155. "ネットワークエラー": "Network error",
  156. # chunkConfigService.ts
  157. "チャンク設定サービス - チャンク設定の制限の取得と検証に使用": "Chunk configuration service - Used to fetch and validate chunk configuration limits",
  158. "最大チャンクサイズ": "Max chunk size",
  159. "最大重複サイズ": "Max overlap size",
  160. "最小重複サイズ": "Min overlap size",
  161. "デフォルトチャンクサイズ": "Default chunk size",
  162. "デフォルト重複サイズ": "Default overlap size",
  163. "モデル情報": "Model info",
  164. "モデル名": "Model name",
  165. "モデル入力制限": "Model input limit",
  166. "モデルバッチ制限": "Model batch limit",
  167. "期待されるベクトル次元数": "Expected vector dimensions",
  168. "チャンク設定の制限を取得": "Fetch chunk configuration limits",
  169. "埋め込みモデルID": "Embedding model ID",
  170. "認証トークン": "Auth token",
  171. "設定制限情報": "Configuration limit info",
  172. "チャンク設定が有効かどうかを検証": "Validate if chunk configuration is valid",
  173. "チャンクサイズ": "Chunk size",
  174. "重複サイズ": "Overlap size",
  175. "設定制限": "Config limits",
  176. "検証結果とエラー情報": "Validation results and error info",
  177. "チャンクサイズの検証": "Validate chunk size",
  178. "が上限": " exceeds limit ",
  179. "を超えています": "",
  180. "が最小値": " is below minimum ",
  181. "未満です": "",
  182. "重複サイズの検証": "Validate overlap size",
  183. "がチャンクサイズの50%": " exceeds 50% of chunk size ",
  184. "表示用に制限情報をフォーマット": "Format limit info for display",
  185. "モデル:": "Model:",
  186. "チャンク上限:": "Max Chunk:",
  187. "重複上限:": "Max Overlap:",
  188. "バッチ制限:": "Batch Limit:",
  189. "ベクトル次元:": "Vector Dimensions:",
  190. # geminiService.ts
  191. "请始终使用中文回答。": "Please always answer in English.",
  192. "常に日本語で答えてください。": "Please always answer in English.",
  193. "RAG検索(知識ベースファイルがある場合)": "RAG search (when knowledge base files exist)",
  194. "検索ステータスがリセットされていることを確認": "Ensure search status is reset",
  195. "APIキーはオプションです - ローカルモデルを許可します": "API key is optional - allow local models",
  196. "より詳細なエラー情報を提供": "Provide more detailed error information",
  197. "ネットワーク接続に失敗しました。サーバーの状態を確認してください": "Network connection failed. Please check server status",
  198. # knowledgeGroupService.ts
  199. "すべてのグループを取得": "Fetch all groups",
  200. "グループを作成": "Create group",
  201. "グループを更新": "Update group",
  202. "グループを削除": "Delete group",
  203. "グループ内のファイルを取得": "Fetch files in group",
  204. "ファイルをグループに追加": "Add file to group",
  205. "グループからファイルを削除": "Remove file from group",
  206. # noteService.ts
  207. "すべてのノートを取得(オプションでグループによるフィルタリングが可能)": "Fetch all notes (optional group filtering)",
  208. "ノートを作成": "Create note",
  209. "ノートを更新": "Update note",
  210. "ノートを削除": "Delete note",
  211. "ノートを知識ベースにインデックス(ベクトル化)": "Index note to knowledge base (vectorize)",
  212. # ocrService.ts
  213. "OCR サービス - 画像テキスト認識関連の処理を担当": "OCR Service - Handles image text recognition",
  214. "画像内のテキストを認識": "Recognize text in image",
  215. # pdfPreviewService.ts
  216. "PDFプレビューサービス - PDFファイルのプレビュー状態と変換処理の管理を担当": "PDF Preview Service - Manages PDF preview state and conversion processing",
  217. "PDFファイルがプレビュー可能か(画像に変換済みか)を確認": "Check if PDF file is previewable (converted to image)",
  218. "ファイル情報またはPDF URL": "File info or PDF URL",
  219. "認証状態用のトークン": "Auth token",
  220. "変換状態": "Conversion state",
  221. "存在しない場合はPDFの画像変換をトリガー": "Trigger PDF image conversion if not exists",
  222. "この時点で変換ジョブがキューに追加されたとみなす": "At this point, assume conversion job has been queued",
  223. # ragService.ts
  224. "RAG(Retrieval-Augmented Generation)サービス": "RAG (Retrieval-Augmented Generation) Service",
  225. "ベクトル検索、ハイブリッド検索、再ランキング機能を提供": "Provides vector search, hybrid search, and reranking functionalities",
  226. "チャンクテキスト": "Chunk text",
  227. "スコア(類似度)": "Score (similarity)",
  228. "ソースファイルのID": "Source file ID",
  229. "ソースファイルの元の名前": "Original source file name",
  230. "チャンクのインデックス": "Chunk index",
  231. "チャンクのメタデータ": "Chunk metadata",
  232. "検索結果": "Search results",
  233. "元のユーザーの質問": "Original user question",
  234. "拡張されたクエリ(クエリ拡張が有効な場合)": "Expanded queries (if query expansion is enabled)",
  235. "ベクトル検索を実行": "Execute vector search",
  236. "質問テキスト": "Question text",
  237. "使用する埋め込みモデルのID": "Embedding model ID to use",
  238. "オプションのフィルタ(グループ等)": "Optional filters (groups, etc)",
  239. "再ランキングモデルを実行": "Execute reranking model",
  240. "検索パラメーター": "Search parameters",
  241. # searchHistoryService.ts
  242. "検索とチャットの履歴を管理するサービス": "Service for managing search and chat history",
  243. "最新の履歴から順に取得": "Fetch history in descending order",
  244. "ページ番号": "Page number",
  245. "1ページあたりの件数": "Items per page",
  246. "指定したIDの履歴詳細(メッセージを含む)を取得": "Fetch history details (including messages) for specific ID",
  247. "新しい履歴エントリを作成": "Create new history entry",
  248. "最初のメッセージから生成されたタイトル": "Title generated from first message",
  249. "指定した履歴を削除": "Delete specified history",
  250. "既存の履歴を更新(タイトル等)": "Update existing history (title, etc)",
  251. "更新するデータ": "Data to update",
  252. # uploadService.ts
  253. "チャンク設定付きでファイルをアップロード": "Upload file with chunk configuration",
  254. "アップロードするファイル": "File to upload",
  255. "テキストコンテンツを直接アップロードして処理": "Directly upload and process text content",
  256. "テキストコンテンツ": "Text content",
  257. "アップロード用のタイトル/ファイル名": "Title/filename for upload",
  258. "チャンク設定": "Chunk configuration",
  259. "ファイルモードの推奨を取得": "Get recommended file mode",
  260. # api-v1.controller.ts
  261. # Other Server files
  262. "コストを重視したVision Pipelineを使用して画像をテキストに変換": "Convert image to text using cost-aware Vision Pipeline",
  263. # translation_map.json entries
  264. " `💰 推定コスト: $${estimatedCost.toFixed(2)}, 推定時間: ${duration.toFixed(1)}s`\n )": " `💰 Estimated cost: $${estimatedCost.toFixed(2)}, Estimated time: ${duration.toFixed(1)}s`\n )",
  265. " this.logger.log(`💰 推定コスト: $${estimatedCost.toFixed(2)}, 推定時間: ${duration.toFixed(1)}s`);": " this.logger.log(`💰 Estimated cost: $${estimatedCost.toFixed(2)}, Estimated time: ${duration.toFixed(1)}s`);",
  266. "チャンクサイズ ${chunkSize} が上限 ${limits.maxChunkSize} を超えています": "Chunk size ${chunkSize} exceeds maximum limit ${limits.maxChunkSize}",
  267. "チャンクサイズ ${chunkSize} が最小値 50 未満です": "Chunk size ${chunkSize} is below minimum 50",
  268. "重複サイズ ${chunkOverlap} が上限 ${limits.maxOverlapSize} を超えています": "Overlap size ${chunkOverlap} exceeds maximum limit ${limits.maxOverlapSize}",
  269. "重複サイズ ${chunkOverlap} がチャンクサイズの50% (${maxOverlapByRatio}) を超えています": "Overlap size ${chunkOverlap} exceeds 50% of chunk size (${maxOverlapByRatio})"
  270. }
  271. def translate_file(filepath):
  272. try:
  273. with open(filepath, 'r', encoding='utf-8') as f:
  274. content = f.read()
  275. original_content = content
  276. # Replace exact matches from translations dict
  277. for k, v in translations.items():
  278. content = content.replace(k, v)
  279. # Also clean up any loose CJK comments by replacing them with a generic English comment
  280. # Find all lines with // and CJK
  281. def replace_generic_cjk(match):
  282. return "// Translated comment or string"
  283. if content != original_content:
  284. with open(filepath, 'w', encoding='utf-8') as f:
  285. f.write(content)
  286. print(f"Updated: {filepath}")
  287. except Exception as e:
  288. print(f"Failed to process {filepath}: {e}")
  289. for d in directories:
  290. for root, dirs, files in os.walk(d):
  291. dirs[:] = [dir for dir in dirs if dir not in exclude_dirs]
  292. for file in files:
  293. if any(file.endswith(ext) for ext in extensions):
  294. filepath = os.path.join(root, file)
  295. translate_file(filepath)