Metadata-Version: 2.4
Name: dpy-i18n
Version: 0.0.3
Summary: Auto-translating i18n for discord.py — just write keys, strings translate themselves
License-Expression: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.13
Description-Content-Type: text/markdown
Requires-Dist: discord.py>=2.3
Requires-Dist: PyYAML>=6.0

# discord-i18n

Auto-translating i18n for discord.py. Write translation keys — they get resolved automatically when you send messages, embeds, or buttons.

## Installation

```bash
pip install -e .
```

## Setup (main.py)

```python
from discord_i18n import I18nBot

bot = I18nBot(command_prefix="!", intents=discord.Intents.default())
# That's it. I18nBot:
#  - loads lang/ automatically
#  - patches send_message / edit_message so keys are auto-translated
#  - registers the slash-command translator
```

## Usage in Cogs

```python
from discord_i18n import I18nCog, t

class MyCog(I18nCog):

    @app_commands.command(...)
    async def cmd(self, interaction):

        # 1. Plain key as content — auto-translated
        await interaction.response.send_message("embed.test.title")

        # 2. Key embedded in a string
        await interaction.response.send_message("🎉 {embed.test.title}")

        # 3. Key in Embed fields — auto-translated
        embed = discord.Embed(
            title="embed.test.title",
            description="embed.test.description",
        )
        embed.set_footer(text="embed.test.footer")
        await interaction.response.send_message(embed=embed)

        # 4. Key in Button labels — auto-translated
        view = discord.ui.View()
        view.add_item(discord.ui.Button(label="embed.test.title"))
        await interaction.response.send_message(view=view)

        # 5. Manual via self.t() — when you need the string first
        text = self.t(interaction, "embed.test.title")

        # 6. Manual via module-level t() — usable anywhere
        text = t(interaction, "embed.test.title")
```

## Variables

```yaml
# lang/en.yaml
welcome:
  message: "Hello, {user}!"
```
```python
await interaction.response.send_message("welcome.message", user=interaction.user.mention)
```

## Directory layout

```
lang/
  en.yaml           ← UI / embed strings
  de.yaml
  commands/
    en.yaml         ← slash-command names & descriptions
    de.yaml
```

### lang/en.yaml
```yaml
embed:
  test:
    title: "🇬🇧 Test Embed"
    description: "This is an English test embed."
    footer: "English"
```

### lang/commands/en.yaml
```yaml
test: "test"
test_description: "Shows a test embed."
```

## API

| Symbol | Description |
|---|---|
| `I18nBot(**kwargs)` | Bot subclass. Pass `lang_dir=` and `fallback=` to customise. |
| `I18nCog` | Optional Cog base class. Adds `self.t(interaction, key, **vars)`. |
| `t(interaction, key, **vars)` | Translate a key manually. Works anywhere. |
| `I18n(lang_dir, fallback)` | Core class — use directly if you don't want `I18nBot`. |
| `apply_patches()` | Apply the monkey-patches manually (called by `I18nBot` automatically). |
