From 12c70ac38890d2bd3aad31758911a201dd767f64 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 3 May 2020 13:36:01 +0200 Subject: [PATCH] Add a json conversion --- localization.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/localization.py b/localization.py index e6e6249..329aea1 100644 --- a/localization.py +++ b/localization.py @@ -2,6 +2,7 @@ from typing import * import importlib import types import logging +import json log = logging.getLogger(__name__) @@ -45,3 +46,14 @@ class Localization: def boolmoji(self, boolean: bool) -> str: return self.get("emoji_yes") if boolean else self.get("emoji_no") + + +def create_json_localization_file_from_strings(language: str): + module: types.ModuleType = importlib.import_module(f"strings.{language}") + raw = module.__dict__ + clean = {} + for key in raw: + if not (key.startswith("__") and key.endswith("__")): + clean[key] = raw[key] + with open(f"locale/{language}.json", "w") as file: + json.dump(clean, file)