{"id":15793102,"url":"https://github.com/damego/interactions-i18n","last_synced_at":"2025-03-14T14:30:49.384Z","repository":{"id":63614046,"uuid":"569224907","full_name":"Damego/interactions-i18n","owner":"Damego","description":"Add localization support to your interactions.py bot","archived":false,"fork":false,"pushed_at":"2022-12-28T17:31:04.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-11T23:29:15.551Z","etag":null,"topics":["bot","discord","i18n","interactions","localization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Damego.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-22T11:03:54.000Z","updated_at":"2023-08-26T13:56:31.000Z","dependencies_parsed_at":"2023-01-31T07:00:22.463Z","dependency_job_id":null,"html_url":"https://github.com/Damego/interactions-i18n","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Damego%2Finteractions-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Damego%2Finteractions-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Damego%2Finteractions-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Damego%2Finteractions-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Damego","download_url":"https://codeload.github.com/Damego/interactions-i18n/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243593239,"owners_count":20316154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","discord","i18n","interactions","localization"],"created_at":"2024-10-04T23:09:07.962Z","updated_at":"2025-03-14T14:30:48.919Z","avatar_url":"https://github.com/Damego.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# interactions-i18n\nAdd localization support to your interactions.py bot\n\n## Installation\n\n1. `pip uninstall discord-py-interactions`\n2. `pip install git+https://github.com/interactions-py/library.git@4.4.0-beta.1`\n3. `pip install --upgrade interactions-i18n`\n\n\n## Usage\n\n```py\nimport interactions\nfrom interactions.ext.i18n import setup\n\nclient = interactions.Client(...)\n\n# Load an i18n extension\ni18n = setup(client)\n\n...  # your cool commands and cogs loads\n\n# Load a folder with localization\ni18n.load(\"./locales/de\")\nclient.start()\n```\n\n### Usage in Extension\n\n```py\nfrom interactions import Extension\nfrom interactions.ext.i18n import Localization\n\n\nclass MyExt(Extension):\n    def __init__(self, client):\n        self.client = client\n\n        self.i18n: Localization = self.client.i18n\n```\n\n## Creating localization files\n\n1. Choose a language you want and find their code in the [Discord Locales Docs](https://discord.com/developers/docs/reference#locales)\n2. Create a `[CODE]` folder with found code and put it in the folder with locales.\n3. Create two files. First is `commands.json` for your commands and second is `custom.json` for anything you want\n\n## Example\n\nLet's create a command with name `info` with some subcommands\n\n```py\n@client.command()\nasync def info(ctx: interactions.CommandContext):\n    ...\n\n@info.group()\nasync def my_group(ctx: interactions.CommandContext):\n    ...\n\n@my_group.subcommand()\n@interactions.option()\nasync def user(ctx: interactions.CommandContext, member: interactions.Member):\n    loc = i18n.get_translate(\"some_key\", ctx.locale)\n    await ctx.send(loc)\n```\n\n### Structure of json files\n\n`locales/de/commands.json`\n\nThis file will contain localizations for your commands\n\n```json\n{\n    \"info\": { // command name\n        \"name\": \"...\", // localized name\n        \"description\": \"...\", // localized description\n        \"options\": { // options of command. Command groups and subcommands are options btw\n            \"my_group\": {\n                \"name\": \"...\",\n                \"description\": \"...\",\n                \"options\": {\n                    \"user\": {\n                        \"name\": \"...\",\n                        \"description\": \"...\",\n                        \"options\": {\n                            \"member\": {\n                                \"name\": \"...\",\n                                \"description\": \"...\",\n                                // if your option have choices you can do:\n                                \"choices\": {\n                                    \"choice_name\": \"...\"\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n```\n\n`locales/de/custom.json`\n\nThis file will contain your custom localizations for anything\n\n```json\n{\n  \"SOME_KEY\": \"Some value\"\n}\n```\n\n## Automatic file generation\n\nIt seems difficult to write every command in the json, so you can generate file with your commands.\nYou need to only fill empty strings with your language\n\n```python\nfrom interactions import Client, Locale\nfrom interactions.ext.i18n import setup\n\nbot = Client(...)\ni18n = setup(bot)\n# i18n.load(\"./locales/de\")\n\n...  # your cool commands\n\n# call this function in the end of main file\ni18n.generate_files(Locale.GERMAN, \"./locales/\")\n# bot.start()  # comment line where starts your bot\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamego%2Finteractions-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamego%2Finteractions-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamego%2Finteractions-i18n/lists"}