Maseshi / Shioru

🧸 (Discord) Your personal assistant that will make your discord never lonely again.
https://shiorus.web.app
MIT License
150 stars 22 forks source link

What is %s? #47

Closed IFlox closed 1 year ago

IFlox commented 1 year ago

I don't understand what is %s in your project as I am new to this field and I am seeing it a lot in your code. As I searched through the files I am not ables see it as a variable or anything. If you can please tell me how does it work or anything.

Maseshi commented 1 year ago

%s is a replacement for some value. In fact, it can represent anything other than %s such as %n, %number or %cat. Any value other than %s must replace itself, for example:

// Javascript
const name = "John";
const text = "Hello, my name is %name";

text.replace("%name", name);
console.log(text);
// -> Hello, my name is John

Using %s made it easier for me to translate, and using %s I was inspired by a Minecraft project. https://github.com/Mojang/bedrock-samples/blob/60083d4b1d4a62bc88f71636a23992b750d659d1/resource_pack/texts/en_US.lang#L14

Maseshi commented 1 year ago

If you are still confused, you can compare between these two files of mine. https://github.com/Maseshi/Shioru/blob/9c4093482d52a8002fc45d6ca8f52873789583c8/source/commands/developer/ping.js#L33-L35 https://github.com/Maseshi/Shioru/blob/9c4093482d52a8002fc45d6ca8f52873789583c8/source/languages/en-US.json#L392

IFlox commented 1 year ago

Alright 👍, now I understand it. Thanks for the help.