# Language Symlink Organization - Implementation Summary **Date:** October 8, 2025 **Status:** ✅ Complete and Tested --- ## Overview Implemented a comprehensive language symlink organization system that creates virtual "By Language/" folders without duplicating ROM files. This solves the problem where organizing ROMs by language would require multiple copies of multi-language games. --- ## Architecture: Two-Tier Organization ### Physical Organization (Moves Files) 1. **Regions** - Move games to `By Region//` folders 2. **Kinds** - Move special editions to kind subfolders (Beta, Proto, etc.) ### Virtual Organization (Symlinks) 3. **Languages** - Create `By Language//` folders with symlinks **Key Principle:** Regions and kinds use physical moves (files exist once), languages use symlinks (multiple views of same file). --- ## New Environment Variables ### `KEEP_IN_ROOT_REGIONS` Controls which regions stay in root folder vs organized into subfolders. - **Unset/Empty:** Organize all regions - **Value:** Comma-separated region list to keep in root **Example:** `export KEEP_IN_ROOT_REGIONS="USA,World"` ### `KEEP_IN_ROOT_KINDS` Controls which ROM kinds should NOT be organized into subfolders. - **Unset/Empty:** Organize all kinds - **Value:** Comma-separated kind list to keep in place **Example:** `export KEEP_IN_ROOT_KINDS="Beta,Proto"` ### `ORGANIZE_LANGUAGES_BY_SYMLINK` Enables/disables language symlink folders. - **Unset/`false`:** No language organization - **`true`:** Create language symlink folders **Example:** `export ORGANIZE_LANGUAGES_BY_SYMLINK="true"` ### `LANGUAGE_EXCLUDE_REGIONS` Prevents specified regions from getting language symlinks. - **Unset/Empty:** All regions get symlinks - **Value:** Comma-separated region list to exclude **Example:** `export LANGUAGE_EXCLUDE_REGIONS="USA,World"` *Prevents 500+ USA games from cluttering "By Language/English/" folder* --- ## Files Modified ### Core Scripts **`/data/emu/rom-groomer/core/config-arrays.sh`** - Added `LANGUAGE_NAMES` associative array - Maps language codes to full names: `En→English`, `Fr→French`, etc. **`/data/emu/rom-groomer/organizers/organize-roms.sh`** - Complete rewrite of organization logic - Removed old flag-based system - Implemented environment variable configuration - Added three-phase organization process: 1. `organize_regions()` - Physical move by region 2. `organize_kinds_recursively()` - Physical move by kind (recursive) 3. `organize_languages_by_symlinks()` - Virtual symlink by language - New functions: - `detect_rom_languages()` - Parse language codes from filename - `detect_rom_region_from_file()` - Parse region from filename - `organize_languages_by_symlinks()` - Create language symlink folders - Updated help text with new variables - Enhanced validation for all configuration variables **`/data/emu/rom-groomer/tools/nointro-processor.sh`** - Updated `organize_roms()` function - Removed legacy flag construction - Now calls organize-roms.sh with environment variables only - Added documentation comments about new variable system ### Build Scripts **`/data/emu/rom-groomer/builders/build-nes-usa-1g1r.sh`** - Added ROM organization configuration section - Set variables for USA-only builds: ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" ``` **`/data/emu/rom-groomer/builders/build-nes-eng-1g1r.sh`** - Added ROM organization configuration section - Set variables for English builds: ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" ``` **`/data/emu/rom-groomer/builders/build-saturn-usa-1g1r.sh`** *(Redump Example)* - Added ROM organization configuration section - Set variables for USA-only builds (Redump sets): ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" ``` **`/data/emu/rom-groomer/builders/build-saturn-eng-1g1r.sh`** *(Redump Example)* - Added ROM organization configuration section - Set variables for English builds (Redump sets): ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" ``` **`/data/emu/rom-groomer/builders/build-saturn-all-1g1r.sh`** *(Redump Example)* - Added ROM organization configuration section - Set variables for All Languages builds (Redump sets): ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="" ``` ### Tests **`/data/emu/rom-groomer/tests/test-language-symlinks.sh`** *(New)* - Comprehensive test suite with 31 tests - Tests all configuration scenarios: 1. English build with USA/World excluded (15 tests) 2. All languages build with no exclusions (7 tests) 3. Language symlinks disabled (2 tests) 4. On-demand folder creation (4 tests) 5. Symlink accessibility validation (3 tests) - All tests passing ✅ ### Documentation **`/data/emu/rom-groomer/docs/BUILD-SCRIPT-CONFIGURATION.md`** *(New)* - Complete configuration guide - Variable reference with examples - Common build configurations - Three-phase organization explanation - Physical vs virtual organization concepts - Troubleshooting guide - Migration guide from old flag system --- ## Test Results **Test Suite:** `/data/emu/rom-groomer/tests/test-language-symlinks.sh` ``` Tests Run: 31 Tests Passed: 31 Tests Failed: 0 ✓ All tests passed! ``` ### Test Coverage ✅ USA games stay in root when configured ✅ World games stay in root when configured ✅ USA games excluded from language folders when configured ✅ Non-USA games organized by region ✅ Non-USA English games get English symlinks ✅ Multi-language games get multiple symlinks (one per language) ✅ Symlinks are relative (portable) ✅ Japanese/Korean folders created for Japan/Korea region games ✅ USA games included in language folders when not excluded ✅ Language symlinks can be disabled ✅ Region organization works without language symlinks ✅ On-demand folder creation (no empty folders) ✅ Symlinks are readable and accessible ✅ Symlink targets exist and are valid --- ## Example: English 1G1R Build Structure **Configuration:** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" ``` **Result:** ``` nes.eng.1g1r/ ├── Super Mario Bros (USA).nes # USA: stays in root ├── The Legend of Zelda (USA) (En).nes # USA: stays in root ├── Tetris (World).nes # World: stays in root ├── Secret of Mana (USA) (En,Fr,De).nes # USA: stays in root │ ├── By Region/ │ ├── Europe/ │ │ ├── Terranigma (Europe) (En,Fr,De).nes │ │ └── Suikoden (Europe) (En).nes │ ├── Japan/ │ │ ├── Final Fantasy (Japan) (En).nes │ │ └── Dragon Quest (Japan) (En,Ja).nes │ ├── France/ │ │ └── Asterix (France) (Fr).nes │ └── Germany/ │ └── Das Schwarze Auge (Germany) (De).nes │ └── By Language/ ├── English/ # Non-USA English games │ ├── Terranigma (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... │ ├── Suikoden (Europe) (En).nes -> ../../By Region/Europe/... │ ├── Final Fantasy (Japan) (En).nes -> ../../By Region/Japan/... │ └── Dragon Quest (Japan) (En,Ja).nes -> ../../By Region/Japan/... ├── French/ │ ├── Terranigma (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... │ └── Asterix (France) (Fr).nes -> ../../By Region/France/... ├── German/ │ ├── Terranigma (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... │ └── Das Schwarze Auge (Germany) (De).nes -> ../../By Region/Germany/... └── Japanese/ └── Dragon Quest (Japan) (En,Ja).nes -> ../../By Region/Japan/... ``` **Benefits:** - USA games easily accessible in root (most common games) - English folder shows international games with English translations - Multi-language games appear in all relevant language folders - No file duplication (symlinks only) - USA games don't clutter English folder (500+ games excluded) --- ## Key Features ### 1. On-Demand Folder Creation - Only creates folders when ROMs exist for that region/language/kind - No empty `By Region/Spain/` if no Spanish games - Cleaner directory structure ### 2. Relative Symlinks - All symlinks use relative paths: `../../By Region/Japan/...` - Portable across different mount points - Compatible with Batocera's filesystem structure ### 3. Multi-Language Support - Single ROM with multiple language tags gets multiple symlinks - `Secret of Mana (Europe) (En,Fr,De).nes` appears in English, French, and German folders - No file duplication ### 4. Three-Phase Organization - **Phase 1:** Region organization (physical move) - **Phase 2:** Kind organization (physical recursive move) - **Phase 3:** Language symlinks (virtual organization) - Each phase respects exclusion settings ### 5. Flexible Configuration - Each variable has three modes: unset, empty, or with values - Allows fine-grained control over organization behavior - Backward compatible (old flags still work via nointro-processor.sh) --- ## Usage Examples ### USA Only Build ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" /data/emu/rom-groomer/organizers/organize-roms.sh /path/to/roms ``` ### English Build (USA + International English) ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" /data/emu/rom-groomer/organizers/organize-roms.sh /path/to/roms ``` ### All Languages Build ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="" /data/emu/rom-groomer/organizers/organize-roms.sh /path/to/roms ``` ### Completely Flat (No Organization) ```bash # Simply don't call organize-roms.sh # Or set everything to keep in root export KEEP_IN_ROOT_REGIONS="USA,World,Europe,Japan,..." ``` --- ## Migration Path ### For Existing Build Scripts 1. Add environment variable configuration section 2. Set appropriate values based on build type (USA/ENG/ALL) 3. Remove any manual organize-roms.sh calls (nointro-processor.sh handles it) ### Example Migration **Before:** ```bash # No configuration needed, used flags ``` **After:** ```bash # ROM Organization Configuration export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" ``` --- ## Technical Details ### Language Detection - Parses language codes from filename using regex - Matches patterns like `(En)`, `(Fr,De)`, `(En,Fr,De,Es)` - Validates against `LANGUAGE_ARRAY` from config-arrays.sh - Supports all No-Intro language codes ### Region Detection - Parses region from filename using regex - Matches patterns like `(USA)`, `(Europe)`, `(Japan)` - Validates against `REGION_ARRAY` from config-arrays.sh - Supports all No-Intro regions ### Symlink Creation - Uses relative paths for portability - Calculates depth from language folder to original file - Creates parent directories on-demand - Handles spaces and special characters in filenames ### Validation - All variables validated against defined arrays - Unknown regions/languages/kinds logged as warnings - Invalid configuration stops execution with error - Comprehensive error messages --- ## Known Limitations 1. **Language detection requires language tags** - ROMs without language tags in filename won't get language symlinks 2. **Region detection required for exclusion** - ROMs without region tags can't be excluded from language folders 3. **Symlinks not supported on all filesystems** - Some network filesystems may not support symlinks 4. **No automatic symlinking for USA games** - If `LANGUAGE_EXCLUDE_REGIONS` includes USA, USA English games won't be in English folder (by design) --- ## Future Enhancements Potential improvements for future versions: 1. **GUI Configuration** - Web interface for setting variables 2. **Per-System Configuration** - Different settings for different systems 3. **Language Priority** - Prefer certain languages when multiple available 4. **Automatic DAT Parsing** - Read language info from No-Intro DAT files 5. **Symlink Verification** - Check and repair broken symlinks 6. **Hard Link Option** - Alternative to symlinks for unsupported filesystems --- ## Related Documentation - [BUILD-SCRIPT-CONFIGURATION.md](./BUILD-SCRIPT-CONFIGURATION.md) - User configuration guide - [KEEP-IN-ROOT-IMPLEMENTATION.md](./KEEP-IN-ROOT-IMPLEMENTATION.md) - Technical implementation details - [ONDEMAND-FOLDERS-IMPLEMENTATION.md](./ONDEMAND-FOLDERS-IMPLEMENTATION.md) - On-demand folder creation - [test-language-symlinks.sh](../tests/test-language-symlinks.sh) - Comprehensive test suite - [organize-roms.sh](../organizers/organize-roms.sh) - Main organization script --- ## Conclusion The language symlink organization system provides a flexible, efficient way to organize ROM collections by language without duplicating files. Combined with region and kind organization, it creates a comprehensive three-tier organization structure that accommodates different use cases (USA-only, English, all languages) while keeping the most common games easily accessible. **Status: Production Ready** ✅ All features implemented, tested, and documented. Ready for use in build scripts.