Create

Create

86M Downloads

Remove mandatory spaces around highlight format in language files

Krantz-XRF opened this issue · 3 comments

commented

In the past few days, I was working on a supplemental translation of all the new stuff v0.3 introduced into Chinese. And I noticed that highlights (represented by surrounding texts with underscores (_)) would only work (rendered correctly in-game) if there is a space both before the first _ and after the last _. That is:

This_A_ will not be highlighted.
This _A_won't, either.
But this _A_ will.

It is quite reasonable for a language such as English, where words are naturally separated by spaces. However, in Chinese, words are usually not separated by spaces, so the only spaces in the text would be these mandatory spaces surrounding highlights. These extra spaces in the texts would look odd for Chinese players already. To make things worse, the line breaking algorithm doesn't really like these spaces, either: instead of filling the line until the right boundary, it always breaks lines at these spaces, see the following screenshot:

image

Note how the highlighting format of "旋转动能" ("rotational energy") on the first line forces a line break.

So here I propose changing the highlighting format to remove the mandatory spaces, and therefore producing a better rendering for players whose language does not use spaces to indicate word boundaries.

P.S. I can submit a PR, if this is acceptable but you don't have time for this change.

commented

I can think of three possible ways to solve this:

  • apply a filter (to remove all spaces) to the message immediately before passing it to the rendering engine
    • this should only be done in several specific locales
    • perhaps add a new boolean value in the translation file to control this behaviour
  • make the highlighting format "consume" a pair of surrounding spaces
    • therefore to add real spaces around the text, one would need to type two spaces instead
  • remove the requirement for those spaces
    • I can hardly imagine where a translation would result in an underscore in any natural language
    • when an underscore is really desired, perhaps write two consecutive underscores to represent one

For the idea of non-breaking space characters, I suspect these kinds of characters are usually hard to type, and even harder to recognize.

commented

This is a great point, the formatting requirements are definitely made with english in mind. That being said, I think some kind of delimiter is important to avoid false positives.

I wonder if the Minecraft font renderer supports non-breaking space characters? If not we could probably find some compromise here, perhaps it would be fine to just not require the spaces or maybe it would be preferable to add an alternate delimiter for this situation.

commented

I am a little confused now. I began to read the source code just now, and I found this:

String markedUp = s.replaceAll("_([^_]+)_", highlightColor + "$1" + defaultColor);

It seems the replaceAll function is directly applied to the source text, so from the regex pattern "_([^_]+)_" it seems that really no space is required during this replacement. Besides, according to a few experiments I just tried out, if no spaces were added before and after those underscores, the underscore itself is NOT preserved; it is just that the highlighting effect is not applied. This makes me wonder whether this requirement of spaces is a limit in Minecraft/Forge, rather than a limitation in Create.

Anyway, even if we eventually found out the requirement for spaces is due to Minecraft/Forge, I would still think the rendering can be improved by modifying the layout function:

for (int i = 0; i < words.length; i++) {
word = words[i];
lastWord = i == words.length - 1;
if (!lastWord && !firstWord && currentLine.length() + word.length() > maxCharsPerLine) {
lines.add(currentLine.toString());
currentLine = new StringBuilder(lineStart);
firstWord = true;
}
currentLine.append((firstWord ? "" : " ") + word);
firstWord = false;
}