Precondition i18n
Per this example here https://www.sapphirejs.dev/docs/Guide/preconditions/global-preconditions is it possible to like use one i18n function for it to work for all them with the message or do I have to take special precautions and check which type it is?
Sapphire Framework
Global preconditions | Sapphire
Sometimes you want a precondition that automatically runs for every command, without having to add it to each command.
Solution:Jump to solution
If so, no, but you don't send messages through the preconditions anyway. You to that through listeners. And you identify the identifier there then send the translated message. See https://github.com/skyra-project/skyra/blob/main/src/listeners/commands/messageCommandDenied.ts for an example.
GitHub
skyra/src/listeners/commands/messageCommandDenied.ts at main · skyr...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
8 Replies
One function to do what
Oh to translate it
Get the localized string
So you mean translate the message from a precondition denial?
Solution
If so, no, but you don't send messages through the preconditions anyway. You to that through listeners. And you identify the identifier there then send the translated message. See https://github.com/skyra-project/skyra/blob/main/src/listeners/commands/messageCommandDenied.ts for an example.
GitHub
skyra/src/listeners/commands/messageCommandDenied.ts at main · skyr...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
Yeah I got that part it was more like trying to do one function so I don't have to like get the translation in each message
Cause it seems in that example that the actual error is sent there and then it's parsed by something else
Like I have a chatInputCommandDenied but I would have to extend all 3 then I assume?
Basically it all sums down me wanting to avoid having to translate message and just do it at the end of banlistcheck
But I guess it doesn't really matter cause I can just send a string as it's 3 functions, it was just trying to write less code for not much gain
Okay I re-read it and it makes sense, thank you. To sum it up just move the translation to the listeners instead and have a hardcoded string here just to know what error.
Correct