I'm currently writing a localize method for my program and I'm currently coding on Mac OS X and the Forbiddenfruit library works finely. But when I tried to run it in Windows 10 computer it causes an exception. There are 4 questions I can't stop think about them.
- Is there an alternative library for forbiddenfruit?
- If I make my program an executable, will it run in other computers without causing any error?
- Is there a solution to fix this error?
- Why this happened? Is forbiddenfruit outdated?
Here is a Screenshot for my error
And here is the code
from forbiddenfruit import curse
import json
from importlib import import_module
from localize.keyword_list import keywords
import locale
def initialize_language():
with open("../settings.json", "r") as file:
json_file = json.load(file)
json_file["language"] = locale.getlocale()[0][:2]
with open("../settings.json", "w") as file:
json_file["first_run"] = False
json_dump = json.dumps(json_file, indent=len(json_file))
file.writelines(json_dump)
initialize_language()
with open("../settings.json", "r") as file:
language = f"localize.language.{json.load(file)['language']}"
try:
localized_keywords = import_module(language, package=None).localized_keywords
except ModuleNotFoundError:
localized_keywords = import_module("localize.language.en", package=None).localized_keywords
def init_localize(self):
if self in keywords:
return localized_keywords[keywords.index(self)]
else:
raise AttributeError(f"Can not localize '{self}'")
curse(str, "localize", init_localize)
#Here is an example usage of my method
#print("HELLO".localize())
#>>> Merhaba(Turkish)