Skip to content

Commit

Permalink
Added translations
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinRepo committed Mar 17, 2022
1 parent f30ac15 commit fbc61ee
Show file tree
Hide file tree
Showing 128 changed files with 619,014 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChatBot.iml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
Expand Down
5,163 changes: 5,163 additions & 0 deletions resources/translations/af_za.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ar_sa.json

Large diffs are not rendered by default.

4,654 changes: 4,654 additions & 0 deletions resources/translations/ast_es.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/az_az.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ba_ru.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/bar.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/be_by.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/bg_bg.json

Large diffs are not rendered by default.

4,142 changes: 4,142 additions & 0 deletions resources/translations/br_fr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/brb.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/bs_ba.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ca_es.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/cs_cz.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/cy_gb.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/da_dk.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/de_at.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/de_ch.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/de_de.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/el_gr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_au.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_ca.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_gb.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_nz.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_pt.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/en_ud.json

Large diffs are not rendered by default.

5,165 changes: 5,165 additions & 0 deletions resources/translations/en_us.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/enp.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/enws.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/eo_uy.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_ar.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_cl.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_ec.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_es.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_mx.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_uy.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/es_ve.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/esan.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/et_ee.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/eu_es.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fa_ir.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fi_fi.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fil_ph.json

Large diffs are not rendered by default.

4,681 changes: 4,681 additions & 0 deletions resources/translations/fo_fo.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fr_ca.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fr_fr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fra_de.json

Large diffs are not rendered by default.

4,933 changes: 4,933 additions & 0 deletions resources/translations/fur_it.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/fy_nl.json

Large diffs are not rendered by default.

5,158 changes: 5,158 additions & 0 deletions resources/translations/ga_ie.json

Large diffs are not rendered by default.

5,126 changes: 5,126 additions & 0 deletions resources/translations/gd_gb.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/gl_es.json

Large diffs are not rendered by default.

4,080 changes: 4,080 additions & 0 deletions resources/translations/haw_us.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/he_il.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/hi_in.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/hr_hr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/hu_hu.json

Large diffs are not rendered by default.

5,164 changes: 5,164 additions & 0 deletions resources/translations/hy_am.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/id_id.json

Large diffs are not rendered by default.

4,560 changes: 4,560 additions & 0 deletions resources/translations/ig_ng.json

Large diffs are not rendered by default.

4,429 changes: 4,429 additions & 0 deletions resources/translations/io_en.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/is_is.json

Large diffs are not rendered by default.

5,160 changes: 5,160 additions & 0 deletions resources/translations/isv.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/it_it.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ja_jp.json

Large diffs are not rendered by default.

3,524 changes: 3,524 additions & 0 deletions resources/translations/jbo_en.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ka_ge.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/kk_kz.json

Large diffs are not rendered by default.

5,121 changes: 5,121 additions & 0 deletions resources/translations/kn_in.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ko_kr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ksh.json

Large diffs are not rendered by default.

5,141 changes: 5,141 additions & 0 deletions resources/translations/kw_gb.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/la_la.json

Large diffs are not rendered by default.

5,154 changes: 5,154 additions & 0 deletions resources/translations/lb_lu.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/li_li.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/lmo.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/lol_us.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/lt_lt.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/lv_lv.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/lzh.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/mk_mk.json

Large diffs are not rendered by default.

5,099 changes: 5,099 additions & 0 deletions resources/translations/mn_mn.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ms_my.json

Large diffs are not rendered by default.

5,095 changes: 5,095 additions & 0 deletions resources/translations/mt_mt.json

Large diffs are not rendered by default.

5,160 changes: 5,160 additions & 0 deletions resources/translations/nds_de.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/nl_be.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/nl_nl.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/nn_no.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/no_no.json

Large diffs are not rendered by default.

4,212 changes: 4,212 additions & 0 deletions resources/translations/oc_fr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ovd.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/pl_pl.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/pt_br.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/pt_pt.json

Large diffs are not rendered by default.

3,593 changes: 3,593 additions & 0 deletions resources/translations/qya_aa.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ro_ro.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/rpr.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ru_ru.json

Large diffs are not rendered by default.

5,151 changes: 5,151 additions & 0 deletions resources/translations/se_no.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/sk_sk.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/sl_si.json

Large diffs are not rendered by default.

3,860 changes: 3,860 additions & 0 deletions resources/translations/so_so.json

Large diffs are not rendered by default.

5,159 changes: 5,159 additions & 0 deletions resources/translations/sq_al.json

Large diffs are not rendered by default.

5,162 changes: 5,162 additions & 0 deletions resources/translations/sr_sp.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/sv_se.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/sxu.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/szl.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/ta_in.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/th_th.json

Large diffs are not rendered by default.

5,157 changes: 5,157 additions & 0 deletions resources/translations/tl_ph.json

Large diffs are not rendered by default.

4,612 changes: 4,612 additions & 0 deletions resources/translations/tlh_aa.json

Large diffs are not rendered by default.

5,161 changes: 5,161 additions & 0 deletions resources/translations/tok.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/tr_tr.json

Large diffs are not rendered by default.

5,129 changes: 5,129 additions & 0 deletions resources/translations/tt_ru.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/uk_ua.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/val_es.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/vec_it.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/vi_vn.json

Large diffs are not rendered by default.

5,157 changes: 5,157 additions & 0 deletions resources/translations/yi_de.json

Large diffs are not rendered by default.

5,147 changes: 5,147 additions & 0 deletions resources/translations/yo_ng.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/zh_cn.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/zh_hk.json

Large diffs are not rendered by default.

5,163 changes: 5,163 additions & 0 deletions resources/translations/zh_tw.json

Large diffs are not rendered by default.

93 changes: 84 additions & 9 deletions src/me/dustin/chatbot/chat/ChatMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.util.StringJoiner;

public class ChatMessage {

public String senderName;
public String body;
private String senderName;
private String body;
private boolean isChat;

public ChatMessage(String senderName, String body) {
this.senderName = senderName;
Expand All @@ -34,24 +36,57 @@ public String getBody() {
return body;
}

public boolean isChat() {
return isChat;
}

public void setChat(boolean chat) {
isChat = chat;
}

public static ChatMessage of(String jsonData) {
if (jsonData.isEmpty())
return new ChatMessage("", "");
StringBuilder name = new StringBuilder();
StringBuilder body = new StringBuilder();
StringJoiner insertion = new StringJoiner(",");
boolean isChat = false;
JsonObject jsonObject = GeneralHelper.gson.fromJson(jsonData, JsonObject.class);
JsonArray with = jsonObject.getAsJsonArray("with");
String translate = "";
if (jsonObject.get("translate") != null) {
translate = jsonObject.get("translate").getAsString();
if (translate.equalsIgnoreCase("chat.type.text"))
isChat = true;
}

if (with != null) {
for (int i = 0; i < with.size(); i++) {
try {
JsonObject object = with.get(i).getAsJsonObject();

if (object.get("with") != null) {
JsonArray with2 = object.getAsJsonArray("with");
for (int ii = 0; ii < with2.size(); ii++) {
JsonObject o = with2.get(ii).getAsJsonObject();
if (o.get("insertion") != null && !insertion.toString().contains(o.get("insertion").getAsString())) {
insertion.add(o.get("insertion").getAsString());
}
}
}
if (object.get("insertion") != null && insertion.toString().isEmpty()) {
String s = object.get("insertion").getAsString();
insertion.add(s);
}
if (object.get("color") != null) {
TextColors textColors = TextColors.getFromName(object.get("color").getAsString());
if (textColors != null)
name.append("§").append(textColors.getChar());
}
String text = object.get("text").getAsString();
name.append(text);
if ((isChat || name.isEmpty()) && !Translator.translate(translate).startsWith("%1$s")) {
name.append(text);
}
} catch (Exception e) {
try {
body.append(" ").append(with.get(i).getAsString());
Expand All @@ -60,23 +95,49 @@ public static ChatMessage of(String jsonData) {
}
}
if (jsonObject.get("translate") != null) {
String translate = jsonObject.get("translate").getAsString();
if (!translate.equalsIgnoreCase("chat.type.text"))
body.append(" ").append(translate);
if (jsonObject.get("color") != null) {
TextColors textColors = TextColors.getFromName(jsonObject.get("color").getAsString());
if (textColors != null)
body.append("§").append(textColors.getChar());
}
if (!translate.equalsIgnoreCase("chat.type.text")) {
System.out.println(insertion);
String translated = Translator.translate(translate);
if (!insertion.toString().isEmpty()) {
String[] insertions = insertion.toString().split(",");
int c = 0;
for (int i = 0; i < insertions.length; i++) {
if (translated.contains("%" + (i + 1) + "$s")) {
translated = translated.replace("%" + (i + 1) + "$s", insertions[i]);
c++;
} else
break;
}
for (int i = c; i < insertions.length; i++) {
System.out.println("replacing " + i + " with " + insertions[i]);
translated = translated.replaceFirst("%s", insertions[i]);
}
}
//translated = translated.replace("%s", insertions[insertions.length - 1]);
body.append(" ").append(translated);
}
}
body.append(getExtra(jsonObject));
if (body.toString().startsWith("<") && body.toString().contains("> ") && name.toString().isEmpty()) {//crude way to move player name to actual name field if the text is set up weird
if (isChat && body.toString().startsWith("<") && body.toString().contains("> ") && name.toString().isEmpty()) {//crude way to move player name to actual name field if the text is set up weird
String s = body.toString().split("<")[1].split(">")[0];
name.append(s);
body = new StringBuilder(body.toString().replace("<" + s + "> ", ""));
}

if (body.toString().startsWith(" ")) {
body = new StringBuilder(body.substring(1));
}
if (jsonObject.get("text") != null) {
body.append(jsonObject.get("text").getAsString());
}
return new ChatMessage(name.toString(), body.toString());
ChatMessage chatMessage = new ChatMessage(name.toString(), body.toString());
chatMessage.setChat(isChat);
return chatMessage;
}

private static String getExtra(JsonObject jsonObject) {
Expand All @@ -97,7 +158,21 @@ private static String getExtra(JsonObject jsonObject) {
if (object.get("extra") != null)
s.append(getExtra(object));
} catch (Exception e) {
s.append(" ").append(extra.get(i).getAsString());
try {
s.append(" ").append(extra.get(i).getAsString());
} catch (Exception e1) {
JsonObject o = extra.get(i).getAsJsonObject();
if (o.get("color") != null) {
TextColors textColors = TextColors.getFromName(o.get("color").getAsString());
if (textColors != null)
s.append("§").append(textColors.getChar());
}
if (o.get("translate") != null) {
String translate = o.get("translate").getAsString();
if (!translate.equalsIgnoreCase("chat.type.text"))
s.append(" ").append(Translator.translate(translate));
}
}
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/me/dustin/chatbot/chat/Translator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package me.dustin.chatbot.chat;

import com.google.gson.JsonObject;
import me.dustin.chatbot.helper.GeneralHelper;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Translator {

private static JsonObject translations;

public static void setTranslation(String translation) {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream("translations/" + translation + ".json");
InputStreamReader streamReader = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(streamReader);
StringBuilder sb = new StringBuilder();
for (String line; (line = reader.readLine()) != null;) {
sb.append(line);
}
is.close();
reader.close();
translations = GeneralHelper.gson.fromJson(sb.toString(), JsonObject.class);
} catch (Exception e) {
e.printStackTrace();
GeneralHelper.print("Error grabbing translation file: " + translation + ".json", ChatMessage.TextColors.DARK_RED);
}
}

public static String translate(String s) {
if (translations.get(s) == null)
return s;
return translations.get(s).getAsString();
}

}
1 change: 1 addition & 0 deletions src/me/dustin/chatbot/command/impl/CommandReload.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void run(String str, UUID sender) {
getClientConnection().sendPacket(new ServerBoundClientSettingsPacket(ChatBot.getConfig().getLocale(), ChatBot.getConfig().isAllowServerListing(), ServerBoundClientSettingsPacket.SkinPart.all()));
try {
ChatBot.getConfig().loadConfig();
getClientConnection().updateTranslations();
sendChat("Reloaded commands and config!");
} catch (Exception e) {
sendChat("Error in config! " + e.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/me/dustin/chatbot/helper/GeneralHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void print(String s, ChatMessage.TextColors color) {
}

public static void printChat(ChatMessage chatMessage) {
if (!chatMessage.getSenderName().isEmpty())
if (!chatMessage.getSenderName().isEmpty() && chatMessage.isChat())
chatMessage = new ChatMessage("<" + chatMessage.getSenderName() + (chatMessage.getSenderName().contains("§") ? "§f" : "") +">", chatMessage.getBody());
String m = chatMessage.getMessage();
if (!m.contains("§") || !ChatBot.getConfig().isColorConsole()) {
Expand Down
8 changes: 8 additions & 0 deletions src/me/dustin/chatbot/network/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import me.dustin.chatbot.ChatBot;
import me.dustin.chatbot.account.Session;
import me.dustin.chatbot.chat.ChatMessage;
import me.dustin.chatbot.chat.Translator;
import me.dustin.chatbot.command.CommandManager;
import me.dustin.chatbot.config.Config;
import me.dustin.chatbot.event.EventLoginSuccess;
import me.dustin.chatbot.helper.GeneralHelper;
import me.dustin.chatbot.helper.TPSHelper;
Expand Down Expand Up @@ -85,6 +87,8 @@ public ClientConnection(String ip, int port, Session session) throws IOException
this.tpsHelper = new TPSHelper();
this.playerManager = new PlayerManager();
this.eventManager = new EventManager();

updateTranslations();
getEventManager().register(this);
getEventManager().register(ChatBot.getGui());
}
Expand Down Expand Up @@ -166,6 +170,10 @@ public void close() {
}
}

public void updateTranslations() {
Translator.setTranslation(ChatBot.getConfig().getLocale());
}

public void tick() {
getProcessManager().tick();
getClientPlayer().tick();
Expand Down

0 comments on commit fbc61ee

Please sign in to comment.