Multi-Language Support

New in v1.0.0

Create mods that support multiple languages

The i18n API lets your mod support English, Spanish, French, and other languages automatically based on the player's game settings.

Creating Translations#

Use i18n.create() to define translations for your mod:

javascript
const t = SubwayBuilderAPI.utils.i18n.create({
    en: {
        greeting: 'Hello',
        status: 'Active',
        passengers: 'passengers'
    },
    es: {
        greeting: 'Hola',
        status: 'Activo',
        passengers: 'pasajeros'
    },
    fr: {
        greeting: 'Bonjour',
        status: 'Actif',
        passengers: 'passagers'
    }
});

// Use the translation function
t('greeting'); // Returns "Hola" if game is set to Spanish
t('status'); // Returns "Actif" if game is set to French
t('passengers'); // Returns "passengers" (English fallback if translation missing)

How It Works#

The returned t() function automatically:

  1. Checks the player's current game language setting
  2. Returns the translation for that language
  3. Falls back to English if a translation is missing
  4. Falls back to the key itself if English is also missing

Supported Languages#

The game supports these language codes:

CodeLanguage
enEnglish
esSpanish
frFrench
deGerman
ptPortuguese
itItalian
jaJapanese
koKorean
zhChinese (Simplified)

Complete Example#

javascript
const api = window.SubwayBuilderAPI;

// Define all translations for your mod
const t = api.utils.i18n.create({
    en: {
        modName: 'My Transit Mod',
        settings: 'Settings',
        enableFeature: 'Enable Feature',
        stats: {
            passengers: 'Total Passengers',
            revenue: 'Daily Revenue'
        }
    },
    es: {
        modName: 'Mi Mod de Tránsito',
        settings: 'Configuración',
        enableFeature: 'Activar Función',
        stats: {
            passengers: 'Total de Pasajeros',
            revenue: 'Ingresos Diarios'
        }
    },
    fr: {
        modName: 'Mon Mod de Transit',
        settings: 'Paramètres',
        enableFeature: 'Activer la Fonction',
        stats: {
            passengers: 'Total des Passagers',
            revenue: 'Revenus Quotidiens'
        }
    }
});

// Use in your mod
api.ui.addButton('settings-menu', {
    id: 'my-mod-settings',
    label: t('settings'),
    onClick: () => {
        api.ui.showNotification(t('modName') + ' ' + t('stats.passengers'));
    }
});

Nested Translations#

You can nest translation objects for better organization:

javascript
const t = api.utils.i18n.create({
    en: {
        menu: {
            file: 'File',
            edit: 'Edit',
            view: 'View'
        },
        messages: {
            saved: 'Game saved successfully',
            error: 'An error occurred'
        }
    },
    es: {
        menu: {
            file: 'Archivo',
            edit: 'Editar',
            view: 'Ver'
        },
        messages: {
            saved: 'Juego guardado exitosamente',
            error: 'Ocurrió un error'
        }
    }
});

t('menu.file'); // "Archivo" in Spanish
t('messages.saved'); // "Juego guardado exitosamente" in Spanish

Tips#

  • Always provide English (en) translations as the fallback
  • Keep translation keys consistent across all languages
  • Test your mod in different languages to ensure translations display correctly
  • Use descriptive key names that indicate the context