#Translation Keys and $s

1 messages · Page 1 of 1 (latest)

onyx rover
#

Is anyone familiar with translation keys and can tell me why some indexed substitutions contain $s after them and some don't? For example with these two strings:

immersive_reader.book_page_header=Page %1 of %2
book.pageIndicator=Page %1$s of %2$s

They don't seem to have any functional difference when tested in-game. Are they synonymous?

#

To add to this, some lines use $d instead of $s, adding more to the confusion.

ruby aurora
#

Depending on what they implemented, you can likely do more formatting stuff, like forcing text into scientific notation, setting number of trailing decimals, etc.

#

My guesss is this:

#

Page %1 of %2 --> Page 1 of 2
Page %1$s of %2$s --> Page one of two (?)

#

's' would be string, 'f' would be float 'd' would be int

onyx rover
#

Whoa, that would be pretty neat if so, I should test that out

onyx rover
#

I tried out various combinations of $d and $s with string and number inputs, and between direct /tellraw translations and also in-game examples (opening a book to read book.pageIndicator) and saw no notable differences in the output

#

I wonder if it is some optimization kind of thing, or the effects of it cannot be seen in English

foggy parrot
#

I'm trying to wrap my head around how this string substitution actually works. In a command block I have this command:
tellraw @a {"rawtext":[{"translate":"test.one","with":["1","2","3"]}]}, with strings in numerical order.
Now I change the translation key with the structure test.one=Hello A, B, and C and also D. These are the outputs when I edit A, B, C, & D:
%0 %1 %s %s = 2 3 1 2
%1 %2 %s %s = 3 _ 1 2
%2 %3 %s %s = _ _ 1 2
%s %1 %s %s = 1 _ 2 3
%s %s %1 $s = 1 2 _ 3
%s %s %s %1 = 1 2 3 _ This is when you want to add new variables
%1 %2 %3 %s = 2 3 _ 1
%0 %1 %2 %s = 1 2 3 1 This is when you want to loop back to the beginning.
%0 %1 %2 %3 = _ 1 2 3 But alas, %0 doesn't work if the highest number ≥ array length.
%1 %2 %3 %4 = 1 2 3 _ This makes a little more sense, I guess. The pattern continues with higher numbers; 4-7 would leave everything blank.
%s %s %s %s = 1 2 3 _ Same result as above.
%s %s %s %0 = 1 2 3 3 Huh? It's not null & it doesn't loop back, but it does repeat the last element? What's going on?

So what I can gather is that %# and %s don't play nicely together. When they do, it's only when using numbers 0-(n-1) & using %s for looping back. Using %s for unaccounted variables does not work when you already used numbers. Using %s & then using numbers to add more works fine so long as you don't use 0.

If you know how many variables to expect & order matters, I'd recommend only using numbers. If you just need to plug in things in a list, I'd recommend only using %s. In my limited testing, $s did absolutely nothing.

ruby aurora
#

Wow nice job. This could make a nice wiki article, if you're able to gather more concrete information.