mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-05-08 04:55:52 +08:00
Output the handbook based off the client language (#1993)
This commit is contained in:
parent
92fbaa8670
commit
fe80290bed
@ -18,6 +18,8 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
final class HandbookRequestHandler implements DocumentationHandler {
|
final class HandbookRequestHandler implements DocumentationHandler {
|
||||||
private List<String> handbookHtmls;
|
private List<String> handbookHtmls;
|
||||||
@ -33,12 +35,24 @@ final class HandbookRequestHandler implements DocumentationHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Context ctx) {
|
public void handle(Context ctx) {
|
||||||
final int langIdx = Language.TextStrings.MAP_LANGUAGES.getOrDefault(DOCUMENT_LANGUAGE, 0); // TODO: This should really be based off the client language somehow
|
int langIdx = 0;
|
||||||
|
String acceptLanguage = ctx.header("Accept-Language");
|
||||||
|
if (acceptLanguage != null) {
|
||||||
|
Pattern localePattern = Pattern.compile("[a-z]+-[A-Z]+");
|
||||||
|
Matcher matcher = localePattern.matcher(acceptLanguage);
|
||||||
|
if (matcher.find()) {
|
||||||
|
String lang = matcher.group(0);
|
||||||
|
langIdx = Language.TextStrings.MAP_GC_LANGUAGES.getOrDefault(lang,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.handbookHtmls == null) {
|
if (this.handbookHtmls == null) {
|
||||||
ctx.status(500);
|
ctx.status(500);
|
||||||
} else {
|
} else {
|
||||||
ctx.contentType(ContentType.TEXT_HTML);
|
if (langIdx <= this.handbookHtmls.size() - 1) {
|
||||||
ctx.result(this.handbookHtmls.get(langIdx));
|
ctx.contentType(ContentType.TEXT_HTML);
|
||||||
|
ctx.result(this.handbookHtmls.get(langIdx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user