Saria Translator
Loading language modules...
Initializing...
⚠️

Module Loading Errors

Some language modules failed to load. The translator will continue with the modules that loaded successfully.
Modular Translation Workbench

Saria Translator

Translate, detranslate, and mix loaded language modules from one shell without losing the line between the framing, controls, and active work area.

v0.7.7
Translator Status
Loading translator version…

Input

Test Phrases Presets
Inserts common test phrases to quickly evaluate translation behavior.
Open module configuration to enable/disable modules and reorder transformers.
View and reset saved configuration settings.
View the changelog and see what's been updated.

Output + Modifiers

Character Presets Presets
Question / Mood Flags Toggles
These can be combined. Your rules file decides how combinations resolve.
Style Controls Sliders
Sliders are passed into the translator as parameters; rules decide how they affect output.
Debug Info

Module Configuration

Upload a zip file containing a custom language module

Installed Modules (Drag ⋮⋮ to reorder • 🔧 = Built-in, 📦 = Custom)

Module & Transformer Order

Drag modules or transformers to reorder the translation pipeline. Modules apply in top-to-bottom order.

Settings Manager

🎉 What's New

📚 Module Creation Guide

📚 Overview

Welcome to the custom module creation guide! This guide will walk you through creating your own translation modules for the Saria Translator system.

What is a Module?

A module is a self-contained unit that applies linguistic transformations to text. Each module can define:

  • Transformers - Functions that modify text (e.g., phonology, lexicon, grammar)
  • Sliders - UI controls that adjust transformation intensity
  • Flags - Boolean toggles for features
  • Moods - Normalized emotional state controls

Module Philosophy

The Saria Translator is designed for constructed languages (conlangs) and linguistic transformations. Modules can:

  • Apply phonological changes (sound shifts)
  • Replace vocabulary (lexical substitution)
  • Modify grammar and syntax
  • Add stylistic effects (like UWU speak or accents)
  • Combine multiple linguistic layers
💡 Key Principle: Modules use a progressive "band" system where transformations become more aggressive as slider values increase. This allows users to control how strongly a language effect is applied.

What You'll Need

  • Basic JavaScript knowledge (ES6 modules)
  • Understanding of your linguistic transformation rules
  • A text editor
  • A way to create ZIP files

Quick Start Checklist

  1. Define your module metadata and transformers
  2. Create data files for linguistic rules
  3. Write transformer functions
  4. Package as ZIP file
  5. Upload and test
✅ Ready to start? Click through the navigation tabs above to learn about each component of a custom module.

🏗️ Module Structure

Required Files

A custom module ZIP must contain at minimum:

File Purpose Required?
module.js Main module definition and exports ✅ Yes
data.js Linguistic data (lexicon, rules, etc.) ⚠️ Recommended
transformer_*.js Individual transformation functions ⚠️ As needed

Module.js Template

Here's the basic structure of a module.js file:

export const MyModule = {
  // Unique identifier (lowercase, no spaces)
  id: "mymodule",
  
  // Display name
  name: "My Custom Module",
  
  // Version string
  version: "1.0.0",
  
  // Description shown in UI
  description: "Brief description of what this module does",
  
  // Optional: author information
  author: "Your Name",
  
  // Optional: default enabled state
  enabled: true,
  
  // Sliders for user control
  sliders: [
    {
      id: "mymoduleIntensity",  // Must be unique across all modules
      label: "Intensity",
      defaultValue: 50,
      min: 0,
      max: 100,
      hint: "Controls how strongly transformations are applied"
    }
  ],
  
  // Optional: flags for boolean toggles
  flags: [
    {
      id: "mymoduleSpecialMode",
      label: "Enable Special Mode",
      defaultValue: false
    }
  ],
  
  // Optional: mood sliders (normalized 0-1, sum to 1.0)
  moods: [],
  
  // Transformers (the core transformation pipeline)
  transformers: [
    {
      id: "phonology",
      name: "Phonology",
      apply: (text, context, steps, tokenMap) => {
        // Your transformation logic here
        return text;
      }
    }
  ]
};
💡 Naming Convention: Slider IDs should be prefixed with your module name (e.g., mymoduleIntensity) to avoid conflicts with other modules.

Import Structure

If you have separate files, use ES6 imports:

// In module.js
import { applyPhonology } from './phonology.js';
import { applyLexicon } from './lexicon.js';
import { MY_LEXICON_DATA } from './data.js';

export const MyModule = {
  // ... module definition
};
⚠️ Important: All file paths in imports are relative to the module root. The system will resolve them correctly when loading your module.

⚙️ Transformers

What is a Transformer?

A transformer is a function that takes text and returns modified text. Each transformer receives four parameters:

(text, context, steps, tokenMap) => {
  // Your transformation logic
  return modifiedText;
}

Transformer Parameters

Parameter Type Description
text string The input text to transform
context object Contains sliders, flags, and moods values
steps array Debug array to track transformations
tokenMap Map Tracks word-level transformations for Rule Inspector

Context Object Structure

The context object provides access to all module controls:

{
  sliders: {
    mymoduleIntensity: 0.5,  // Normalized 0-1 from UI 0-100
    mymoduleLexicon: 0.8,
    // ... all other module sliders
  },
  flags: {
    mymoduleSpecialMode: true,
    // ... all flags
  },
  moods: {
    fear: 0.25,
    comfort: 0.25,
    // ... normalized moods (sum = 1.0)
  }
}

Transformation Patterns

Pattern 1: Simple Replacement

Replace specific patterns in the text:

apply: (text, context, steps, tokenMap) => {
  let result = text;
  
  // Check slider value
  const intensity = context.sliders.mymoduleIntensity;
  
  // Apply replacement
  result = result.replace(/pattern/gi, 'replacement');
  
  // Track step for debugging
  steps.push({
    label: "My Transformation",
    preview: result
  });
  
  return result;
}
Pattern 2: Word-by-Word Processing

Process each word individually for lexical replacements:

import { LEXICON } from './data.js';

apply: (text, context, steps, tokenMap) => {
  const intensity = context.sliders.mymoduleLexicon;
  if (intensity < 0.2) return text;  // Skip if too low
  
  // Split preserving whitespace
  const tokens = text.split(/(\s+)/);
  
  const result = tokens.map(token => {
    // Extract word and punctuation
    const match = token.match(/^([A-Za-z']+)([?.!,;:]*)$/);
    if (!match) return token;
    
    const [, word, punct] = match;
    const lowerWord = word.toLowerCase();
    
    // Check lexicon
    if (LEXICON[lowerWord]) {
      const replacement = LEXICON[lowerWord];
      
      // Track transformation in tokenMap
      if (!tokenMap.has(lowerWord)) {
        tokenMap.set(lowerWord, []);
      }
      tokenMap.get(lowerWord).push({
        module: "mymodule",
        transformer: "lexicon",
        rule: `${lowerWord} → ${replacement}`
      });
      
      return replacement + punct;
    }
    
    return token;
  }).join('');
  
  steps.push({
    label: "Lexicon Replacement",
    preview: result
  });
  
  return result;
}
Pattern 3: Conditional Transformation

Apply different transformations based on flags or mood:

apply: (text, context, steps, tokenMap) => {
  let result = text;
  
  // Check flag
  if (context.flags.mymoduleSpecialMode) {
    result = result.replace(/old/gi, 'new');
  }
  
  // Check mood (if applicable)
  if (context.moods && context.moods.aggression > 0.5) {
    result = result.toUpperCase();
  }
  
  steps.push({
    label: "Conditional Transform",
    preview: result
  });
  
  return result;
}
💡 Best Practice: Always add a step to the steps array so users can debug transformations with "Show transformation steps" enabled.

📊 Band System

What are Bands?

The band system provides progressive intensity control. Transformations become more aggressive as slider values increase through four levels:

Band Slider Range Normalized (0-1) Usage
0 0-19% 0.0-0.19 Disabled - no transformations
1 20-49% 0.2-0.49 Light - subtle transformations
2 50-79% 0.5-0.79 Moderate - noticeable changes
3 80-100% 0.8-1.0 Full - maximum transformations

Using the Band Helper

Instead of implementing band logic manually, import the shared band utility:

// Import from shared utilities (works for custom modules)
import { band } from '../shared/banding.js';

apply: (text, context, steps, tokenMap) => {
  const intensity = context.sliders.mymoduleIntensity;
  const b = band(intensity);
  
  if (b === 0) return text;  // Skip if disabled
  
  let result = text;
  
  // Band 1: Light transformations (20-49%)
  if (b >= 1) {
    result = result.replace(/th/gi, 'd');
  }
  
  // Band 2: Moderate transformations (50-79%)
  if (b >= 2) {
    result = result.replace(/sh/gi, 'sch');
  }
  
  // Band 3: Full transformations (80-100%)
  if (b >= 3) {
    result = result.replace(/w/gi, 'v');
  }
  
  steps.push({ label: "Phonology", preview: result });
  return result;
}

Inline Band Logic

If you can't import the helper, implement it manually:

function getBand(intensity) {
  if (intensity < 0.2) return 0;
  if (intensity < 0.5) return 1;
  if (intensity < 0.8) return 2;
  return 3;
}

Band-Gated Replacement Limits

For lexicon transformations, limit replacements by band:

const limits = [0, 1, 3, Infinity];  // Band 0, 1, 2, 3
const b = band(intensity);
const maxReplacements = limits[b];

let replacementCount = 0;
tokens.forEach(token => {
  if (replacementCount >= maxReplacements) return;
  if (LEXICON[token]) {
    // Apply replacement
    replacementCount++;
  }
});
💡 Design Tip: Use bands to create a gradual progression. Band 1 should apply the most characteristic changes, Band 2 adds more noticeable effects, and Band 3 goes all-in.

🔍 Token Tracking (Rule Inspector)

What is TokenMap?

The tokenMap parameter is a Map that tracks word-level transformations for the Rule Inspector feature. Users can click words in the output to see which transformers modified them.

TokenMap Structure

Each entry in the Map uses the transformed word (lowercase) as the key:

tokenMap.set("transformedword", {
  original: "OriginalWord",
  current: "transformedword",
  transformations: [
    {
      module: "Module Display Name",
      transformer: "transformer_id",
      from: "before",
      to: "after",
      rule: "Human-readable description"
    }
  ]
});

Tracking Transformations

When a word is transformed, add an entry to tokenMap:

apply: (text, context, steps, tokenMap) => {
  const tokens = text.split(/(\s+)/);
  
  const result = tokens.map(token => {
    const match = token.match(/^([A-Za-z']+)([?.!,;:]*)$/);
    if (!match) return token;
    
    const [, word, punct] = match;
    const lowerWord = word.toLowerCase();
    
    // Check for replacement
    if (LEXICON[lowerWord]) {
      const replacement = LEXICON[lowerWord];
      const lowerReplacement = replacement.toLowerCase();
      
      // Track in tokenMap (if it exists)
      if (tokenMap) {
        // Initialize entry if first transformation
        if (!tokenMap.has(lowerReplacement)) {
          tokenMap.set(lowerReplacement, {
            original: word,
            current: replacement,
            transformations: []
          });
        }
        
        // Add transformation record
        tokenMap.get(lowerReplacement).transformations.push({
          module: "My Module",
          transformer: "lexicon",
          from: lowerWord,
          to: replacement,
          rule: `${lowerWord} → ${replacement}`
        });
      }
      
      return replacement + punct;
    }
    
    return token;
  }).join('');
  
  steps.push({ label: "Lexicon", preview: result });
  return result;
}
⚠️ Critical Rules:
  • Always check if (tokenMap) before tracking (it may be undefined)
  • Use lowercase transformed word as the Map key
  • Include module, transformer, from, to, and rule fields
  • The rule field should be human-readable for UI display

Example: Tracking Sound Changes

For phonological transformations that change spelling:

apply: (text, context, steps, tokenMap) => {
  const intensity = context.sliders.mymodulePhonology;
  const b = band(intensity);
  if (b === 0) return text;
  
  let result = text;
  const tokens = result.split(/(\s+)/);
  
  const transformed = tokens.map(token => {
    const match = token.match(/^([A-Za-z']+)([?.!,;:]*)$/);
    if (!match) return token;
    
    const [, word, punct] = match;
    let modified = word;
    
    // Band 1: TH → D
    if (b >= 1 && /th/i.test(modified)) {
      const before = modified;
      modified = modified.replace(/th/gi, 'd');
      
      // Track transformation
      if (tokenMap && before !== modified) {
        const key = modified.toLowerCase();
        if (!tokenMap.has(key)) {
          tokenMap.set(key, {
            original: word,
            current: modified,
            transformations: []
          });
        }
        
        tokenMap.get(key).transformations.push({
          module: "My Module",
          transformer: "phonology",
          from: before,
          to: modified,
          rule: "TH → D (Germanic shift)"
        });
      }
    }
    
    return modified + punct;
  }).join('');
  
  steps.push({ label: "Phonology", preview: transformed });
  return transformed;
}
💡 Pro Tip: If your transformer doesn't change word forms (only punctuation, spacing, etc.), you can skip tokenMap tracking.

📦 Packaging & Upload

File Structure

Your module ZIP should be organized like this:

mymodule/
├── module.js          # Main module definition (required)
├── data.js            # Linguistic data exports (recommended)
├── phonology.js       # Phonology transformer (if separate)
├── lexicon.js         # Lexicon transformer (if separate)
└── README.md          # Optional documentation

Validation Checklist

Before packaging, verify:

  • ✅ module.js exports a module object with id, name, version
  • ✅ All slider IDs are prefixed with your module name
  • ✅ All transformer functions return modified text
  • ✅ TokenMap tracking includes module, transformer, from, to, rule
  • ✅ Steps are pushed to steps array for debugging
  • ✅ All imports use relative paths (./filename.js)

Creating the ZIP File

  1. Place all module files in a folder named after your module
  2. Select all files inside the folder (not the folder itself)
  3. Right-click and choose "Compress" or "Send to → Compressed folder"
  4. Name the ZIP descriptively: mymodule-v1.0.zip
⚠️ Critical Requirement: The ZIP must contain files at the root level, not nested inside a folder. When you open the ZIP, you should see module.js immediately, not a folder containing module.js.

Upload Process

  1. Open the Saria Translator main page
  2. Click ⚙️ Configure Modules in the sidebar
  3. Scroll to 📦 Upload Custom Module section
  4. Click Choose File and select your ZIP
  5. Wait for confirmation message
  6. Page will reload automatically with your module loaded
  7. Find your module in the Style Controls sidebar

Testing Your Module

  1. After upload, check browser console (F12) for errors
  2. Verify your module appears in Configure Modules with ✅ status
  3. Enable "Show transformation steps" in debug controls
  4. Test with simple input phrases
  5. Adjust sliders to verify band-gated progression
  6. Enable "Rule Inspector" and click output words to verify tokenMap tracking
  7. Test edge cases: empty input, punctuation, numbers, special characters

Troubleshooting

Issue Cause Solution
Module doesn't appear ZIP structure incorrect Ensure files are at root level in ZIP
Import errors in console Relative paths wrong Use ./filename.js for same directory
Sliders don't work Slider ID conflicts Prefix slider IDs with module name
Transformations not applied Band check too restrictive Verify if (b === 0) check, test at 50%+
✅ Validation Tip: Test your module locally by temporarily adding it to saria_rules.js before packaging. This catches errors before upload.

📝 Complete Examples

Example 1: Simple French Accent Module

A single-file module with progressive phonology transformations:

// module.js
export const FrenchAccentModule = {
  id: "frenchaccent",
  name: "French Accent",
  version: "1.0.0",
  description: "Applies French phonology patterns",
  author: "Your Name",
  
  sliders: [
    {
      id: "frenchaccentIntensity",
      label: "Accent Strength",
      defaultValue: 50,
      min: 0,
      max: 100,
      hint: "Controls how strongly French phonology is applied"
    }
  ],
  
  transformers: [
    {
      id: "phonology",
      name: "French Phonology",
      apply: (text, context, steps, tokenMap) => {
        const intensity = context.sliders.frenchaccentIntensity || 0;
        
        // Band check
        if (intensity < 0.2) return text;
        
        let result = text;
        
        // Band 1: Basic French sounds (20-49%)
        if (intensity >= 0.2) {
          result = result.replace(/\\bth/gi, 'z');  // "the" → "ze"
          result = result.replace(/\\bh/gi, '');     // Drop H
        }
        
        // Band 2: More aggressive (50-79%)
        if (intensity >= 0.5) {
          result = result.replace(/w/gi, 'v');      // "water" → "vater"
          result = result.replace(/ing\\b/gi, 'ain'); // "doing" → "doain"
        }
        
        // Band 3: Full Frenchification (80-100%)
        if (intensity >= 0.8) {
          result = result.replace(/er\\b/gi, 'é');  // "danger" → "dangé"
        }
        
        steps.push({
          label: "French Phonology",
          preview: result
        });
        
        return result;
      }
    }
  ]
};
💡 Usage: Package just module.js in a ZIP. This is the simplest possible custom module.

Example 2: Fantasy Lexicon with Separate Files

A more complex module with data separation:

// data.js
export const FANTASY_LEXICON_BAND1 = {
  "magic": "mana",
  "wizard": "mage",
  "sword": "blade"
};

export const FANTASY_LEXICON_BAND2 = {
  "power": "essence",
  "strong": "mighty",
  "weak": "feeble"
};

export const FANTASY_LEXICON_BAND3 = {
  "friend": "companion",
  "enemy": "foe",
  "fight": "battle"
};
// lexicon.js
import { 
  FANTASY_LEXICON_BAND1,
  FANTASY_LEXICON_BAND2,
  FANTASY_LEXICON_BAND3
} from './data.js';

function getBand(intensity) {
  if (intensity < 0.2) return 0;
  if (intensity < 0.5) return 1;
  if (intensity < 0.8) return 2;
  return 3;
}

export function applyFantasyLexicon(text, intensity, steps, tokenMap) {
  const b = getBand(intensity);
  if (b === 0) return text;
  
  // Combine lexicons based on band
  let lexicon = { ...FANTASY_LEXICON_BAND1 };
  if (b >= 2) Object.assign(lexicon, FANTASY_LEXICON_BAND2);
  if (b >= 3) Object.assign(lexicon, FANTASY_LEXICON_BAND3);
  
  // Split preserving whitespace
  const tokens = text.split(/(\\s+)/);
  
  const result = tokens.map(token => {
    const match = token.match(/^([A-Za-z']+)([?.!,;:]*)$/);
    if (!match) return token;
    
    const [, word, punct] = match;
    const lowerWord = word.toLowerCase();
    
    if (lexicon[lowerWord]) {
      const replacement = lexicon[lowerWord];
      
      // Track in tokenMap
      if (tokenMap) {
        const key = replacement.toLowerCase();
        if (!tokenMap.has(key)) {
          tokenMap.set(key, {
            original: word,
            current: replacement,
            transformations: []
          });
        }
        
        tokenMap.get(key).transformations.push({
          module: "Fantasy Lexicon",
          transformer: "lexicon",
          from: lowerWord,
          to: replacement,
          rule: `${lowerWord} → ${replacement}`
        });
      }
      
      return replacement + punct;
    }
    
    return token;
  }).join('');
  
  steps.push({
    label: "Fantasy Lexicon",
    preview: result
  });
  
  return result;
}
// module.js
import { applyFantasyLexicon } from './lexicon.js';

export const FantasyLexiconModule = {
  id: "fantasylexicon",
  name: "Fantasy Lexicon",
  version: "1.0.0",
  description: "Replaces modern words with fantasy equivalents",
  
  sliders: [
    {
      id: "fantasylexiconIntensity",
      label: "Fantasy Level",
      defaultValue: 50,
      min: 0,
      max: 100,
      hint: "How much fantasy vocabulary to use"
    }
  ],
  
  transformers: [
    {
      id: "lexicon",
      name: "Lexicon Replacement",
      apply: (text, context, steps, tokenMap) => {
        return applyFantasyLexicon(
          text,
          context.sliders.fantasylexiconIntensity,
          steps,
          tokenMap
        );
      }
    }
  ]
};
💡 Usage: Package module.js, lexicon.js, and data.js together in a ZIP.

Example 3: Multi-Transformer Module

A complex module with both phonology and lexicon transformers:

// module.js
export const ComplexModule = {
  id: "complex",
  name: "Complex Multi-Stage Module",
  version: "1.0.0",
  description: "Combines phonology and lexicon transformations",
  
  sliders: [
    {
      id: "complexPhonology",
      label: "Phonology Strength",
      defaultValue: 50,
      min: 0,
      max: 100,
      hint: "Controls sound changes"
    },
    {
      id: "complexLexicon",
      label: "Vocabulary Replacement",
      defaultValue: 50,
      min: 0,
      max: 100,
      hint: "Controls word replacements"
    }
  ],
  
  flags: [
    {
      id: "complexFormalMode",
      label: "Formal Speech Mode",
      defaultValue: false
    }
  ],
  
  transformers: [
    // Phonology runs first
    {
      id: "phonology",
      name: "Phonology",
      apply: (text, context, steps, tokenMap) => {
        const intensity = context.sliders.complexPhonology;
        if (intensity < 0.2) return text;
        
        let result = text.replace(/th/gi, 'd');
        steps.push({ label: "Phonology", preview: result });
        return result;
      }
    },
    
    // Lexicon runs second
    {
      id: "lexicon",
      name: "Lexicon",
      apply: (text, context, steps, tokenMap) => {
        const intensity = context.sliders.complexLexicon;
        if (intensity < 0.2) return text;
        
        // Check formal mode flag
        const formal = context.flags.complexFormalMode;
        
        let result = text;
        if (formal) {
          result = result.replace(/\\bhi\\b/gi, 'greetings');
        } else {
          result = result.replace(/\\bhello\\b/gi, 'hey');
        }
        
        steps.push({ label: "Lexicon", preview: result });
        return result;
      }
    }
  ]
};
✨ Next Steps: Review these examples, adapt them to your linguistic needs, and start building! Use the other guide pages for detailed references on specific features.

🤖 LLM Assistant Prompt

Use this prompt with AI coding assistants (like GitHub Copilot, Claude, ChatGPT) to create custom modules. Copy the prompt below and provide it to your LLM along with your linguistic requirements.

💡 Tip: The LLM will ask you questions to understand your module's requirements. Have your linguistic rules, vocabulary lists, and transformation ideas ready!
Assistant: "I'll help you create a custom module! Let's start with some questions: 1. What would you like to name your module? 2. What type of linguistic transformation are you creating? (accent, conlang, style effect) 3. What are the key sound changes or vocabulary replacements you want? 4. Should the effect get stronger as the slider increases, or should it be all-or-nothing? Once I understand your requirements, I'll generate the complete module code ready to upload!" ## Additional Guidelines - Keep transformations linguistically consistent - Design Band 1 for the most characteristic changes - Reserve Band 3 for aggressive/experimental transformations - Test edge cases: punctuation, capitalization, empty strings - Consider word boundaries (use `\b` in regex where appropriate) - Preserve spacing and punctuation structure --- Now begin by asking the user the required questions to understand their module requirements!
✅ Ready to use: Copy this prompt, paste it into your AI assistant, and answer its questions to generate a custom module!