### Install SoMaJo dependency Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20add%20a%20program%20as%20dictionary Install the SoMaJo library via pip to enable German sentence tokenization. ```bash pip install -U SoMaJo ``` -------------------------------- ### Install GoldenDict-NG on macOS Source: https://xiaoyifang.github.io/goldendict-ng/howto/build_from_source Installs the built GoldenDict-NG application on macOS. This command invokes macdeployqt and code signing, preparing the application for distribution. ```bash cmake --install build_dir/ ``` -------------------------------- ### Specify Qt6 Installation Path for Windows CMake Source: https://xiaoyifang.github.io/goldendict-ng/howto/build_from_source Use this CMake option on Windows to point to your Qt6 installation directory, especially when using MSVC. Ensure the path is correct for your installation. ```bash -DCMAKE_PREFIX_PATH=F:\Qt\6.4.1\msvc2019_64 ``` -------------------------------- ### Install Debian/Ubuntu Dependencies Source: https://xiaoyifang.github.io/goldendict-ng/howto/build_from_source Installs all required packages for building GoldenDict-NG on Debian-based systems like Ubuntu. Ensure your package list is up-to-date before running. ```bash sudo apt-get install build-essential ninja-build \ libvorbis-dev zlib1g-dev libhunspell-dev x11proto-record-dev \ libxtst-dev liblzo2-dev libbz2-dev libavutil-dev libavformat-dev \ libeb16-dev libzstd-dev libxkbcommon-dev libxapian-dev libzim-dev \ libopencc-dev libfmt-dev qt6-5compat-dev qt6-base-dev qt6-multimedia-dev \ qt6-speech-dev qt6-svg-dev qt6-tools-dev qt6-tools-dev-tools \ qt6-webchannel-dev qt6-webengine-dev ``` -------------------------------- ### Configure and Build GoldenDict-NG with CMake Source: https://xiaoyifang.github.io/goldendict-ng/howto/build_from_source Commands to configure, build, and install GoldenDict-NG using CMake. The optional arguments allow customization of the build process. ```bash cd goldendict-ng && mkdir build_dir # config step cmake -S . -B build_dir -G "Ninja"/"Unix Makefiles"/"Xcode"... (Optional) --install-prefix=/usr/local/ (Optional) -DCMAKE_BUILD_TYPE=Release (Optional) # actual build cmake --build build_dir --parallel 7 (Optional if Ninja was chosen) cmake --install ./build_dir/ ``` -------------------------------- ### Configure VLC as External Audio Engine Source: https://xiaoyifang.github.io/goldendict-ng/ui_audioengine Use this command to configure VLC as an external audio player. Ensure VLC is installed and accessible in your system's PATH. ```bash vlc --intf dummy --play-and-exit ``` -------------------------------- ### Configure CMake for VS Code Source: https://xiaoyifang.github.io/goldendict-ng/developer When using Visual Studio Code with CMake Tools, you need to specify the path to your Qt installation and other options in the configure arguments. Ensure the path points to your specific Qt version and compiler. ```bash -DCMAKE_PREFIX_PATH={Your Qt install path}\6.7.2\msvc2019_64 ``` -------------------------------- ### Build from Source with FFmpeg Player Enabled Source: https://xiaoyifang.github.io/goldendict-ng/faq To enable the ffmpeg audio player when building from source, use the CMake flag -DWITH_FFMPEG_PLAYER=ON. ```bash -DWITH_FFMPEG_PLAYER=ON ``` -------------------------------- ### Configure ffplay as External Program Source: https://xiaoyifang.github.io/goldendict-ng/faq If you need to use ffmpeg audio player and Qt6.5+ is not sufficient, you can configure ffplay as an external program. ```bash ffplay ``` -------------------------------- ### Execute host programs from Flatpak Source: https://xiaoyifang.github.io/goldendict-ng/topic_flatpak Use flatpak-spawn to run host-side applications from within the Flatpak sandbox. ```bash flatpak-spawn --host --directory=${the external program's pwd will be set to this value} ${The actual commands} ``` ```bash flatpak-spawn --host --directory=. trans -no-ansi %GDWORD% ``` -------------------------------- ### Configure Custom Dictionary Icon Source: https://xiaoyifang.github.io/goldendict-ng/dictformats Place an icon file with the same basename as the dictionary file in the same directory. ```text . ├── My_best_dictionary.mdx <- the main dictionary file └── My_best_dictionary.svg <- the icon ``` -------------------------------- ### Directory structure for metadata.toml Source: https://xiaoyifang.github.io/goldendict-ng/custom_dictionary Place the metadata.toml file in the root folder of each dictionary alongside the dictionary files. ```text . ├── Cambridge │ ├── metadata.toml < here │ ├── Cambridge.idx │ ├── Cambridge.info │ ├── Cambridge.syn │ └── Cambridge.dict.dz └── Collins ├── metadata.toml < here ├── res.zip └── Collins.dsl ``` -------------------------------- ### Create Python tokenization script Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20add%20a%20program%20as%20dictionary A script that accepts a sentence as a command-line argument and prints tokenized words. ```python from somajo import SoMaJo import sys tokenizer = SoMaJo("de_CMC", split_camel_case=True) # note that paragraphs are allowed to contain newlines paragraphs = [sys.argv[1]] sentences = tokenizer.tokenize_text(paragraphs) for sentence in sentences: for token in sentence: if token.token_class=='regular': print(f"{token.text}") ``` -------------------------------- ### Configure mpv as External Audio Engine Source: https://xiaoyifang.github.io/goldendict-ng/ui_audioengine Use this command to configure mpv as an external audio player. mpv is a free and open-source media player. ```bash mpv --no-video --no-audio-display ``` -------------------------------- ### Analyze Dump File with minidump_stackwalk (Google Version) Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20use%20breadpad%20crash%20analysis Analyze a crash dump file using minidump_stackwalk and a symbols directory. The output is redirected to a text file for review. ```bash minidump_stackwalk.exe -s a.dmp symbols > a.txt ``` -------------------------------- ### Configuration Folder Structure Source: https://xiaoyifang.github.io/goldendict-ng/topic_userstyle The expected layout of the GoldenDict configuration directory. ```text . ├── config ├── article-style.css ├── article-style-print.css (affecting styles when printing) ├── article-script.js └── qt-style.css ``` -------------------------------- ### Generate Symbol File with dump_syms (Google Version) Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20use%20breadpad%20crash%20analysis Use dump_syms.exe to generate a symbol file from a PDB file. The output format is specific and used for crash analysis with Google's tools. ```bash dump_syms.exe GoldenDict.pdb > GoldenDict.sym ``` -------------------------------- ### List exported Flatpak documents Source: https://xiaoyifang.github.io/goldendict-ng/topic_flatpak View the directories currently exported to the Flatpak application via the file chooser. ```bash flatpak documents --columns=id,origin,application ``` -------------------------------- ### Injecting Direct JavaScript Code Source: https://xiaoyifang.github.io/goldendict-ng/topic_website_scripting Use this pattern to apply styles or behavior directly within the configuration field without an external file. ```javascript document.addEventListener('DOMContentLoaded', function() { document.body.style.backgroundColor = '#f0f0f0'; }); ``` -------------------------------- ### Define Addon Styles Directory Structure Source: https://xiaoyifang.github.io/goldendict-ng/topic_userstyle Represents the required file system hierarchy for enabling multiple switchable themes in GoldenDict-NG settings. ```text . ├── config └── styles ├── dark │ ├── article-style.css │ └── qt-style.css └── light ├── article-style.css └── qt-style.css ``` -------------------------------- ### Linux OCR with Tesseract and GoldenDict Source: https://xiaoyifang.github.io/goldendict-ng/howto/ocr A bash script for Linux that captures a screenshot using spectacle or grim, performs OCR with Tesseract, and then passes the recognized text to GoldenDict. It handles different desktop environments (sway, KDE) and cleans up temporary files. ```bash #!/usr/bin/env bash set -e case $DESKTOP_SESSION in sway) grim -g "$(slurp)" /tmp/tmp.just_random_name.png ;; plasmawayland | plasma) spectacle --region --nonotify --background \ --output /tmp/tmp.just_random_name.png ;; *) echo "Failed to know desktop type" exit 1 ;; esac # note that tesseract will apppend .txt to output file tesseract /tmp/tmp.just_random_name.png /tmp/tmp.just_random_name --oem 1 -l eng goldendict "$(cat /tmp/tmp.just_random_name.txt)" rm /tmp/tmp.just_random_name.png rm /tmp/tmp.just_random_name.txt ``` -------------------------------- ### Configure external program command Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20add%20a%20program%20as%20dictionary The command line string to be used in the GoldenDict-NG program dictionary settings. ```text python e:\test.py %GDWORD% ``` -------------------------------- ### Configure ffplay as External Audio Engine Source: https://xiaoyifang.github.io/goldendict-ng/ui_audioengine Use this command to configure ffplay as an external audio player. ffplay is part of the FFmpeg suite. ```bash ffplay -autoexit -nodisp ``` -------------------------------- ### Analyze Dump File with minidump-stackwalk (Mozilla/Rust) Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20use%20breadpad%20crash%20analysis Process a crash dump file using minidump-stackwalk and the generated symbol file to produce a text report of the stack trace. This is part of the Mozilla/Rust toolchain. ```bash .\minidump-stackwalk.exe .\crash.dmp .\goldendict.sym > f.txt ``` -------------------------------- ### Force XWayland (X11) Mode Source: https://xiaoyifang.github.io/goldendict-ng/topic_wayland Run GoldenDict-NG in X11 mode to enable features like global hotkeys and the ScanPopup. This is recommended if native Wayland mode causes issues with these features. ```bash env GOLDENDICT_FORCE_XCB=1 goldendict ``` -------------------------------- ### Customize Interface Styles Source: https://xiaoyifang.github.io/goldendict-ng/topic_userstyle Qt Style Sheet rules for modifying the GoldenDict application interface components. ```css /* Change main window background */ QMainWindow { background-color: #f0f0f0; } /* Change toolbar style */ QToolBar { background-color: #333; border: none; padding: 4px; } /* High contrast toolbar buttons */ QToolBar QPushButton { background-color: #4CAF50; color: white; border: 2px solid #388E3C; border-radius: 4px; padding: 6px 12px; font-weight: bold; min-width: 80px; } QToolBar QPushButton:hover { background-color: #45a049; border-color: #2E7D32; } QToolBar QPushButton:pressed { background-color: #388E3C; border-color: #1B5E20; } /* Change general button style */ QPushButton { background-color: #3498db; color: white; border: none; border-radius: 3px; padding: 5px 10px; font-weight: bold; } QPushButton:hover { background-color: #2980b9; } /* Change input box style */ QLineEdit { border: 1px solid #bdc3c7; border-radius: 3px; padding: 5px; background-color: white; } /* Change list and tree view style */ QListWidget, QTreeWidget { background-color: white; border: 1px solid #bdc3c7; border-radius: 3px; } QListWidget::item:selected, QTreeWidget::item:selected { background-color: #bbdefb; color: #2c3e50; } ``` -------------------------------- ### Update crowdin.ts with lupdate Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20update%20crowdin.ts%20file Run this command to synchronize the crowdin.ts file with the source code. The -no-obsolete and -no-ui-lines flags help maintain a clean commit history. ```bash lupdate.exe -no-obsolete -no-ui-lines -locations none .\src\ -ts .\locale\crowdin.ts ``` -------------------------------- ### Capture2Text Output Action Configuration Source: https://xiaoyifang.github.io/goldendict-ng/howto/ocr Configure Capture2Text to call GoldenDict after capturing text. Ensure the path to GoldenDict.exe is correct and the "${capture}" argument is used to pass the captured text. ```bash path_to_the_GD_executable\GoldenDict.exe "${capture}" ``` -------------------------------- ### Configure full-text search settings Source: https://xiaoyifang.github.io/goldendict-ng/custom_dictionary Control full-text search status using the fts field. Valid values include on/off, 1/0, and true/false. ```toml fts=false [metadata] name="New Name" ``` ```toml fts=false ``` -------------------------------- ### Force Native Wayland Mode Source: https://xiaoyifang.github.io/goldendict-ng/topic_wayland Use this command to explicitly run GoldenDict-NG in native Wayland mode. This is the default behavior but can be forced if needed. ```bash env GOLDENDICT_FORCE_WAYLAND=1 goldendict ``` -------------------------------- ### Generate Symbol File with dump_syms Source: https://xiaoyifang.github.io/goldendict-ng/howto/how%20to%20use%20breadpad%20crash%20analysis Use dump_syms to convert a PDB file into a symbol file for crash analysis. This is part of the Mozilla/Rust toolchain. ```bash .\dump_syms.exe goldendict.pdb > goldendict.sym ``` -------------------------------- ### Manipulate DOM with article-script.js Source: https://xiaoyifang.github.io/goldendict-ng/topic_userstyle Contains event listeners for audio buttons, link behavior, UI toolbar injection, and global text highlighting functions. ```javascript // Execute when page is loaded window.addEventListener('DOMContentLoaded', function() { // Example 1: Add click effect to all audio buttons const audioButtons = document.querySelectorAll('.playSound'); audioButtons.forEach(button => { button.addEventListener('click', function() { // Add click animation effect this.style.transform = 'scale(0.95)'; setTimeout(() => { this.style.transform = 'scale(1)'; }, 100); }); }); // Example 2: Add new window opening functionality to all links const links = document.querySelectorAll('a'); links.forEach(link => { link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); }); // Example 3: Add custom toolbar const toolbar = document.createElement('div'); toolbar.style.cssText = ` position: fixed; top: 10px; right: 10px; background: rgba(255, 255, 255, 0.9); padding: 5px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 1000; `; const button = document.createElement('button'); button.textContent = 'Toggle Theme'; button.style.cssText = ` padding: 5px 10px; border: none; border-radius: 3px; background: #3498db; color: white; cursor: pointer; `; button.addEventListener('click', function() { document.body.classList.toggle('dark-theme'); }); toolbar.appendChild(button); document.body.appendChild(toolbar); }); // Example 4: Define global function for other scripts to use function highlightText(text) { const elements = document.querySelectorAll('p, span, div'); elements.forEach(element => { if (element.textContent.includes(text)) { element.innerHTML = element.innerHTML.replace( new RegExp(text, 'gi'), '$&' ); } }); } ``` -------------------------------- ### Override dictionary display name Source: https://xiaoyifang.github.io/goldendict-ng/custom_dictionary Use the [metadata] section to define a custom name for the dictionary. ```toml [metadata] name = "New Name" ``` -------------------------------- ### Injecting JavaScript via External File Source: https://xiaoyifang.github.io/goldendict-ng/topic_website_scripting Use this pattern to hide specific DOM elements by referencing a local JavaScript file in the configuration. ```javascript // Example: Hide a specific element document.addEventListener('DOMContentLoaded', function() { var element = document.getElementById('annoying-banner'); if (element) { element.style.display = 'none'; } }); ``` -------------------------------- ### Flatpak Override for X11 Mode Source: https://xiaoyifang.github.io/goldendict-ng/topic_wayland Configure the Flatpak version of GoldenDict-NG to always run in X11 mode by setting the environment variable using `flatpak override`. This ensures features requiring X11 are available. ```bash # Force X11 mode for Flatpak flatpak override --env=GOLDENDICT_FORCE_XCB=1 io.github.xiaoyifang.goldendict_ng ``` -------------------------------- ### Create 1-click lookup link in Anki Source: https://xiaoyifang.github.io/goldendict-ng/topic_anki Add this HTML anchor tag to your Anki card template to enable direct word lookup in GoldenDict-ng. ```html {{Front}} ``` -------------------------------- ### Customize Dictionary Article Styles Source: https://xiaoyifang.github.io/goldendict-ng/topic_userstyle CSS rules for modifying the appearance of dictionary entries, including colors, typography, and layout. ```css /* Change article background color */ body { background-color: #f5f5f5; color: #333; } /* Change heading styles */ h1, h2, h3 { color: #2c3e50; font-family: Arial, sans-serif; margin-top: 1em; margin-bottom: 0.5em; } /* Change dictionary entry style */ .article { padding: 10px; border-radius: 5px; background-color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.1); } /* Change link style */ a { color: #3498db; text-decoration: none; } a:hover { text-decoration: underline; } /* Change audio button style */ .playSound { background-color: #e74c3c; color: white; border: none; border-radius: 3px; padding: 2px 6px; cursor: pointer; } .playSound:hover { background-color: #c0392b; } /* Change definition list style */ dl { margin: 0; padding: 0; } dt { font-weight: bold; margin-top: 0.5em; } dd { margin-left: 1em; margin-bottom: 0.5em; } /* Change example sentences style */ .example { font-style: italic; color: #7f8c8d; margin-left: 1em; } ``` -------------------------------- ### Python stdin UTF-8 Handling Source: https://xiaoyifang.github.io/goldendict-ng/manage_sources For Python versions older than 3.6, explicitly set PYTHONIOENCODING to UTF-8 to ensure correct stdin handling. For newer versions, this is the default behavior. ```python import sys sys.stdin.reconfigure(encoding='utf-8') ``` -------------------------------- ### Node.js stdin UTF-8 Handling Source: https://xiaoyifang.github.io/goldendict-ng/manage_sources In Node.js, set the stdin encoding to 'utf8' to correctly process UTF-8 encoded input. This is crucial for handling non-ASCII characters. ```javascript process.stdin.setEncoding('utf8'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.