Skip to content

Commit

Permalink
Start work with translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Soapy7261 committed Aug 1, 2024
1 parent e9a78b7 commit f5caa7b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
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!
37 changes: 37 additions & 0 deletions providers/translation/get_translate.py
Original file line number Diff line number Diff line change
@@ -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!")
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"
}

0 comments on commit f5caa7b

Please sign in to comment.