Carpet

Carpet

2M Downloads

Scarpet suggestion: Ability to use localized text in `format`ted strings

James103 opened this issue ยท 2 comments

commented

Currently, in order to use localized text anywhere from within Scarpet, you would need to use a command to set the text. For example, if you wanted to print "Shears" in English and "Tijeras" in Spanish, you would need to run the following command, even if it is done from within Scarpet:
tellraw @s {"translate":"item.minecraft.shears"}

In order to avoid having to run commands every tick while still allowing for per-player localized text, a new component type would need to be introduced into the format function:

  • j: Translate (the following word including periods is treated as a string ID for which to turn into localized text).

This would now allow you to run something like script run print('j item.minecraft.shears') to do the same as above.

commented

What about translation with arguments?
script run print(format('j multiplayer.player.joined Herobrine')) would be a nice solution, but what happens if the arg has a space?

commented

If player want to use the localization system to its full potential, a new function may be required and it would be called translate:

translate(format, id, ...args)

Returns a localized FormattedText object. format is the format specifiers to apply on the full string. id is the translation ID of the string to use. ...args can be either strings or FormattedText objects, which get inserted as translation arguments.

For example, translate('b', 'death.attack.mob', format('i A'), 'B') would return a Formatted Text corresponding to
(in English) A was slain by B
(in Spanish) A fue asesinado/a por B

Another example: format(translate('b', 'death.attack.mob', format('i A'), 'B'), 'g \ (x3)') would output:
(in English) A was slain by B (x3)
(in Spanish) A fue asesinado/a por B (x3)
with the "(x3)" in gray.

Note that going the functional route will eliminate the need for using j as a format specifier for localized text.