From f5caa7b10aaa1ff5152c9099d84fa68e08bc653c Mon Sep 17 00:00:00 2001
From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com>
Date: Wed, 31 Jul 2024 21:11:44 -0400
Subject: [PATCH 1/5] Start work with translations
---
.gitattributes | 2 ++
README.md | 3 +++
providers/translation/get_translate.py | 37 ++++++++++++++++++++++++++
translations/en-GB/translation.json | 3 +++
translations/en-US/translation.json | 3 +++
translations/translation_help.md | 7 +++++
translations/translations_needed.json | 3 +++
7 files changed, 58 insertions(+)
create mode 100644 .gitattributes
create mode 100644 providers/translation/get_translate.py
create mode 100644 translations/en-GB/translation.json
create mode 100644 translations/en-US/translation.json
create mode 100644 translations/translation_help.md
create mode 100644 translations/translations_needed.json
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..eba1110
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
\ No newline at end of file
diff --git a/README.md b/README.md
index 8ee3bb3..5ea8e38 100644
--- a/README.md
+++ b/README.md
@@ -12,3 +12,6 @@ The bot displays:
The API we use is not affiliated with Aternos, Minecraft or any server host. This bot is also not affiliated with Aternos.
You can invite the bot here: https://discord.com/api/oauth2/authorize?client_id=889197952994791434&permissions=274878286848&scope=bot%20applications.commands
+
+# Translation help
+Read [this](/translations/translation_help.md) for how to translate!
\ No newline at end of file
diff --git a/providers/translation/get_translate.py b/providers/translation/get_translate.py
new file mode 100644
index 0000000..c244aff
--- /dev/null
+++ b/providers/translation/get_translate.py
@@ -0,0 +1,37 @@
+from os import walk
+from json import load
+class Translation:
+ def _get_translation_map() -> dict:
+ "You shouldn't have to use this unless your debugging."
+ translation_map = {}
+ for dirname, _, filenames in walk("./translations/"):
+ if dirname == "./translations/": continue
+ filename = filenames[0] # There should be only 1
+ with open (f"{dirname}/{filename}", "r") as f:
+ json_data = load(f)
+ translation_map[dirname.removeprefix("./translations/")] = json_data
+ return translation_map
+ def get_translation(language: str, message_code: str) -> str:
+ translation_map = Translation._get_translation_map()
+ try:
+ return translation_map[language][message_code]
+ except KeyError:
+ try:
+ return translation_map["en-US"][message_code] # Default to US
+ except KeyError:
+ return "No message available for this given message code"
+if __name__ == "__main__":
+ #Just some tests
+ if Translation.get_translation("en-GB", "test") != "British!":
+ print ("Test 1 failed")
+ exit(1)
+ if Translation.get_translation("thislanguage-doesnotexist", "test") != "Works!":
+ print ("Test 2 failed")
+ exit(1)
+ if Translation.get_translation("en-US", "test") != "Works!":
+ print ("Test 3 failed")
+ exit(1)
+ if Translation.get_translation("en-US", "thisdoesnotexist") != "No message available for this given message code":
+ print ("Test 4 failed")
+ exit(1)
+ print ("All tests passed!")
\ No newline at end of file
diff --git a/translations/en-GB/translation.json b/translations/en-GB/translation.json
new file mode 100644
index 0000000..4864bee
--- /dev/null
+++ b/translations/en-GB/translation.json
@@ -0,0 +1,3 @@
+{
+ "test": "British!"
+}
\ No newline at end of file
diff --git a/translations/en-US/translation.json b/translations/en-US/translation.json
new file mode 100644
index 0000000..0d96973
--- /dev/null
+++ b/translations/en-US/translation.json
@@ -0,0 +1,3 @@
+{
+ "test": "Works!"
+}
\ No newline at end of file
diff --git a/translations/translation_help.md b/translations/translation_help.md
new file mode 100644
index 0000000..800a7da
--- /dev/null
+++ b/translations/translation_help.md
@@ -0,0 +1,7 @@
+# Wanna help with translating? Heres the directions to translate!
+
+
PS: If the language isn't in discord's language list, it cannot be added
+
+- You must fork this repo and create a folder in [this folder](/translations/) named the language then the region IF discord offers more then 1 region of the language, like "en-US" vs just "es"
+- You must fill out all translations in the [translations_needed.json](/translations/translations_needed.json) and only change the value, not the key
+- uhhh something else i forgot to add here
\ No newline at end of file
diff --git a/translations/translations_needed.json b/translations/translations_needed.json
new file mode 100644
index 0000000..86de26b
--- /dev/null
+++ b/translations/translations_needed.json
@@ -0,0 +1,3 @@
+{
+ "test": "Something Here, its needed uwu"
+}
\ No newline at end of file
From 6c5f1e9cc11364bfc1e941060d5fbd0925ddbc54 Mon Sep 17 00:00:00 2001
From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com>
Date: Wed, 31 Jul 2024 21:15:30 -0400
Subject: [PATCH 2/5] if pylint doesn't complain about this, ima eat my own
shoe
---
providers/translation/get_translate.py | 29 ++++++++++++++------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/providers/translation/get_translate.py b/providers/translation/get_translate.py
index c244aff..064c9ff 100644
--- a/providers/translation/get_translate.py
+++ b/providers/translation/get_translate.py
@@ -1,17 +1,19 @@
from os import walk
from json import load
+from sys import exit as sysexit
class Translation:
- def _get_translation_map() -> dict:
+ def _get_translation_map(self) -> dict:
"You shouldn't have to use this unless your debugging."
translation_map = {}
for dirname, _, filenames in walk("./translations/"):
- if dirname == "./translations/": continue
+ if dirname == "./translations/":
+ continue
filename = filenames[0] # There should be only 1
- with open (f"{dirname}/{filename}", "r") as f:
+ with open (f"{dirname}/{filename}", "r", encoding="UTF-8") as f:
json_data = load(f)
translation_map[dirname.removeprefix("./translations/")] = json_data
return translation_map
- def get_translation(language: str, message_code: str) -> str:
+ def get_translation(self, language: str, message_code: str) -> str:
translation_map = Translation._get_translation_map()
try:
return translation_map[language][message_code]
@@ -22,16 +24,17 @@ def get_translation(language: str, message_code: str) -> str:
return "No message available for this given message code"
if __name__ == "__main__":
#Just some tests
- if Translation.get_translation("en-GB", "test") != "British!":
+ translation_class = Translation()
+ if translation_class.get_translation("en-GB", "test") != "British!":
print ("Test 1 failed")
- exit(1)
- if Translation.get_translation("thislanguage-doesnotexist", "test") != "Works!":
+ sysexit(1)
+ if translation_class.get_translation("thislanguage-doesnotexist", "test") != "Works!":
print ("Test 2 failed")
- exit(1)
- if Translation.get_translation("en-US", "test") != "Works!":
+ sysexit(1)
+ if translation_class.get_translation("en-US", "test") != "Works!":
print ("Test 3 failed")
- exit(1)
- if Translation.get_translation("en-US", "thisdoesnotexist") != "No message available for this given message code":
+ sysexit(1)
+ if translation_class.get_translation("en-US", "thisdoesnotexist") != "No message available for this given message code":
print ("Test 4 failed")
- exit(1)
- print ("All tests passed!")
\ No newline at end of file
+ sysexit(1)
+ print ("All tests passed!")
From 0d7eaa235826c59f7a537b739e39d9065fdbf62e Mon Sep 17 00:00:00 2001
From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com>
Date: Wed, 31 Jul 2024 21:18:16 -0400
Subject: [PATCH 3/5] there
---
providers/translation/get_translate.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/providers/translation/get_translate.py b/providers/translation/get_translate.py
index 064c9ff..7a0d7e8 100644
--- a/providers/translation/get_translate.py
+++ b/providers/translation/get_translate.py
@@ -14,7 +14,7 @@ def _get_translation_map(self) -> dict:
translation_map[dirname.removeprefix("./translations/")] = json_data
return translation_map
def get_translation(self, language: str, message_code: str) -> str:
- translation_map = Translation._get_translation_map()
+ translation_map = self._get_translation_map()
try:
return translation_map[language][message_code]
except KeyError:
From d40bbc00d07f9a2d242ab1cfdbb6f96942997e49 Mon Sep 17 00:00:00 2001
From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com>
Date: Thu, 8 Aug 2024 20:07:32 -0400
Subject: [PATCH 4/5] ok
---
providers/translation/get_translate.py | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/providers/translation/get_translate.py b/providers/translation/get_translate.py
index 7a0d7e8..658955a 100644
--- a/providers/translation/get_translate.py
+++ b/providers/translation/get_translate.py
@@ -1,6 +1,7 @@
from os import walk
from json import load
from sys import exit as sysexit
+
class Translation:
def _get_translation_map(self) -> dict:
"You shouldn't have to use this unless your debugging."
@@ -22,19 +23,24 @@ def get_translation(self, language: str, message_code: str) -> str:
return translation_map["en-US"][message_code] # Default to US
except KeyError:
return "No message available for this given message code"
+
if __name__ == "__main__":
#Just some tests
translation_class = Translation()
if translation_class.get_translation("en-GB", "test") != "British!":
print ("Test 1 failed")
sysexit(1)
+
if translation_class.get_translation("thislanguage-doesnotexist", "test") != "Works!":
print ("Test 2 failed")
sysexit(1)
+
if translation_class.get_translation("en-US", "test") != "Works!":
print ("Test 3 failed")
sysexit(1)
+
if translation_class.get_translation("en-US", "thisdoesnotexist") != "No message available for this given message code":
print ("Test 4 failed")
sysexit(1)
+
print ("All tests passed!")
From 5a9870617e93947c2e3b03a0ac5f7ad75fde9717 Mon Sep 17 00:00:00 2001
From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com>
Date: Thu, 8 Aug 2024 20:35:01 -0400
Subject: [PATCH 5/5] oops
---
providers/translation/get_translate.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/providers/translation/get_translate.py b/providers/translation/get_translate.py
index 658955a..05c59af 100644
--- a/providers/translation/get_translate.py
+++ b/providers/translation/get_translate.py
@@ -14,6 +14,7 @@ def _get_translation_map(self) -> dict:
json_data = load(f)
translation_map[dirname.removeprefix("./translations/")] = json_data
return translation_map
+
def get_translation(self, language: str, message_code: str) -> str:
translation_map = self._get_translation_map()
try: