stewbeet.plugins.auto.lang_file
The auto.lang_file plugin automatically generates language files for datapacks.
It scans all functions and loot tables for hardcoded text strings, extracts them into
translation keys, replaces the original text with translate text component keys, and generates
an en_us.json language file for internationalization support.
Required: Beet context with functions, loot tables, advancements, recipes, etc.
Required: Project ID for translation key namespacing
Position: Should run after content generation but before finalization
Optional: Existing en_us.json language file (will be merged)
Related: Works with any plugins that generate text content
Feature Showcase
Before and after lang plugin:
Generated en_us.json lang file:
Source Code: stewbeet/plugins/auto/lang_file/__init__.py
Source Code: stewbeet/plugins/auto/lang_file/utils.py
What it does
- Automatically generates language files from hardcoded text
- Converts
"text"text component keys to"translate"keys - Extracts text strings from functions and loot tables
- Creates standardized translation keys with project namespacing
- Cleans and validates text content for language file inclusion
- Enables internationalization support for datapacks
Configuration
Basic Example Configuration
pipeline:
- ...
- stewbeet.plugins.auto.lang_file
- ...
# No configuration required - plugin runs automatically
# Processes all text files by default (functions, loot tables, advancements, etc.)Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
| Text Extraction | automatic | Enabled | Scans all "text" fields in file content |
| Key Generation | automatic | Project-based | Uses project ID for translation key prefixes |
| Parallel Processing | automatic | 32 workers | Multi-threaded file processing for performance |
| Language Target | constant | en_us | Generates English language file by default |
Features
Text Extraction Engine
Scans content for hardcoded text using regex patterns:
- π Uses advanced regex to find
"text": "value"patterns - π Handles escaped characters and various quote styles
- π Tracks text positions for accurate replacement
- π― Processes both single and double quoted strings
Translation Key Generation
Creates standardized translation keys with project namespacing:
- π§Ή Cleans text by removing special characters and normalizing case
- π Limits key length to 64 characters for compatibility
- π§ Uses project ID prefix for unique namespacing
- β Validates keys to ensure they contain meaningful content
Content Replacement System
Replaces hardcoded text with translate components:
- π Converts
"text": "value"to"translate": "key" - π Processes matches in reverse order to maintain position accuracy
- π§Ή Handles escape sequences and special characters properly
- β Preserves JSON structure and formatting during replacement
Parallel Processing System
Efficiently processes multiple files using multi-threading:
- β‘ Uses up to 32 worker threads for fast processing
- π Processes both functions and loot tables simultaneously
- π¨ Provides colored progress indicators during execution
- π§ Optimizes worker count based on file quantity
Language File Management
Generates and updates the English language file:
- π Creates
minecraft:en_uslanguage resource - π Merges with existing language data if present
- πΎ Uses proper JSON formatting for compatibility
- π Sets up foundation for multi-language support
Content Validation System
Ensures only meaningful text gets processed:
- β Skips text without alphanumeric characters
- π Validates minimum key length requirements
- π« Excludes Unicode escapes and template variables
- π― Prevents duplicate keys with conflicting values
Next steps
- Writing functions and files: the functions this plugin post-processes.
- All plugins: the rest of the pipeline, in the order it runs.
- Configuring the build: enabling, ordering and configuring plugins.