#Automatic `.lang` file Generator for any TypeScript Repository.

1 messages · Page 1 of 1 (latest)

worthy tinsel
#

Hey everyone, I created this script today after realizing that people wanted to translate my addon into other languages. The problem was that all my functions use .sendMessage to communicate with the player. However to make it so people could translate it I need to convert it to a lang file system inside a resource pack.

So at first I was translating it manually typing in each translate object and adding it to the resource pack, but because of the sheer size of my addon it just was going to take too long. So I decided to build a interrupter that would interpret template literals and pass it into the with parameter inside the function.

For example, lets say you have a function here:

world.sendMessage("Hey everyone in Bedrock Scripting API")

It will convert this message to

world.sendMessage({ translate: "some.unique.key" });

Additionally If you have a template string you can automatically interpret the expressions inside.
For example:

world.sendMessage(`The current day: ${world.getDay()}`);

Will convert too

world.sendMessage({
  translate: "some.unique.key"
  with: [world.getDay().toString()]
});```

The code automatically detects the return type of the value, and will append a `.toString()` function to the end, if its a number. Additionally, If the value is not of type `string | number` a warning will be displayed alerting manual transformation, because that value cannot be converted automatically.

Check out the code and let me know what you think!
true verge
#

you should make a Regolith filter out of this 👀

stone garden
#

That's cool..