From 76e709193614b3668d3c31a078e667473af20369 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 15 May 2023 11:52:20 +0200 Subject: Initial i18n implementation --- wrappers/python/eduvpn_common/main.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'wrappers/python') diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index f3639e0..335b78c 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -1,4 +1,5 @@ import ctypes +import json from enum import IntEnum from typing import Any, Callable, Iterator, Optional @@ -17,14 +18,19 @@ from eduvpn_common.state import State class WrappedError(Exception): - pass + def __init__(self, translations, language, misc): + self.translations = translations + self.language = language + self.misc = misc + def __str__(self) -> str: + print(self.translations) + return self.translations[self.language] -def forwardError(error: bytes | str): - # TODO: HACK, remove this - if isinstance(error, str): - raise WrappedError(error) - raise WrappedError(error.decode("utf-8")) + +def forwardError(error: str): + d = json.loads(error) + raise WrappedError(d["message"], "en", d["misc"]) class ServerType(IntEnum): -- cgit v1.2.3