Skip to main content
  • Forward Translation

    • Word-wise translation of input strings from any detected source language → English.
    • Optional token-level mapping (getTokenList) for round-trip tracking.
    • Preserve specified “protected” tokens (e.g. IDs, placeholders, rules).
  • Preserving Sementics during Translation

    • Chunk-wise translation of input strings from any detected source language → English.
    • Merges common prepositional phrases, translates whole sentences when possible, then aligns individual parts for better context.
    • Uses BERT-based alignment to keep multi-word units intact.
  • Backward Translation

    • Restoration of original text by inverting the mapping produced during forward translation.

📦 Installation

To install the package, run

pip install windowtitles-translation@git+https://github.com/paxray/windowtitles-translation-llm.git

to install without cloning the repository. If the repository is already cloned, running

pip install .

in the root folder also works.

Features

  • Forward translation using Hugging Face MarianMT.
  • Back-translation to reconstruct original window titles.
  • Token mapping for granular translation control.
  • Preserve placeholders and specified words.

Usage

Forward Translation

Use the getTranslations function from main.py:

from main import getTranslations

payload = {
    "windowTitles": ["Fenêtre de terminal", "Título de documento"],
    "preserveWordsList": ["Word"],
    "getTokenList": True,
    "windowTitlesLanguage": None,
    "translationType": "forward" 
}

translations = getTranslations(payload)
print(translations)

Output example:

{
  "Fenêtre de terminal": {
    "language": "fr",
    "translation": "Terminal window",
    "tokenMapping": { ... }
  },
  "Título de documento": {
    "language": "es",
    "translation": "Document title",
    "tokenMapping": { ... }
  }
} 

Backward Translation

Use the getOriginalData function to reverse a translation:

from main import getOriginalData

payload = {
    "alteredWindowTitles": {
        "alteredWindowTitle": { ... }
    },
    "translationType": "backward"
}

originals = getOriginalData(payload)
print(originals)

CLI

By default, running main.py performs a backward translation on sample data:

python main.py

Results are saved to data/output-data/output_file_name.json.

Configuration Options

Below are the configuration options for both forward and backward translation payloads. Each field’s datatype and whether it is mandatory are listed.

Forward Translation Payload:

  • windowTitles (List[str], mandatory):
    • A list of strings representing the window titles to be translated.
  • preserveWordsList (List[str], optional, default=[]):
    • Words or tokens you want to remain unchanged during translation.
  • getTokenList (bool, optional, default=False):
    • If true, includes a mapping of source-to-target tokens in the output.
  • windowTitlesLanguage (str, optional, default=None):
    • ISO 639-1 code (e.g., "fr", "es"); forces the source language detection.
  • translationType (str, mandatory):
    • For forward translation use the keyword "forward"

Backward Translation Payload (fields within alteredWindowTitles entries):

  • alteredWindowTitles (str, mandatory):
    • The translated window title you wish to revert.
  • tokenMapping (Dict[int, int], mandatory):
    • Original-to-translated token index mapping used during forward translation.
  • translationType (str, mandatory):
    • For backward translation use the keyword "backward"

Config.py

  • device = "cpu" #or "cuda"
  • Set to 'CPU' by default. Change to 'Cuda' to use GPU.

Project Structure

└── src
  └── windowtitles_translation
    ├── constants.py
    ├── config.py
    ├── commonMethods.py
    ├── backwardTranslation.py
    ├── forwardTranslation.py
    ├── forwardTranslationWithSemantics.py
    ├── main.py
└── data
    ├── input-data
    └── output-data

Metadata

Release files for windowtitles-translation-llm 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for windowtitles-translation-llm 0.1.0
File Size Uploaded
windowtitles_translation_llm-0.1.0.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for windowtitles-translation-llm 0.1.0
File Interpreter ABI Platform
windowtitles_translation_llm-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / windowtitles_translation_llm-0.1.0.tar.gz

Download URL windowtitles_translation_llm-0.1.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d6398174c86152abf2299ea2c320fa72590c97eab809dedc6033daf1b58df7fe
BLAKE2b-256 checksum
How to use checksums
01a04467394ef1bc278baa0b837b6b705f1b618cb234c17ec49d4795f7f968da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release files / windowtitles_translation_llm-0.1.0-py3-none-any.whl

Download URL windowtitles_translation_llm-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
843711beffd0b050b972c4c326ba8fa22e39bad85b112a8cd5716772782b1acb
BLAKE2b-256 checksum
How to use checksums
4b9d72d94223664dc98cb59c913f34c56a83deeb1440753bf31f7e45364243c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page