Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

feat(i18n): implement localisation (#197) #324

Closed
wants to merge 13 commits into from

Conversation

perzeuss
Copy link

@perzeuss perzeuss commented Aug 20, 2020

This Feature implements:

  • Localization for all communications between commando and users.
  • A (default) command to get and set the global/guild language and load/reload language files.

To translate commando into your language simply do the following:

  1. Create a language file by using the included util createTranslationFile found in src/i18n/dev.js

  2. Create a folder for each language and place the language file just created into it

  3. Define the translation settings in the CommandoClient#options like:

        new CommandoClient({
            commandPrefix: '!',
            i18n: {
                debug: true, // Enables debug mode of i18next which will tell you if locale files where not found
                loadTranslations: true, // If you set this to false, Commando will not look for translation files and instead load the builtin ones
                localesPath: path.join(__dirname, 'i18n/{{lng}}/{{ns}}.json'), // Define where you've put the translation files. Leave `{{lng}}` and `{{ns}}` as they tell i18next where to look for language files. In this case it will look in `i18n/en/commando.json` to load the language file for `en`
                supportedLanguages: [ 'de', 'fr', 'en'], // Tip: This are the languages you can swith to using the command `!language CODE`
                overrides: {
                // You can configure everything from https://www.i18next.com/overview/configuration-options in here
                },
            },
        });

Learn how to use translations

I've created a guide on repl.it where you have a playground with a working example of commando with translations.

Copy link

@d-513 d-513 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, locale was the only thing that kept me from using Commando for all my bots since some are specifically made for my non-english server. I used a patch workaround but I really do think this PR will be very useful.

@FlyCrafting
Copy link

FlyCrafting commented Jan 26, 2021

when you plan to merge it? I'm waiting this feature.

Comment on lines 299 to 304
export class CommandoGuild extends Guild {
private _commandPrefix: string;
private _language: string;
private _commandsEnabled: object;
private _groupsEnabled: object;
private _settings: GuildSettingsHelper;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public language: string; is required

@perzeuss
Copy link
Author

perzeuss commented Feb 17, 2021

when you plan to merge it? I'm waiting this feature.

After a conversation with @Gawdl3y I started to rewrite the code to implement the Loader/Loadable functionality according to the ideas from #196, but I had no time to complete the work.

I've reviewed my changes and pushed what I have so far, but I did not have time yet to test it and there are some changes I want to make.

Since the code isn't ready to merge, I'll close this PR and re open it when I'm done.

@perzeuss perzeuss closed this Feb 17, 2021
@perzeuss perzeuss mentioned this pull request Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants