0

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)
grandsirr
  • 584
  • 4
  • 19
  • 1
    This seems like an unnecessary use of `forbiddenfruit` as it could simply be replaced by a function. As for a solution to the error, the stacktrace makes it clear that `Visual C++ 14.0` is required and how to download it. – Axe319 Dec 21 '20 at 14:26
  • Thanks for your reply. What did you mean by replacing it with a function? Like `init_localize (" Hello ")`? Yes, I can do that but actually I don't want to. What I want to know is there is an alternative to "forbidden fruit" and also if I freeze this code with a tool like `pyinstaller` will it work even if there is no Visual C++ 14.0 on other machines? – grandsirr Dec 21 '20 at 18:17
  • 1
    Yes it should. `Visual C++ 14.0` is just used for the build process. And yes, using it in a function in that manner. From their pypi page: `"This project aims to help you reach heaven while writing tests, but it may lead you to hell if used on production code."` – Axe319 Dec 21 '20 at 19:40

0 Answers0