SVG Translation Tool
This tool extracts multilingual text pairs from SVG files and applies translations to other SVG files by inserting missing <text systemLanguage="XX"> blocks.
Installation
This tool requires Python 3.10+. Install the lightweight core dependencies with:
pip install CopySVGTranslation
Usage
Extracting and injecting in a single step
from pathlib import Path
from CopySVGTranslation import svg_extract_and_inject
tree = svg_extract_and_inject(
extract_file=Path("examples/source_multilingual.svg"),
inject_file=Path("examples/target_missing_translations.svg"),
data_output_file = Path("examples/data.json"),
save_result=True,
)
if tree is not None:
print("Injection completed!")
The helper stores the extracted phrases under Path("examples/data.json") and,
when save_result=True, writes the translated SVG to
output_dir=Path("./translated"). If you also need statistics about how many
translations were inserted, call the lower level injector with
return_stats=True:
from CopySVGTranslation.injection import inject
tree, stats = inject(
inject_file="examples/target_missing_translations.svg",
mapping_files=["CopySVGTranslation/data/source_multilingual.svg.json"],
output_dir=Path("./translated"),
save_result=True,
return_stats=True,
)
print(stats)
Injecting with pre-translated data
When you already have the translation JSON, load it and use
inject directly. Important parameters include overwrite
to update existing translations and output_dir to control where translated
files are written.
from pathlib import Path
from CopySVGTranslation import inject
translations = {
"new": {
"Hello": {"ar": "مرحبًا", "fr": "Bonjour"},
}
}
tree, stats = inject(
inject_file=Path("examples/target_missing_translations.svg"),
all_mappings=translations,
output_dir=Path("./translated"),
overwrite=True,
save_result=True,
return_stats=True,
)
print("Saved to", Path("./translated/target_missing_translations.svg"))
print(stats)
Data Model
The extractor writes a JSON document rooted under the "new" key. Each entry
maps normalized English text to a dictionary of language codes and translations.
An example of the modern format:
{
"new": {
"but are connected in anti-phase": {
"ar": "لكنها موصولة بمرحلتين متعاكستين."
}
}
}
Older exports may omit the wrapper and look like
{"english": {"ar": "…"}}. The injector transparently accepts both
structures, but the recommended format is the nested "new" layout shown
above.
Extract Example
Input SVG (arabic.svg)
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg">
<switch>
<text id="t0-ar" systemLanguage="ar">
<tspan id="t0-ar">الموسيقى في عام 2020</tspan>
</text>
<text id="t0-fr" systemLanguage="fr">
<tspan id="t0-fr">La musique en 2020</tspan>
</text>
<text id="t0">
<tspan id="t0">Music in 2020</tspan>
</text>
</switch>
<switch>
<text id="t0-ar" systemLanguage="ar">
<tspan id="t0-ar">مرحبا</tspan>
</text>
<text id="t0-fr" systemLanguage="fr">
<tspan id="t0-fr">Bonjour</tspan>
</text>
<text id="t0">
<tspan id="t0">Hello</tspan>
</text>
</switch>
</svg>
Python code
from pathlib import Path
from CopySVGTranslation import extract
translations = extract(
svg_file_path=Path("arabic.svg"),
case_insensitive=True,
)
Extracted JSON
{
"new": {
"music in 2020": {
"ar": "الموسيقى في عام 2020",
"fr": "La musique en 2020"
},
"hello": {
"ar": "مرحبا",
"fr": "Bonjour"
}
},
"title": {
"music in": {
"ar": "الموسيقى في عام",
"fr": "La musique en"
}
},
"tspans_by_id": {
"t0": "Hello"
}
}
Injection Example
- TODO
Testing
Run the unit tests:
python -m pytest tests -v
Implementation Details
Text Normalization
The tool normalizes text by:
- Trimming leading and trailing whitespace
- Replacing multiple internal whitespace characters with a single space
- Optionally converting to lowercase for case-insensitive matching
ID Generation
When adding new translation nodes, the tool generates unique IDs by:
- Taking the existing ID and appending the language code (e.g.,
text2213becomestext2213-ar) - If the generated ID already exists, appending a numeric suffix until unique (e.g.,
text2213-ar-1)
Error Handling
The tool includes comprehensive error handling for:
- Missing input files
- Invalid XML structure
- Missing required attributes
- File permission issues
Metadata
Release files for CopySVGTranslation 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| copysvgtranslation-0.1.9.tar.gz | 119.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| copysvgtranslation-0.1.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 148.6 kB
Release files / copysvgtranslation-0.1.9.tar.gz
| Download URL | copysvgtranslation-0.1.9.tar.gz |
|---|---|
| Size | 119.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f203a249d54cf75323a40b0999009f43dd1e2f4cf5113e503891c1cb7a1fcb4d
|
|
BLAKE2b-256 checksum How to use checksums |
a730d64ed2641249a208f3bb1108e698ea89ebc797b5317c7c2eb47dbe8bcea0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / copysvgtranslation-0.1.9-py3-none-any.whl
| Download URL | copysvgtranslation-0.1.9-py3-none-any.whl |
|---|---|
| Size | 29.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38438ad2d1768218d06a561584b77ca85968e9bf6ed0ee01f748968d02acd8a2
|
|
BLAKE2b-256 checksum How to use checksums |
0caa2627c9b2029850d96b54ad301a4e25edd9a894d813e5be8799c7f20b8689
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logSecurity for CopySVGTranslation 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for copysvgtranslation-0.1.9.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.