Unverified Commit fe80290b authored by ZanyRain's avatar ZanyRain Committed by GitHub
Browse files

Output the handbook based off the client language (#1993)

parent 92fbaa86
...@@ -18,6 +18,8 @@ import java.io.IOException; ...@@ -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,14 +35,26 @@ final class HandbookRequestHandler implements DocumentationHandler { ...@@ -33,14 +35,26 @@ 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 {
if (langIdx <= this.handbookHtmls.size() - 1) {
ctx.contentType(ContentType.TEXT_HTML); ctx.contentType(ContentType.TEXT_HTML);
ctx.result(this.handbookHtmls.get(langIdx)); ctx.result(this.handbookHtmls.get(langIdx));
} }
} }
}
private List<String> generateHandbookHtmls(String template) { private List<String> generateHandbookHtmls(String template) {
final int NUM_LANGUAGES = Language.TextStrings.NUM_LANGUAGES; final int NUM_LANGUAGES = Language.TextStrings.NUM_LANGUAGES;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment