๐ŸŒ stewbeet.plugins.auto.lang_file

๐Ÿ“„ Source Code: stewbeet/plugins/auto/lang_file/__init__.py ๐Ÿ”—
๐Ÿ“„ Source Code: stewbeet/plugins/auto/lang_file/utils.py ๐Ÿ”—

๐Ÿ”— Dependencies

  • โœ… 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

๐Ÿ“‹ Overview

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
a comprehensive en_us.json language file for internationalization support.

Feature Showcase

Before and after lang plugin:

Generated en_us.json lang file:

๐ŸŽฏ Purpose

  • ๐ŸŒ 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

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