Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
translation, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Nov 15, 2022
1 parent aba94ce commit 4785f85
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.katsute</groupId>
<artifactId>mta-information-site</artifactId>
<version>2.15.0</version>
<version>2.17.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
6 changes: 3 additions & 3 deletions site/live.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<b>Developer Tools:</b>

[<a href="/">Home</a>]
[<a href="?type=bus&route=M1&direction=1">M1 Bus</a>]
[<a href="?type=subway&route=6&direction=1">6 Subway</a>]

[<a href="?type=bus&route=M1&direction=1">M1 Bus</a> | <a href="?type=bus&route=M1&direction=1&lang=ja">translated</a>]
[<a href="?type=subway&route=6&direction=1">6 Subway</a> | <a href="?type=subway&route=6&direction=1&lang=ja">translated</a>]
|
<i>Open developer tools for more information</i>

<hr>
Expand Down
6 changes: 5 additions & 1 deletion site/mta.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const getLocation = async () => new Promise((res, rej) => {
* @param {*} dir direction 0 | 1
* @param {*} lat latitude
* @param {*} lon longitude
* @param {*} lang ISO 2-letter language code
* @returns bus
*/
const getBusByCoord = async (route, dir, lat, lon, lang) => {
Expand All @@ -72,6 +73,7 @@ const getBusByCoord = async (route, dir, lat, lon, lang) => {

/**
* @param {*} id vehicle id
* @param {*} lang ISO 2-letter language code
* @returns bus
*/
const getBusByID = async (id, lang) => {
Expand All @@ -84,9 +86,10 @@ const getBusByID = async (id, lang) => {

/**
* @param {*} route route code
* @param {*} dir direction 0 | 1
* @param {*} dir direction 1 | 3
* @param {*} lat latitude
* @param {*} lon longitude
* @param {*} lang ISO 2-letter language code
* @returns bus
*/
const getSubwayByCoord = async (route, dir, lat, lon, lang) => {
Expand All @@ -102,6 +105,7 @@ const getSubwayByCoord = async (route, dir, lat, lon, lang) => {

/**
* @param {*} id vehicle id
* @param {*} lang ISO 2-letter language code
* @returns bus
*/
const getSubwayByID = async (id, lang) => {
Expand Down
2 changes: 2 additions & 0 deletions site/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ const generate = (data) => {

content += `<b>${data.route.shortName}</b> ${data.route.name}`;

content += `<pre>${JSON.stringify(data, null, 2)}</pre>`;

main.innerHTML = content; // write content onto the page
}
26 changes: 16 additions & 10 deletions src/main/java/dev/katsute/mis/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ public final void handle(final SimpleHttpExchange exchange){
final String desc = alert.getDescription();
a.add(new JsonBuilder()
.set("header", alert.getHeader())
.set("header_translated", translate(alert.getHeader().trim(), "en", lang))
.set("description", alert.getDescription().trim())
.set("translated", translate(alert.getDescription().trim(), "en", lang))
.set("description_translated", translate(alert.getDescription().trim(), "en", lang))
.set("type", alert.getAlertType())
.set("effect", alert.getEffect())
.set("slow", desc.contains("slow") || desc.contains("delay"))
Expand Down Expand Up @@ -203,8 +204,9 @@ public final void handle(final SimpleHttpExchange exchange){
final String desc = alert.getDescription();
a.add(new JsonBuilder()
.set("header", alert.getHeader())
.set("header_translated", translate(alert.getHeader().trim(), "en", lang))
.set("description", alert.getDescription().trim())
.set("translated", translate(alert.getDescription().trim(), "en", lang))
.set("description_translated", translate(alert.getDescription().trim(), "en", lang))
.set("type", alert.getAlertType())
.set("effect", alert.getEffect())
.set("slow", desc.contains("slow") || desc.contains("delay"))
Expand Down Expand Up @@ -296,8 +298,9 @@ public final void handle(final SimpleHttpExchange exchange){
final String desc = alert.getDescription().toLowerCase();
a.add(new JsonBuilder()
.set("header", alert.getHeader())
.set("header_translated", translate(alert.getHeader().trim(), "en", lang))
.set("description", alert.getDescription().trim())
.set("translated", translate(alert.getDescription().trim(), "en", lang))
.set("description_translated", translate(alert.getDescription().trim(), "en", lang))
.set("type", alert.getAlertType())
.set("effect", alert.getEffect())
.set("slow", desc.contains("slow") || desc.contains("delay"))
Expand Down Expand Up @@ -333,8 +336,9 @@ public final void handle(final SimpleHttpExchange exchange){
final String desc = alert.getDescription().toLowerCase();
a.add(new JsonBuilder()
.set("header", alert.getHeader())
.set("header_translated", translate(alert.getHeader().trim(), "en", lang))
.set("description", alert.getDescription().trim())
.set("translated", translate(alert.getDescription().trim(), "en", lang))
.set("description_translated", translate(alert.getDescription().trim(), "en", lang))
.set("type", alert.getAlertType())
.set("effect", alert.getEffect())
.set("slow", desc.contains("slow") || desc.contains("delay"))
Expand Down Expand Up @@ -409,11 +413,11 @@ private static String translate(final String q, final String from, final String

final Map<String,String> query = new HashMap<String,String>(){{
put("client", "at");
put("dt", "t"); // sentences
put("dt", "t"); // translation
put("dj", "1"); // as json
put("sl", from);
put("tl", to);
put("q", q);
put("sl", from); // source
put("tl", to); // target
put("q", q.replace("@", "at")); // query
}};

HttpURLConnection conn = null;
Expand Down Expand Up @@ -447,8 +451,10 @@ private static String translate(final String q, final String from, final String

final Matcher m = trans.matcher(OUT.toString());

if(m.find())
return m.group();
String str = "";
while(m.find())
str += m.group() + " ";
return str.trim();
}
}catch(final IOException e){
e.printStackTrace();
Expand Down

0 comments on commit 4785f85

Please sign in to comment.