-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from alexlnkp/pr-optimization
Optimize various parts of inference/training + requirement fixes
- Loading branch information
Showing
9 changed files
with
1,058 additions
and
1,840 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
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 @@ | ||
False,8.0,1.2 |
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 @@ | ||
False |
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 |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import locale | ||
import json | ||
import os | ||
|
||
|
||
def load_language_list(language): | ||
with open(f"./i18n/{language}.json", "r", encoding="utf-8") as f: | ||
language_list = json.load(f) | ||
return language_list | ||
try: | ||
with open(f"./i18n/{language}.json", "r", encoding="utf-8") as f: | ||
return json.load(f) | ||
except FileNotFoundError: | ||
raise FileNotFoundError( | ||
f"Failed to load language file for {language}. Check if the correct .json file exists." | ||
) | ||
|
||
|
||
class I18nAuto: | ||
""" | ||
A class used for internationalization using JSON language files. | ||
Examples | ||
-------- | ||
>>> i18n = I18nAuto('en_US') | ||
>>> i18n.print() | ||
Using Language: en_US | ||
""" | ||
def __init__(self, language=None): | ||
if language in ["Auto", None]: | ||
language = locale.getdefaultlocale()[ | ||
0 | ||
] # getlocale can't identify the system's language ((None, None)) | ||
if not os.path.exists(f"./i18n/{language}.json"): | ||
from locale import getdefaultlocale | ||
language = language or getdefaultlocale()[0] | ||
if not self._language_exists(language): | ||
language = "en_US" | ||
self.language = language | ||
# print("Use Language:", language) | ||
|
||
self.language_map = load_language_list(language) | ||
self.language = language | ||
|
||
@staticmethod | ||
def _language_exists(language): | ||
from os.path import exists | ||
return exists(f"./i18n/{language}.json") | ||
|
||
def __call__(self, key): | ||
"""Returns the translation of the given key if it exists, else returns the key itself.""" | ||
return self.language_map.get(key, key) | ||
|
||
def print(self): | ||
print("Use Language:", self.language) | ||
"""Prints the language currently in use.""" | ||
print(f"Using Language: {self.language}") |
Oops, something went wrong.