mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 16:14:26 +08:00
Locale patches by Karlatemp (#1468)
* Fix links getting translated. * Updated translation of CN locale * Fix translation of `Plan Wiki, Tutorials & Documentation` not working * Update contributors * Nothing wrong? Affects issues: - Fixed #1463
This commit is contained in:
parent
2eb99166ac
commit
f6e6cfcb98
@ -62,7 +62,8 @@ public class Contributors {
|
||||
new Contributor("TDJisvan", LANG),
|
||||
new Contributor("Vankka", CODE),
|
||||
new Contributor("yukieji", LANG),
|
||||
new Contributor("qsefthuopq", LANG)
|
||||
new Contributor("qsefthuopq", LANG),
|
||||
new Contributor("Karlatemp", CODE, LANG)
|
||||
};
|
||||
int estimatedLength = contributors.length * 40 + 50;
|
||||
StringBuilder html = new StringBuilder(estimatedLength);
|
||||
|
@ -175,7 +175,11 @@ public class ResponseFactory {
|
||||
try {
|
||||
String content = UnaryChain.of(getResource(fileName).asString())
|
||||
.chain(theme::replaceThemeColors)
|
||||
.chain(locale::replaceLanguageInJavascript)
|
||||
.chain(resource -> {
|
||||
if (fileName.startsWith("vendor/") || fileName.startsWith("/vendor/"))
|
||||
return resource;
|
||||
return locale.replaceLanguageInJavascript(resource);
|
||||
})
|
||||
.apply();
|
||||
return Response.builder()
|
||||
.setMimeType(MimeType.JS)
|
||||
|
@ -18,6 +18,11 @@ package com.djrapitops.plan.settings.locale;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Utility for translating String.
|
||||
* <p>
|
||||
@ -27,23 +32,100 @@ import org.apache.commons.lang3.StringUtils;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class TranslatedString {
|
||||
private static final Pattern LINK_MATCHER = Pattern.compile("http(s|)://[\\w.\\-_%/?$#@!()&=]+");
|
||||
|
||||
private String translating;
|
||||
private final List<TranslatedString> translating = new LinkedList<>();
|
||||
|
||||
TranslatedString(String translating) {
|
||||
this.translating = translating;
|
||||
final Matcher matcher = LINK_MATCHER.matcher(translating);
|
||||
int start = 0;
|
||||
while (matcher.find()) {
|
||||
String link = translating.substring(matcher.start(), matcher.end());
|
||||
String prev = translating.substring(start, matcher.start());
|
||||
if (!prev.isEmpty()) {
|
||||
this.translating.add(new Translatable(prev));
|
||||
}
|
||||
start = matcher.end();
|
||||
this.translating.add(new LockedString(link));
|
||||
}
|
||||
String remaining = translating.substring(start);
|
||||
if (!remaining.isEmpty()) {
|
||||
this.translating.add(new Translatable(remaining));
|
||||
}
|
||||
}
|
||||
|
||||
TranslatedString() {
|
||||
}
|
||||
|
||||
public void translate(String replace, String with) {
|
||||
translating = StringUtils.replace(translating, replace, with);
|
||||
for (TranslatedString sub : translating) {
|
||||
sub.translate(replace, with);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return translating;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
toString(builder);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void toString(StringBuilder builder) {
|
||||
for (TranslatedString sub : translating) {
|
||||
sub.toString(builder);
|
||||
}
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return translating.length();
|
||||
int length = 0;
|
||||
for (TranslatedString sub : translating) {
|
||||
length += sub.length();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
static class Translatable extends TranslatedString {
|
||||
|
||||
private String translating;
|
||||
|
||||
Translatable(String translating) {
|
||||
this.translating = translating;
|
||||
}
|
||||
|
||||
public void translate(String replace, String with) {
|
||||
translating = StringUtils.replace(translating, replace, with);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toString(StringBuilder builder) {
|
||||
builder.append(translating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return translating.length();
|
||||
}
|
||||
}
|
||||
|
||||
static class LockedString extends TranslatedString {
|
||||
final String text;
|
||||
|
||||
LockedString(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(String replace, String with) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toString(StringBuilder builder) {
|
||||
builder.append(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return text.length();
|
||||
}
|
||||
}
|
||||
}
|
@ -213,7 +213,7 @@ HTML - SIDE_SERVERS_TITLE || 服务器
|
||||
HTML - SIDE_SESSIONS || 时域
|
||||
HTML - SIDE_TO_MAIN_PAGE || 到主页面
|
||||
HTML - TEXT_CLICK_TO_EXPAND || 点击拓展
|
||||
HTML - TEXT_CONTRIBUTORS_CODE || 码农
|
||||
HTML - TEXT_CONTRIBUTORS_CODE || 开发者
|
||||
HTML - TEXT_CONTRIBUTORS_LOCALE || 译者
|
||||
HTML - TEXT_CONTRIBUTORS_MONEY || 特别感谢那些在经济上支持该插件发展的人.
|
||||
HTML - TEXT_CONTRIBUTORS_THANKS || 另外以下 <span class="col-plan">awesome people</span> 也为该插件作出了贡献:
|
||||
|
@ -179,9 +179,7 @@
|
||||
v3.0</a></p>
|
||||
<hr>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan
|
||||
Wiki,
|
||||
Tutorials & Documentation</a>
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki, Tutorials & Documentation</a>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-bug"></i> Report Issues</a>
|
||||
<a class="btn col-plan" href="https://discord.gg/yXKmjzT" rel="noopener noreferrer"
|
||||
|
@ -732,8 +732,7 @@
|
||||
v3.0</a></p>
|
||||
<hr>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki,
|
||||
Tutorials & Documentation</a>
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki, Tutorials & Documentation</a>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-bug"></i> Report Issues</a>
|
||||
<a class="btn col-plan" href="https://discord.gg/yXKmjzT" rel="noopener noreferrer"
|
||||
|
@ -639,9 +639,7 @@
|
||||
v3.0</a></p>
|
||||
<hr>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan
|
||||
Wiki,
|
||||
Tutorials & Documentation</a>
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki, Tutorials & Documentation</a>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-bug"></i> Report Issues</a>
|
||||
<a class="btn col-plan" href="https://discord.gg/yXKmjzT" rel="noopener noreferrer"
|
||||
|
@ -189,9 +189,7 @@
|
||||
v3.0</a></p>
|
||||
<hr>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan
|
||||
Wiki,
|
||||
Tutorials & Documentation</a>
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki, Tutorials & Documentation</a>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-bug"></i> Report Issues</a>
|
||||
<a class="btn col-plan" href="https://discord.gg/yXKmjzT" rel="noopener noreferrer"
|
||||
|
@ -1204,9 +1204,7 @@
|
||||
v3.0</a></p>
|
||||
<hr>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan
|
||||
Wiki,
|
||||
Tutorials & Documentation</a>
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-graduation-cap"></i> Plan Wiki, Tutorials & Documentation</a>
|
||||
<a class="btn col-plan" href="https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"
|
||||
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-bug"></i> Report Issues</a>
|
||||
<a class="btn col-plan" href="https://discord.gg/yXKmjzT" rel="noopener noreferrer"
|
||||
|
Loading…
Reference in New Issue
Block a user