# localization

## 🌍 Localization

### Overview

SL-Chat supports multiple languages through JSON translation files located in `data/language/`.

***

### Available Languages

| Language | File                    |
| -------- | ----------------------- |
| English  | `data/language/en.json` |
| Polish   | `data/language/pl.json` |

***

### Configuration

Set the default language in `shared/translate.config.lua`:

```lua
Translate.DefaultLanguage = 'pl'  -- or 'en'
```

***

### Translation File Structure

#### English (en.json)

```json
{
    "chat": {
        "cooldown": "You must wait {remaining} seconds before using this command.",
        "messageTooShort": "Message is too short.",
        "messageTooLong": "Message is too long.",
        "noPermission": "You don't have permission to use this command.",
        "playerNotFound": "Player not found.",
        "reportSent": "Report sent to staff.",
        "streamerModeEnabled": "Streamer mode enabled.",
        "streamerModeDisabled": "Streamer mode disabled."
    },
    "commands": {
        "me": {
            "description": "Describe your action"
        },
        "do": {
            "description": "Describe the environment"
        },
        "try": {
            "description": "Attempt an action",
            "success": "succeeded",
            "failure": "failed"
        }
    }
}
```

***

#### Polish (pl.json)

```json
{
    "chat": {
        "cooldown": "Musisz poczekać {remaining} sekund przed użyciem tej komendy.",
        "messageTooShort": "Wiadomość jest za krótka.",
        "messageTooLong": "Wiadomość jest za długa.",
        "noPermission": "Nie masz uprawnień do użycia tej komendy.",
        "playerNotFound": "Nie znaleziono gracza.",
        "reportSent": "Zgłoszenie wysłane do administracji.",
        "streamerModeEnabled": "Tryb streamera włączony.",
        "streamerModeDisabled": "Tryb streamera wyłączony."
    },
    "commands": {
        "me": {
            "description": "Opisz swoją akcję"
        },
        "do": {
            "description": "Opisz otoczenie"
        },
        "try": {
            "description": "Spróbuj wykonać akcję",
            "success": "udało się",
            "failure": "nie udało się"
        }
    }
}
```

***

### Adding New Language

1. Create new file: `data/language/de.json` (German example)
2. Copy structure from `en.json`
3. Translate all strings
4. Set in config:

```lua
Translate.DefaultLanguage = 'de'
```

***

### Using Translations

#### In Server Scripts

```lua
local text = Translate('chat.cooldown', {remaining = 5})
-- Result: "Musisz poczekać 5 sekund przed użyciem tej komendy."
```

#### With Placeholders

```lua
local text = Translate('chat.messageTooLong', {max = 150})
```

***

### Placeholder Format

Use `{placeholder}` in translation strings:

```json
{
    "greeting": "Hello, {name}! You have {count} messages."
}
```

```lua
Translate('greeting', {name = 'John', count = 5})
-- Result: "Hello, John! You have 5 messages."
```

***

### Template Translations

Template labels can also be translated:

```lua
Chat.Templates = {
    ['ERROR'] = {
        template = [[
            <span style="...">{Translate('templates.error')}</span>
            <span>{message}</span>
        ]]
    }
}
```

***

### Next Steps

* 🛠️ Configuration - Main config
* 💬 Commands - Chat commands
* 📝 Templates - Template system
