Skip to main content

interactions-i18n

Add localization support to your interactions.py bot

Installation

  1. pip uninstall discord-py-interactions
  2. pip install git+https://github.com/interactions-py/library.git@4.4.0-beta.1
  3. pip install --upgrade interactions-i18n

Usage

import interactions
from interactions.ext.i18n import setup

client = interactions.Client(...)

# Load an i18n extension
i18n = setup(client)

...  # your cool commands and cogs loads

# Load a folder with localization
i18n.load("./locales/de")
client.start()

Usage in Extension

from interactions import Extension
from interactions.ext.i18n import Localization


class MyExt(Extension):
    def __init__(self, client):
        self.client = client

        self.i18n: Localization = self.client.i18n

Creating localization files

  1. Choose a language you want and find their code in the Discord Locales Docs
  2. Create a [CODE] folder with found code and put it in the folder with locales.
  3. Create two files. First is commands.json for your commands and second is custom.json for anything you want

Example

Let's create a command with name info with some subcommands

@client.command()
async def info(ctx: interactions.CommandContext):
    ...

@info.group()
async def my_group(ctx: interactions.CommandContext):
    ...

@my_group.subcommand()
@interactions.option()
async def user(ctx: interactions.CommandContext, member: interactions.Member):
    loc = i18n.get_translate("some_key", ctx.locale)
    await ctx.send(loc)

Structure of json files

locales/de/commands.json

This file will contain localizations for your commands

{
    "info": { // command name
        "name": "...", // localized name
        "description": "...", // localized description
        "options": { // options of command. Command groups and subcommands are options btw
            "my_group": {
                "name": "...",
                "description": "...",
                "options": {
                    "user": {
                        "name": "...",
                        "description": "...",
                        "options": {
                            "member": {
                                "name": "...",
                                "description": "...",
                                // if your option have choices you can do:
                                "choices": {
                                    "choice_name": "..."
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

locales/de/custom.json

This file will contain your custom localizations for anything

{
  "SOME_KEY": "Some value"
}

Automatic file generation

It seems difficult to write every command in the json, so you can generate file with your commands. You need to only fill empty strings with your language

from interactions import Client, Locale
from interactions.ext.i18n import setup

bot = Client(...)
i18n = setup(bot)
# i18n.load("./locales/de")

...  # your cool commands

# call this function in the end of main file
i18n.generate_files(Locale.GERMAN, "./locales/")
# bot.start()  # comment line where starts your bot

Metadata

Release files for interactions-i18n 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for interactions-i18n 1.0.0
File Size Uploaded
interactions-i18n-1.0.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for interactions-i18n 1.0.0
File Interpreter ABI Platform
interactions_i18n-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / interactions-i18n-1.0.0.tar.gz

Download URL interactions-i18n-1.0.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6497635cee3537097f91dd8b138c44e212ef8fdf01d984e0c6d17d8d40fae328
BLAKE2b-256 checksum
How to use checksums
7c68cc69ce9256d7e38f24c505c34496f4e34926f7bd22537fed9fd0f18b44a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / interactions_i18n-1.0.0-py3-none-any.whl

Download URL interactions_i18n-1.0.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fb0f081d0f743cd4b16ab2749b8a9d57c04bc4ad9101754875325e2e21a1a15
BLAKE2b-256 checksum
How to use checksums
13fc8f377ae227caaef689ef18eb41e2d3afc0b0981c4e2c2942fc79451b1619
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page