-
Notifications
You must be signed in to change notification settings - Fork 148
feat 阅读Markdown的翻译功能 #130
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
feat 阅读Markdown的翻译功能 #130
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0fceeeb
feat: 优化UI组件样式和交互体验
SummerRay160 bc1f547
Update prose class mapping for font sizes
SummerRay160 47c3495
Adjust SearchBar tooltip/z-index and copy
SummerRay160 77f1fb0
feat(store): 添加应用状态水合检测
SummerRay160 2fc7158
feat(SearchBar): 根据AI配置动态显示搜索模式说明
SummerRay160 6b056a9
refactor(App): 调整加载状态渲染位置以优化代码结构
SummerRay160 87a7138
refactor(App): 调整加载状态和认证检查的顺序
SummerRay160 856cf8e
fix(SearchBar): 更新搜索模式描述文本为回退模式说明
SummerRay160 e5ba02c
Update src/store/useAppStore.ts
SummerRay160 f0dc7dc
feat(翻译): 添加Markdown文档翻译功能
SummerRay160 b3b0a09
Merge branch 'AmintaCCCP:main' into Dev
SummerRay160 be9f3c1
refactor(ReadmeModal): 重构TOC提取逻辑并优化翻译服务
SummerRay160 3b7eb05
feat(markdown): 增强 markdown 解析器以支持更多元素类型
SummerRay160 3f64033
feat(翻译): 实现双语Markdown渲染器并重构翻译逻辑
SummerRay160 a5c8439
fix: 修复翻译服务中的令牌验证和代码块处理问题
SummerRay160 fac94e3
refactor: 优化类型守卫并移除未使用的语言属性
SummerRay160 f722aab
feat(markdown): 改进翻译功能并添加显示模式切换
SummerRay160 fc2b2de
feat: 重构翻译功能并添加DOM文本扫描器
SummerRay160 3db1bf8
fix(BilingualMarkdownRenderer): 安全处理内联代码节点的HTML注入
SummerRay160 5f7265e
fix: 修复翻译功能中的多个问题
SummerRay160 983c5b6
fix(翻译服务): 修复认证过期处理和竞态条件
SummerRay160 6a39a2d
feat(翻译): 改进翻译功能并修复滚动问题
SummerRay160 57b5855
Update src/services/translateService.ts
SummerRay160 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,99 @@ | ||
| import React, { memo, useMemo } from 'react'; | ||
| import MarkdownRenderer from './MarkdownRenderer'; | ||
| import { TranslationSegment } from '../utils/markdownSplitter'; | ||
| import { Loader2 } from 'lucide-react'; | ||
|
|
||
| interface BilingualMarkdownRendererProps { | ||
| segments: TranslationSegment[]; | ||
| baseUrl?: string; | ||
| headingIds?: Map<string, string>; | ||
| fontSize?: 'small' | 'medium' | 'large'; | ||
| showTranslation?: boolean; | ||
| language?: 'zh' | 'en'; | ||
| } | ||
|
|
||
| const SegmentBlock: React.FC<{ | ||
| segment: TranslationSegment; | ||
| baseUrl?: string; | ||
| headingIds?: Map<string, string>; | ||
| fontSize?: 'small' | 'medium' | 'large'; | ||
| showTranslation: boolean; | ||
| language: 'zh' | 'en'; | ||
| }> = memo(({ segment, baseUrl, headingIds, fontSize, showTranslation, language }) => { | ||
| const isTranslating = segment.status === 'translating'; | ||
| const hasTranslation = segment.translatedContent !== null && segment.status === 'done'; | ||
|
|
||
| return ( | ||
| <div className="segment-block mb-4"> | ||
| <div className="original-content"> | ||
| <MarkdownRenderer | ||
| content={segment.originalContent} | ||
| baseUrl={baseUrl} | ||
| headingIds={headingIds} | ||
| fontSize={fontSize} | ||
| enableHtml={true} | ||
| /> | ||
| </div> | ||
|
|
||
| {showTranslation && ( | ||
| <> | ||
| {isTranslating && ( | ||
| <div className="translated-content mt-2 pl-3 border-l-2 border-blue-400/50"> | ||
| <div className="flex items-center gap-2 text-xs text-gray-400 dark:text-text-quaternary"> | ||
| <Loader2 className="w-3 h-3 animate-spin" /> | ||
| <span>{language === 'zh' ? '翻译中...' : 'Translating...'}</span> | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| {hasTranslation && segment.translatedContent && ( | ||
| <div className="translated-content mt-2 pl-3 border-l-2 border-blue-400 dark:border-blue-500"> | ||
| <MarkdownRenderer | ||
| content={segment.translatedContent} | ||
| baseUrl={baseUrl} | ||
| headingIds={headingIds} | ||
| fontSize={fontSize} | ||
| enableHtml={true} | ||
| /> | ||
| </div> | ||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| SegmentBlock.displayName = 'SegmentBlock'; | ||
|
|
||
| const BilingualMarkdownRenderer: React.FC<BilingualMarkdownRendererProps> = memo(({ | ||
| segments, | ||
| baseUrl, | ||
| headingIds, | ||
| fontSize = 'medium', | ||
| showTranslation = true, | ||
| language = 'zh', | ||
| }) => { | ||
| const renderedSegments = useMemo(() => { | ||
| return segments.map((segment) => ( | ||
| <SegmentBlock | ||
| key={segment.id} | ||
| segment={segment} | ||
| baseUrl={baseUrl} | ||
| headingIds={headingIds} | ||
| fontSize={fontSize} | ||
| showTranslation={showTranslation} | ||
| language={language} | ||
| /> | ||
| )); | ||
| }, [segments, baseUrl, headingIds, fontSize, showTranslation, language]); | ||
|
|
||
| return ( | ||
| <div className="bilingual-markdown"> | ||
| {renderedSegments} | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| BilingualMarkdownRenderer.displayName = 'BilingualMarkdownRenderer'; | ||
|
|
||
| export default BilingualMarkdownRenderer; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.