fixes
This commit is contained in:
parent
af8be8643c
commit
1f07664660
|
@ -18,16 +18,42 @@ public class YnTransformer extends CachingTransformer {
|
|||
|
||||
@Override
|
||||
public String getTransformed(String str) {
|
||||
ModInit.Log("Transforming: " + str);
|
||||
Language startLang = api.detectionApi().detect(str).get();
|
||||
String currentState = str;
|
||||
Language currentLang = startLang;
|
||||
for (int i = 0; i < rounds; i++) {
|
||||
Language newLang = selectRandom();
|
||||
currentState = api.translationApi().translate(currentState, Direction.of(breakFully ? selectRandom() : currentLang, newLang)).text();
|
||||
currentLang = newLang;
|
||||
if (str.contains("%")) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String s : str.split("%")) {
|
||||
if (!f) {
|
||||
res.append(s.charAt(0)).append(Break(s.substring(1)).replace("%", ""));
|
||||
} else
|
||||
res.append(Break(s));
|
||||
f = false;
|
||||
}
|
||||
return res.toString();
|
||||
} else {
|
||||
return Break(str);
|
||||
}
|
||||
}
|
||||
|
||||
private String Break(String str) {
|
||||
try {
|
||||
if (str.replace(" ", "").replace("[", "").replace("]", "").length() < 2)
|
||||
return str;
|
||||
Language startLang = api.detectionApi().detect(str).get();
|
||||
String currentState = str;
|
||||
Language currentLang = startLang;
|
||||
for (int i = 0; i < rounds; i++) {
|
||||
Language newLang = selectRandom();
|
||||
currentState = api.translationApi().translate(currentState, Direction.of(breakFully ? selectRandom() : currentLang, newLang)).text();
|
||||
currentLang = newLang;
|
||||
}
|
||||
currentState = api.translationApi().translate(currentState, startLang).text();
|
||||
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
return currentState;
|
||||
} catch (Exception e) {
|
||||
ModInit.Warn("Failed to break: " + str + " (" + str.length() + " characters)");
|
||||
ModInit.Warn("Please report this bug with the mod containing the lang file");
|
||||
throw e;
|
||||
}
|
||||
return api.translationApi().translate(currentState, startLang).text();
|
||||
}
|
||||
|
||||
private Language selectRandom() {
|
||||
|
|
Loading…
Reference in New Issue