|
| 1 | +# Contributing to TranslatorHoi4 |
| 2 | + |
| 3 | +Thank you for helping improve TranslatorHoi4. This guide explains how to set up the project, make focused changes, and verify them before opening a pull request. |
| 4 | + |
| 5 | +## Project Scope |
| 6 | + |
| 7 | +TranslatorHoi4 is a Python 3.12+ desktop application for translating Paradox game localization files with AI providers. The main areas of the codebase are: |
| 8 | + |
| 9 | +- `translatorhoi4/translator/` - translation engine, provider backends, caching, prompts, and cost tracking. |
| 10 | +- `translatorhoi4/parsers/` - Paradox localization parsing and serialization. |
| 11 | +- `translatorhoi4/ui/` - PySide6 and Fluent UI windows, controls, localization strings, and review tools. |
| 12 | +- `translatorhoi4/utils/` - settings, validation, logging, update checks, and filesystem helpers. |
| 13 | +- `tests/` - pytest coverage for parser, cache, settings, validation, UI control behavior, and related logic. |
| 14 | +- `docs/` - user-facing and developer documentation. |
| 15 | + |
| 16 | +## Development Setup |
| 17 | + |
| 18 | +Clone the repository and create a virtual environment: |
| 19 | + |
| 20 | +```bash |
| 21 | +git clone https://github.com/Locon213/TranslatorHoi4.git |
| 22 | +cd TranslatorHoi4 |
| 23 | +python -m venv .venv |
| 24 | +``` |
| 25 | + |
| 26 | +Activate the environment: |
| 27 | + |
| 28 | +```bash |
| 29 | +# Windows PowerShell |
| 30 | +.venv\Scripts\Activate.ps1 |
| 31 | + |
| 32 | +# Linux/macOS |
| 33 | +source .venv/bin/activate |
| 34 | +``` |
| 35 | + |
| 36 | +Install dependencies: |
| 37 | + |
| 38 | +```bash |
| 39 | +python -m pip install -U pip wheel setuptools |
| 40 | +pip install -r requirements.txt |
| 41 | +``` |
| 42 | + |
| 43 | +Run the application from source: |
| 44 | + |
| 45 | +```bash |
| 46 | +python -m translatorhoi4 |
| 47 | +``` |
| 48 | + |
| 49 | +## Running Tests |
| 50 | + |
| 51 | +Run the full test suite before submitting code changes: |
| 52 | + |
| 53 | +```bash |
| 54 | +pytest -q |
| 55 | +``` |
| 56 | + |
| 57 | +For focused work, run the relevant test file first: |
| 58 | + |
| 59 | +```bash |
| 60 | +pytest -q tests/test_parser.py |
| 61 | +pytest -q tests/test_ui_batch_controls.py |
| 62 | +``` |
| 63 | + |
| 64 | +If you change parser behavior, translation masking, settings storage, provider configuration, or batch UI controls, add or update tests that cover the changed behavior. |
| 65 | + |
| 66 | +## Building Locally |
| 67 | + |
| 68 | +TranslatorHoi4 uses Nuitka for distributable builds: |
| 69 | + |
| 70 | +```bash |
| 71 | +python build.py |
| 72 | +``` |
| 73 | + |
| 74 | +Build output is generated under `dist/TranslatorHoi4/`. Build artifacts should not be committed unless the repository explicitly asks for them. |
| 75 | + |
| 76 | +## Code Guidelines |
| 77 | + |
| 78 | +- Keep changes focused on one feature, bug fix, or documentation update. |
| 79 | +- Prefer existing project patterns over introducing new abstractions. |
| 80 | +- Preserve Paradox localization syntax exactly, including keys, `$VARIABLES$`, `[scripted.macros]`, escaped newlines, and formatting tokens. |
| 81 | +- Do not log API keys, provider credentials, mod contents beyond what is necessary for debugging, or other user secrets. |
| 82 | +- Keep provider-specific logic inside the relevant backend module when possible. |
| 83 | +- Keep UI text in the locale modules under `translatorhoi4/ui/locales/` when adding user-visible strings. |
| 84 | +- Use clear names for settings and config fields, and keep backwards compatibility with existing stored settings when practical. |
| 85 | + |
| 86 | +## Localization Contributions |
| 87 | + |
| 88 | +When updating UI translations: |
| 89 | + |
| 90 | +- Update every affected locale file if the string is part of shared UI. |
| 91 | +- Keep placeholders, punctuation, and accelerator-style labels consistent across languages. |
| 92 | +- Do not translate provider names, model IDs, file extensions, or command names unless the surrounding UI already does so. |
| 93 | +- Check that translated text still fits in compact controls and dialogs. |
| 94 | + |
| 95 | +## AI Provider Changes |
| 96 | + |
| 97 | +When adding or changing an AI provider: |
| 98 | + |
| 99 | +- Put provider API calls in `translatorhoi4/translator/backends/`. |
| 100 | +- Register the provider through the existing registry/config flow. |
| 101 | +- Add settings UI only for options users need to configure directly. |
| 102 | +- Handle network errors, authentication failures, rate limits, and malformed provider responses gracefully. |
| 103 | +- Add tests for request construction, response parsing, and fallback behavior where feasible. |
| 104 | + |
| 105 | +## Documentation |
| 106 | + |
| 107 | +Documentation changes should be practical and current. If a command, path, or supported provider changes, update the relevant README or file under `docs/` in the same pull request. |
| 108 | + |
| 109 | +## Commit and Pull Request Guidelines |
| 110 | + |
| 111 | +Before committing: |
| 112 | + |
| 113 | +```bash |
| 114 | +git status --short |
| 115 | +pytest -q |
| 116 | +``` |
| 117 | + |
| 118 | +Use concise commit messages that describe the change, for example: |
| 119 | + |
| 120 | +```text |
| 121 | +Add parser tests for escaped localization values |
| 122 | +Fix provider settings persistence |
| 123 | +Update user guide for batch translation |
| 124 | +``` |
| 125 | + |
| 126 | +Pull requests should include: |
| 127 | + |
| 128 | +- A short summary of what changed. |
| 129 | +- The reason for the change. |
| 130 | +- Tests or manual checks performed. |
| 131 | +- Screenshots or screen recordings for visible UI changes. |
| 132 | +- Notes about compatibility, migrations, or provider behavior changes when relevant. |
| 133 | + |
| 134 | +## Reporting Issues |
| 135 | + |
| 136 | +When reporting a bug, include: |
| 137 | + |
| 138 | +- TranslatorHoi4 version or commit. |
| 139 | +- Operating system and Python version if running from source. |
| 140 | +- The game or mod localization format involved. |
| 141 | +- Steps to reproduce the problem. |
| 142 | +- Expected and actual behavior. |
| 143 | +- Relevant logs or screenshots, with API keys and private data removed. |
| 144 | + |
| 145 | +## Security |
| 146 | + |
| 147 | +Do not commit `.env` files, API keys, provider tokens, private mod files, or generated credentials. If a secret is committed by mistake, rotate it immediately and remove it from history before sharing the branch. |
0 commit comments