sapphiredev/framework

request: language support

kyranet opened this issue · 0 comments

Is your feature request related to a problem? Please describe.

As a good framework, we need to implement a built-in way to allow developers customize the strings the framework uses without changing nor transferring its internals, and we can do two features in one: i18n support.

Describe the solution you'd like

We would use i18next for loading, parsing, formatting, and so on. The reasoning behind this is because it's a framework with a very large community that also features a large amount of support (StackOverflow), utilities (online translation services), and plugins (ICU, formatters...), as well as this framework can be used on the web so if a developer does a Sapphire bot with a front-end, they will not have to learn two i18n frameworks.

We would also require an extra method on Client:

Client#fetchLanguage: (message: Message) => string | Promise<string>;

This method is defined by default as a method that returns en-US, may be overriden by users or by plugins. We cannot know which ORM or database driver the developer is using, so we provide this as a method they can freely override.

Additionally we may also provide the following extensions:

Message#sendTranslated(key: string, options?: MessageOptions): Promise<MessageReturn>;
Message#sendTranslated(key: string, values: {}, options?: MessageOptions): Promise<MessageReturn>;
Message#fetchLanguage(): Promise<Language>;
Message#fetchLanguageKey(key: string, values?: {}): Promise<string>;

Describe alternatives you've considered

I considered using a Map and do the entire thing in bare JavaScript, but comes with many issues and everything boils to this.

Additional context

N/a.