Extract and rewrite translatable strings in KubeJS scripts
Project description
KubeJS String Extractor
Extract translatable strings from Minecraft modpack KubeJS scripts, rewrite the JS files to use Text.translatable(), and output en_us.json lang files for localization.
What it does
KubeJS scripts often contain hardcoded English strings (item names, tooltips, ponder text, announcements, etc.) that are not translatable via standard Minecraft resource packs. This tool:
- Scans
client_scripts/,server_scripts/, andstartup_scripts/for translatable strings - Extracts strings from patterns like
.displayName(),Text.of(),Text.red(),scene.text(),addAnnouncement(), etc. - Rewrites the original JS files to use
Text.translatable('key')calls - Outputs a standard
en_us.jsonlang file for translators to work with
Supported Patterns
| Original | Rewritten As |
|---|---|
.displayName('Foo') |
.displayName(Text.translatable('key')) |
Text.of('Foo') |
Text.translatable('key') |
Text.red('Foo') |
Text.translatable('key').red() |
Text.green/blue/yellow/gold('Foo') |
Text.translatable('key').green/blue/yellow/gold() |
scene.text(N, 'Foo', ...) |
scene.text(N, Text.translatable('key'), ...) |
addAnnouncement("ver", "Foo") |
addAnnouncement("ver", Text.translatable('key')) |
.append('Foo') |
.append(Text.translatable('key')) |
.statusMessage = "Foo" |
.statusMessage = Text.translatable('key') |
.tell("Foo") |
.tell(Text.translatable('key')) |
Installation
pip install kubejs-string-extractor
Or with uv:
uv tool install kubejs-string-extractor
Usage
# Extract strings, rewrite JS files, and generate en_us.json
kubejs-strings extract path/to/kubejs
# Custom output directory
kubejs-strings extract path/to/kubejs --output my_translations
# Extract only (no JS rewriting)
kubejs-strings extract path/to/kubejs --no-rewrite
# Modify original JS files in place (⚠️ make backups first!)
kubejs-strings extract path/to/kubejs --in-place
# Custom namespace prefix for translation keys
kubejs-strings extract path/to/kubejs --namespace mypack
Output
extracted/
├── assets/
│ └── kubejs_string_extractor/
│ └── lang/
│ └── en_us.json # Translation keys → English strings
└── kubejs/ # Rewritten JS files (unless --no-rewrite)
├── client_scripts/
├── server_scripts/
└── startup_scripts/
The en_us.json contains entries like:
{
"kubejs.client.tooltips.1": "Place the pad down in the specified Dimension",
"kubejs.startup.universal_press.1": "Inscriber Universal Press"
}
Workflow
- Run the tool to extract strings and rewrite JS files
- Copy the rewritten JS files back into your modpack's
kubejs/directory - Place
en_us.jsonin your resource pack - Create
zh_cn.json(or other locales) by translating the values
Development
# Install dependencies
uv sync
# Run tests
uv run pytest tests/ -v
# Run against sample data
uv run kubejs-strings extract output/kubejs --output test_output
License
MIT
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 kubejs_string_extractor-1.0.9.tar.gz.
File metadata
- Download URL: kubejs_string_extractor-1.0.9.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b0824ac2aa4f2169d3876c8d34c6a4cea179c66eea1b4304cf87e1ee116e311
|
|
| MD5 |
79ae50fdecac1eae6490dbb71350d9d7
|
|
| BLAKE2b-256 |
1ae6930c19a61f2f015072a31cbac8069ed13ab600d8a49c4701c5f1147c8afb
|
Provenance
The following attestation bundles were made for kubejs_string_extractor-1.0.9.tar.gz:
Publisher:
publish.yml on zack-zzq/kubejs-string-extractor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kubejs_string_extractor-1.0.9.tar.gz -
Subject digest:
9b0824ac2aa4f2169d3876c8d34c6a4cea179c66eea1b4304cf87e1ee116e311 - Sigstore transparency entry: 1003808926
- Sigstore integration time:
-
Permalink:
zack-zzq/kubejs-string-extractor@322d4951bc56535a11894c3f6ccc1c4b2cdb96b4 -
Branch / Tag:
refs/tags/v1.0.9 - Owner: https://github.com/zack-zzq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@322d4951bc56535a11894c3f6ccc1c4b2cdb96b4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kubejs_string_extractor-1.0.9-py3-none-any.whl.
File metadata
- Download URL: kubejs_string_extractor-1.0.9-py3-none-any.whl
- Upload date:
- Size: 14.0 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 |
7df9d818c485ef5b3a8e6f2fa523adf1e0f54e70235e5068462d87e2fcf03300
|
|
| MD5 |
deb79d8a3167253163559320f5844e23
|
|
| BLAKE2b-256 |
441bfdcf08c7e082f5a80639eeaccd417189a19312555a54beec4392fa3cc75d
|
Provenance
The following attestation bundles were made for kubejs_string_extractor-1.0.9-py3-none-any.whl:
Publisher:
publish.yml on zack-zzq/kubejs-string-extractor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kubejs_string_extractor-1.0.9-py3-none-any.whl -
Subject digest:
7df9d818c485ef5b3a8e6f2fa523adf1e0f54e70235e5068462d87e2fcf03300 - Sigstore transparency entry: 1003808929
- Sigstore integration time:
-
Permalink:
zack-zzq/kubejs-string-extractor@322d4951bc56535a11894c3f6ccc1c4b2cdb96b4 -
Branch / Tag:
refs/tags/v1.0.9 - Owner: https://github.com/zack-zzq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@322d4951bc56535a11894c3f6ccc1c4b2cdb96b4 -
Trigger Event:
push
-
Statement type: