Earth2Java [FORGE]

Earth2Java [FORGE]

21.3k Downloads

breakLine method breaks CJK translation wrapping

deluxghost opened this issue · 3 comments

commented

public static List<String> breakLine(String input, int maxLineLength) {
List<String> res = new ArrayList<>();
Pattern pattern = Pattern.compile("\\b.{1," + (maxLineLength - 1) + "}\\b\\W?");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
res.add(matcher.group());
}
return res;
}

This method breaks long item descriptions into short lines with a max of 40 chars per line, which is not working on (at least) CJK translations.

CJK: Chinese/Japanese/Korean (zh_cn, zh_tw, ja_jp, ko_kr)

Let's try zh_tw as an example, here is an item description:

"item.earthtojavamobs.cluckshroom_spawn_egg.desc": "幾年前,一群遠征的探險家發現了一種稀有的怪雞,這種雞的身上長滿了蘑菇,因此命名為咕咕菇。這是一種非常奇怪的雞。但是好不好吃?我們只能等時間來證明了。",

Check it in game:

image

It says:

幾年前,一群遠征的探險家發現了一種稀有的怪雞,這種雞的身上長滿了蘑菇,因
。這是一種非常奇怪的雞。但是好不好吃?我們只能等時間來證明了。

And a piece of text is gone:

幾年前,一群遠征的探險家發現了一種稀有的怪雞,這種雞的身上長滿了蘑菇,因
此命名為咕咕菇      <---------------- THIS
。這是一種非常奇怪的雞。但是好不好吃?我們只能等時間來證明了。
commented

For those languages I can break the description at the end of a sentence instead of a fixed length of characters/words. There could be some very large box, but it is better than a broken description.

image

image

image

commented

IMO, since Korean also uses spaces to separate words, it might be ok to use the same rule as latin languages, but with less max line length.

And for Chinese / Japanese, they don't have any word separator, it's already good to break lines from anywhere in a sentence, with less line length too.

e.g. This is good

幾年前,一群遠征的探險家發現了一種稀有的怪
雞,這種雞的身上長滿了蘑菇,因此命名為咕咕
菇。這是一種非常奇怪的雞。但是好不好吃?我
們只能等時間來證明了。

if you want to make it better, just don't let any line start with punctuation

e.g. This is not so good (second line)

幾年前,一群遠征的探險家發現了一種稀有的怪雞
,這種雞的身上長滿了蘑菇,因此命名為咕咕菇。
這是一種非常奇怪的雞。但是好不好吃?我們只能
等時間來證明了。
commented

another valid workaround is, we don't wrap text ourselves, and let mods like this handle all these mess