Skip to content

Conversation

@Moskize91
Copy link
Contributor

No description provided.

@Moskize91 Moskize91 requested a review from Copilot July 7, 2025 03:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a user_prompt parameter across the translation pipeline to allow custom rules to be injected, updates the translation template to respect those prompts, and adjusts example scripts to demonstrate its use.

  • Adds user_prompt argument through translate, _Translator, and helper functions.
  • Implements normalization and embedding of user rules via <rules> tags.
  • Updates Jinja template and example scripts to accept and pass user_prompt.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/translate_texts.py Passes new user_prompt and max_threads_count
scripts/translate_epub.py Uses test asset paths and injects user_prompt
epub_translator/translator.py Adds user_prompt parameter and stores it
epub_translator/translation/utils.py Introduces is_empty helper and regex constant
epub_translator/translation/translation.py Propagates user_prompt, normalizes input, and embeds rules
epub_translator/data/translate.jinja Enhances template to conditionally include user rules
Comments suppressed due to low confidence (5)

epub_translator/translation/utils.py:7

  • [nitpick] Consider adding a docstring for is_empty to explain its purpose and the pattern it detects, improving maintainability.
def is_empty(text: str) -> bool:

epub_translator/translation/translation.py:176

  • [nitpick] A docstring describing how _normalize_user_input handles blank lines and merging rules would clarify its behavior for future readers.
def _normalize_user_input(user_lines: list[str]) -> str | None:

epub_translator/translation/translation.py:23

  • New user_prompt handling logic (normalization, embedding <rules>, template branching) needs unit tests to ensure correct integration and formatting.
      user_prompt: str | None,

epub_translator/data/translate.jinja:1

  • It looks like literal line-number prefixes (e.g. 1 ) were accidentally included in the template. Remove those numeric prefixes so they aren't rendered in the translation prompt.
你是一位翻译家,用户接下来的发言会提交一段{% if user_prompt %}翻译要求和一段{% endif %}文本的原文。你要将原文翻译成{{ target_language }}。

scripts/translate_texts.py:25

  • [nitpick] Hardcoding max_threads_count=1 in the script may limit performance. Consider exposing this as a configurable parameter or using the default from the library.
    max_threads_count=1,

@Moskize91 Moskize91 merged commit 3303779 into main Jul 7, 2025
1 check passed
@Moskize91 Moskize91 deleted the user branch July 7, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants