1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-06 10:23:06 +03:00

Replaced prints with logging

This commit is contained in:
A_D 2020-11-07 16:07:34 +02:00 committed by Athanasius
parent 4ede555c13
commit e44039cfdd

21
l10n.py
View File

@ -13,7 +13,6 @@ from collections import OrderedDict
from contextlib import suppress from contextlib import suppress
from os.path import basename, dirname, exists, isdir, isfile, join, normpath from os.path import basename, dirname, exists, isdir, isfile, join, normpath
from sys import platform from sys import platform
from traceback import print_exc
from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, Union, cast from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, Union, cast
if TYPE_CHECKING: if TYPE_CHECKING:
@ -27,6 +26,10 @@ except Exception:
print("Can't set locale!") print("Can't set locale!")
from config import config from config import config
from EDMCLogging import get_main_logger
logger = get_main_logger()
# Language name # Language name
LANGUAGE_ID = '!Language' LANGUAGE_ID = '!Language'
@ -117,10 +120,10 @@ class _Translations:
self.translations[plugin] = self.contents(cast(str, lang), plugin_path) self.translations[plugin] = self.contents(cast(str, lang), plugin_path)
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') logger.warning(f'Malformed file {lang}.strings in plugin {plugin}: {e}')
except Exception: except Exception:
print_exc() logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}')
builtins.__dict__['_'] = self.translate builtins.__dict__['_'] = self.translate
@ -139,8 +142,8 @@ class _Translations:
to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n')
translations[match.group(1).replace(r'\"', u'"')] = to_set translations[match.group(1).replace(r'\"', u'"')] = to_set
elif __debug__ and not _Translations.COMMENT_RE.match(line): elif not _Translations.COMMENT_RE.match(line):
print(f'Bad translation: {line.strip()}') logger.debug(f'Bad translation: {line.strip()}')
if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID:
translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing
@ -157,15 +160,13 @@ class _Translations:
""" """
if context: if context:
context = context[len(config.plugin_dir)+1:].split(os.sep)[0] context = context[len(config.plugin_dir)+1:].split(os.sep)[0]
if __debug__:
if self.translations[None] and context not in self.translations: if self.translations[None] and context not in self.translations:
print(f'No translations for {context!r}') logger.debug(f'No translations for {context!r}')
return self.translations.get(context, {}).get(x) or self.translate(x) return self.translations.get(context, {}).get(x) or self.translate(x)
if __debug__:
if self.translations[None] and x not in self.translations[None]: if self.translations[None] and x not in self.translations[None]:
print(f'Missing translation: {x!r}') logger.debug(f'Missing translation: {x!r}')
return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n')
@ -224,7 +225,7 @@ class _Translations:
return codecs.open(f, 'r', 'utf-8') return codecs.open(f, 'r', 'utf-8')
except Exception: except Exception:
print_exc() logger.exception(f'could not open {f}')
return None return None