Giter VIP home page Giter VIP logo

discord.py-i18n-demo's Introduction

discord.py-i18n-demo

This project demonstrates how to set up gettext localization and integrate it into discord.py v2.0.

Check out the onboarding if you want to learn how gettext and the package works. If you just want to test out the package, then:

  1. Install this repository

    python -m pip install git+https://github.com/thegamecracks/discord.py-i18n-demo
  2. Create a config.toml file with your bot token

    [bot]
    token = "Bot token from https://discord.com/developers/applications"
  3. Start the bot

    python -m dpygt
  4. Use the "<@mention> sync" text command to register application commands

Requirements

  • Python 3.11 or greater
  • gettext and its associated utilities, particularly msgfmt

Alternatives

discord.py can be used with any translation library, not just gettext. If you are interested in alternatives, consider using Project Fluent via the fluent-compiler package which provides more comprehensive localization features such as arbitrarily-defined message variants, message cross-references, and automatic numeric/datetime formatting (see also Fluent vs. gettext).

Contributing

Want to add translations? Fork this repository, create a new branch, commit your changes there, then make a pull request. You may want to read the onboarding to learn how localizations are done, or look at how existing localizations are written.

discord.py-i18n-demo's People

Contributors

bubobubobubobubo avatar thegamecracks avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

discord.py-i18n-demo's Issues

[FEATURE] Add link to example Fluent discord bot

At the risk of self promoting, now that you recommend checking out Fluent as an alternative to Gettextt, might I recommend a link to my discord bot framework, Basic Discord Bot? It's another open source implementation of discord.py's translation library, though I intend continue adding more features that I've created for my own discord bot.

If not, feel free to delete this comment

Either way, thank you so much for this project! I've used it to learn how to implement translations myself and am very grateful that you released it!

Add translated enums

Is your feature request related to a problem? Please describe

It would be nice to have examples of how to use parameterized input.

Describe the solution you'd like

One thing that would be great is an example of an enum as a parameter. If you add an enum as a parameter, you just need to add the translations and discord.py will automatically handle them. If you follow this example from the docs, you only need to add apple, banana, and cherry` to the translator:

class Fruits(enum.Enum):
    apple = 1
    banana = 2
    cherry = 3

@app_commands.command()
@app_commands.describe(fruits='fruits to choose from')
async def fruit(interaction: discord.Interaction, fruits: Fruits):
    await interaction.response.send_message(f'Your favourite fruit is {fruits}.')

In this example, (I believe) you only need to replace the names with locale_strs

@app_commands.command()
@app_commands.describe(fruits='fruits to choose from')
@app_commands.choices(fruits=[
    Choice(name='apple', value=1),
    Choice(name='banana', value=2),
    Choice(name='cherry', value=3),
])
async def fruit(interaction: discord.Interaction, fruits: Choice[int]):
    await interaction.response.send_message(f'Your favourite fruit is {fruits.name}.')

Describe alternatives you've considered

n/a

Additional context

Thank you so much for making this project! I'm using this now and learning Fluent to add to my current bot. I hope this project helps a lot of people!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.