Allow translators to mark wagtail-localize segments as 'do not translate'
Project description
wagtail-localize-intentional-blanks
A Wagtail library that extends wagtail-localize to allow translators to mark translation segments as "do not translate". These segments count as translated (contributing to progress) but fall back to the source page's value when rendered.
Features
- ✅ Translator Control: Translators decide which fields to not translate
- ✅ Per-Locale Flexibility: One language can translate a value while another language can use the source value
- ✅ Progress Tracking: "Do not translate" segments count as translated by
wagtail-localize - ✅ No Template Changes: Works transparently with existing templates
- ✅ Drop-in Integration: Minimal code changes required
- ✅ UI Included: Adds "Do Not Translate" buttons to translation editor
Installation
pip install wagtail-localize-intentional-blanks
Quick Start
1. Add to INSTALLED_APPS
Important: wagtail_localize_intentional_blanks must come before wagtail_localize in INSTALLED_APPS for template overrides to work.
# settings.py
INSTALLED_APPS = [
# ... other apps
'wagtail_localize_intentional_blanks', # Must be BEFORE wagtail_localize
'wagtail_localize',
'wagtail_localize.locales',
# ... other apps
]
2. Include URLs
# urls.py
from django.urls import path, include
urlpatterns = [
# ... other patterns
path(
'intentional-blanks/', include('wagtail_localize_intentional_blanks.urls')
),
]
That's it! The "Do Not Translate" button will now appear in the translation editor for all translatable fields. No code changes to your blocks or models required.
How It Works
This library works by:
- Adding UI controls - JavaScript adds "Do Not Translate" checkboxes to the translation editor
- Storing markers - When checked, a marker string (
__DO_NOT_TRANSLATE__) is stored in the translation - Automatic replacement - When rendering pages, a patch intercepts segment retrieval and replaces markers with source values
- Progress tracking - Marked segments count as "translated" for progress calculation
Key benefit: No code changes to your blocks or models. The library handles everything automatically through patching wagtail-localize's internal methods.
Usage
In the Translation Editor
- Open a page translation in wagtail-localize's editor
- For each segment, you'll see a "Mark 'Do Not Translate'" checkbox
- Check it to mark that segment as do not translate
- The segment counts as translated (shows green)
- When the page renders, it automatically shows the source value for that field
- If the value in the original page changes, and the translated pages are synced, the segment still counts as translated (shows green) and when the page renders, it shows the updated source value for that field
Common Use Cases
- Brand names and trademarks - Keep consistent across locales
- Product codes and SKUs - No translation needed
- URLs - Pages may contain the translations for different languages, but a URL is the same for all languages
- IDs - Not language-specific identifiers
Configuration
You can customize behavior in your Django settings:
# settings.py
# Enable/disable the feature globally
WAGTAIL_LOCALIZE_INTENTIONAL_BLANKS_ENABLED = True
# Custom marker (advanced)
WAGTAIL_LOCALIZE_INTENTIONAL_BLANKS_MARKER = "__DO_NOT_TRANSLATE__"
# Require specific permission (default: None = any translator)
WAGTAIL_LOCALIZE_INTENTIONAL_BLANKS_REQUIRED_PERMISSION = 'cms.can_mark_do_not_translate'
Advanced Usage
Programmatic API
You can programmatically mark segments as "do not translate" using the provided utilities:
from wagtail_localize_intentional_blanks.utils import (
mark_segment_do_not_translate,
unmark_segment_do_not_translate,
get_source_fallback_stats,
)
from wagtail_localize.models import Translation, StringSegment
# Mark a segment
translation = Translation.objects.get(id=123)
segment = StringSegment.objects.get(id=456)
mark_segment_do_not_translate(translation, segment, user=request.user)
# Unmark a segment
unmark_segment_do_not_translate(translation, segment)
# Get statistics
stats = get_source_fallback_stats(translation)
print(f"{stats['do_not_translate']} segments marked as do not translate")
print(f"{stats['manually_translated']} segments manually translated")
Requirements
- Python 3.10+
- Django 4.2+
- Wagtail 5.2+
- wagtail-localize 1.8+
Release
In order to make a release, we add a git tag and push it to GitHub. We have a GitHub Action that releases the code to PyPI when we add a new tag.
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome!
Development
Setting Up for Development
- Clone the repository:
git clone https://github.com/lincolnloop/wagtail-localize-intentional-blanks.git
cd wagtail-localize-intentional-blanks
- Install the package with development dependencies:
pip install -e ".[dev]"
This installs the package in editable mode along with testing tools (pytest, black, flake8, etc.).
Running Tests
Run the test suite with pytest:
pytest
Run tests with coverage:
pytest --cov=wagtail_localize_intentional_blanks
Run specific test files:
pytest tests/test_utils.py
pytest tests/test_views.py
Code Quality
Check code with ruff:
ruff check .
Format with ruff:
ruff format .
Credits
Created by Lincoln Loop, LLC for the Wagtail community.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_localize_intentional_blanks-0.2.1.tar.gz.
File metadata
- Download URL: wagtail_localize_intentional_blanks-0.2.1.tar.gz
- Upload date:
- Size: 41.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2086bb011d33ba4ecf05c99b621a43571db869bf6f7ad28729719d588416c574
|
|
| MD5 |
37425021e347fdd0ee7e03177cf77607
|
|
| BLAKE2b-256 |
b9c9bac7c7ca4c800509a7488061253bd1d6d56b6ac8fd33e9136b5d7b215ad0
|
Provenance
The following attestation bundles were made for wagtail_localize_intentional_blanks-0.2.1.tar.gz:
Publisher:
build.yml on lincolnloop/wagtail-localize-intentional-blanks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_localize_intentional_blanks-0.2.1.tar.gz -
Subject digest:
2086bb011d33ba4ecf05c99b621a43571db869bf6f7ad28729719d588416c574 - Sigstore transparency entry: 835742281
- Sigstore integration time:
-
Permalink:
lincolnloop/wagtail-localize-intentional-blanks@ed025a8f3e04ed18e7afd2e0520694826d64acd0 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/lincolnloop
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@ed025a8f3e04ed18e7afd2e0520694826d64acd0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wagtail_localize_intentional_blanks-0.2.1-py3-none-any.whl.
File metadata
- Download URL: wagtail_localize_intentional_blanks-0.2.1-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b8774c5f461b2fa53d3498683224df5685ee3e0b2b1c64ea3b8c02257b3648d
|
|
| MD5 |
e0f9d4940323ff07ac0c32c2b0086b24
|
|
| BLAKE2b-256 |
1ef22f240a05d8ce9eb11c5a6b2bcb4c9a777f00e0d768bb98f6b9675575b0bd
|
Provenance
The following attestation bundles were made for wagtail_localize_intentional_blanks-0.2.1-py3-none-any.whl:
Publisher:
build.yml on lincolnloop/wagtail-localize-intentional-blanks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_localize_intentional_blanks-0.2.1-py3-none-any.whl -
Subject digest:
9b8774c5f461b2fa53d3498683224df5685ee3e0b2b1c64ea3b8c02257b3648d - Sigstore transparency entry: 835742282
- Sigstore integration time:
-
Permalink:
lincolnloop/wagtail-localize-intentional-blanks@ed025a8f3e04ed18e7afd2e0520694826d64acd0 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/lincolnloop
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@ed025a8f3e04ed18e7afd2e0520694826d64acd0 -
Trigger Event:
push
-
Statement type: