Skip to content

Translations into V4 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
47 changes: 47 additions & 0 deletions providers/translation/get_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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."
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", encoding="UTF-8") as f:
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:
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
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!")
3 changes: 3 additions & 0 deletions translations/en-GB/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "British!"
}
3 changes: 3 additions & 0 deletions translations/en-US/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "Works!"
}
7 changes: 7 additions & 0 deletions translations/translation_help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Wanna help with translating? Heres the directions to translate!

<h6>PS: If the language isn't in discord's language list, it cannot be added</h6>

- 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
3 changes: 3 additions & 0 deletions translations/translations_needed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "Something Here, its needed uwu"
}
Loading