-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"test": "British!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"test": "Works!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"test": "Something Here, its needed uwu" | ||
} |