disagreement/docs/i18n.md
2025-06-09 22:25:14 -06:00

37 lines
953 B
Markdown

# Internationalization
Disagreement can translate command names, descriptions and other text using JSON translation files.
## Providing Translations
Use `disagreement.i18n.load_translations` to load a JSON file for a locale.
```python
from disagreement import i18n
i18n.load_translations("es", "path/to/es.json")
```
The JSON file should map translation keys to translated strings:
```json
{
"greet": "Hola",
"description": "Comando de saludo"
}
```
You can also set translations programmatically with `i18n.set_translations`.
## Using with Commands
Pass a `locale` argument when defining an `AppCommand` or using the decorators. The command name and description will be looked up using the loaded translations.
```python
@slash_command(name="greet", description="description", locale="es")
async def greet(ctx):
await ctx.send(i18n.translate("greet", ctx.locale or "es"))
```
If a translation is missing the key itself is returned.