darrenfoley / Asiago

A Discord bot written in C#
GNU General Public License v3.0
1 stars 0 forks source link

Use .NET localization services instead of hardcoded language strings #15

Open darrenfoley opened 2 months ago

darrenfoley commented 2 months ago

Is your feature request related to a problem? Please describe. Currently, language strings sent in Discord messages and embeds are hardcoded in English in the C#. In some cases, particularly with error messages, the same string is often hardcoded in multiple places. If we want to change a string, we need to grep for it and potentially change it in multiple places. Additionally, if we ever decided to offer support for other languages, the current system would be completely unworkable.

Describe the solution you'd like Instead, we should use .NET localization services, with language strings defined in resource files. The IStringLocalizer<T> service will be available via dependency injection and language strings can be retrieved by name. Information about this is available here.

If we decide to support other languages in the future, we could store language config per guild (or maybe per user, but I doubt it?) in the db and use the CustomRequestCultureProvider class, or our own provider class, to look up the language/culture for each request. More info here.

t-vaudry commented 2 months ago

https://learn.microsoft.com/en-us/dotnet/core/extensions/localization