Open → Right-Click → Translate → Auto-Scroll → Save Uses Chrome's built-in translation + OS-level keypress to trigger menu
Automates your exact manual workflow:
- Opens local .txt / .html files directly in Chrome
- Right-clicks → opens Chrome's native context menu
- Sends "T" key DIRECTLY to Chrome (OS-level, not Selenium)
- Auto-scrolls PageDown until ACTUAL bottom reached
- Waits 10 seconds → extracts FULL translated text
- Saves with smart renaming: CH_xxx.txt → EN_xxx.txt, JP→EN
WHY THIS WORKS: Selenium cannot send keys to Chrome's native menu. pyautogui sends keys at OS level → Chrome receives them → menu works.
- Auto language detection (Chrome detects CN/JP automatically)
- Accurate bottom detection (tracks scroll position, NOT height)
- Smart rename: CH→EN, JP→EN, case-insensitive
- Configurable timing (all delays at top of script)
- Minimum scroll safety (always scroll at least 10 times)
- Wait-after-scroll (configurable pause before saving)
- Works on local files only (file:/// URLs)
-
Install dependencies: pip install selenium pyautogui
-
Create 2 folders alongside the script: your_script.py to_translate/ <- PUT YOUR FILES HERE (.txt / .html) translated/ <- Output saved here automatically
-
Run: python translate_script.py
====================================================================== ⚙️ CONFIGURATION (ALL SETTINGS AT TOP OF SCRIPT)
INPUT_FOLDER = "to_translate" <- Source folder OUTPUT_FOLDER = "translated" <- Output folder
WINDOW_WIDTH = 300 <- Chrome window width WINDOW_HEIGHT = 900 <- Chrome window height
PAGEDOWN_WAIT = 0.6 <- Seconds after each PageDown RIGHTCLICK_WAIT = 1.2 <- Wait after right-click BEFORE T WAIT_AFTER_T = 7.0 <- Wait for translation to start WAIT_AFTER_SCROLL = 10.0 <- Wait at bottom BEFORE saving
BOTTOM_CONFIRM_COUNT = 3 <- Confirm bottom X times MIN_SCROLLS = 10 <- Minimum PageDown presses
--- TUNING GUIDE --- Menu opens but T does nothing? -> RIGHTCLICK_WAIT = 1.8 Translation slow? -> WAIT_AFTER_T = 10.0 Stops scrolling early? -> MIN_SCROLLS = 15 Bottom text missing? -> WAIT_AFTER_SCROLL = 15.0 Fast enough? Try decreasing: -> PAGEDOWN_WAIT = 0.5
- Open File -> Chrome loads your local text file
- Right-Click -> Chrome's native menu OPENS
- Send T Key -> OS-level keypress -> Menu receives T -> TRANSLATE STARTS
- Auto-Scroll -> PageDown until scroll position stops changing
- Wait -> Pause 10s -> ensure ALL text fully translated
- Save -> Rename CH/JP->EN -> write to output folder
WHY pyautogui INSTEAD OF SELENIUM KEYS: Selenium send_keys() -> goes to webpage ONLY Chrome native menu -> cannot receive it -> IGNORED pyautogui.press("t") -> sent at OS level -> Chrome receives -> WORKS
BOTTOM DETECTION: OLD (FAILED): measure scrollHeight -> NEVER changes on long text -> STOPS EARLY NEW (WORKS): track window.pageYOffset -> actual scroll position -> STOPS ONLY WHEN MOVEMENT STOPS
FILENAME RENAMING RULES: CH_c1-100.txt -> EN_c1-100.txt JP_novel.txt -> EN_novel.txt ch_chapter5.txt -> en_chapter5.txt JP_Volume2.html -> EN_Volume2.html unknown.txt -> unknown_en.txt (appends _en if no CH/JP found)
- Google Chrome must be installed on your system
- DO NOT touch Chrome window while script runs
- Works on LOCAL FILES ONLY (.txt / .html)
- Internet required (Chrome fetches translation data)
- First run may be slower — let Chrome fully load
to_translate/ CH_Volume1.txt JP_Chapter5.txt
[RUN SCRIPT]
translated/ EN_Volume1.txt EN_Chapter5.txt
Menu opens but nothing happens? -> Increase RIGHTCLICK_WAIT to 1.8 Translation incomplete? -> Increase WAIT_AFTER_T to 10.0 Stops too early? -> Increase MIN_SCROLLS to 15 Bottom text missing? -> Increase WAIT_AFTER_SCROLL to 15.0
- Python 3.7+
- Google Chrome (latest)
- selenium >= 4.0
- pyautogui >= 0.9