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

yaml
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

OptionTypeDefaultDescription
Text ExtractionautomaticEnabledScans all "text" fields in file content
Key GenerationautomaticProject-basedUses project ID for translation key prefixes
Parallel Processingautomatic32 workersMulti-threaded file processing for performance
Language Targetconstanten_usGenerates 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_us language 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