mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 18:07:37 +03:00
Merge branch 'develop' into enhancement/806/system-profiler
This commit is contained in:
commit
2516d7b595
@ -1214,6 +1214,15 @@ Many plugins use `_` as the singleton name. We discourage that in versions 5.11
|
||||
If your plugin has multiple files that need translations, simply import the `plugin_tl` function to that location.
|
||||
You should only need to add the boilerplate once.
|
||||
|
||||
If you wish to override EDMCs current language when translating,
|
||||
`l10n.translations.tl()` also takes an optional `lang` parameter which can
|
||||
be passed a language identifier. For example to define a function to override
|
||||
all translations to German:
|
||||
|
||||
```python
|
||||
plugin_tl_de = functools.partial(l10n.Translations.translate, context=__file__, lang="de")
|
||||
```
|
||||
|
||||
If you display localized strings in EDMarketConnector's main window you should
|
||||
refresh them in your `prefs_changed` function in case the user has changed
|
||||
their preferred language.
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 8adfd86b64e8c14e873d2f5123d88ca6743420b9
|
||||
Subproject commit 651aab5af6a22980a1f88dcbb9ed256244cd6dff
|
39
l10n.py
39
l10n.py
@ -20,6 +20,7 @@ from contextlib import suppress
|
||||
from os import listdir, sep, makedirs
|
||||
from os.path import basename, dirname, isdir, join, abspath, exists
|
||||
from typing import TYPE_CHECKING, Iterable, TextIO, cast
|
||||
|
||||
from config import config
|
||||
from EDMCLogging import get_main_logger
|
||||
|
||||
@ -159,25 +160,45 @@ class Translations:
|
||||
|
||||
return translations
|
||||
|
||||
def tl(self, x: str, context: str | None = None) -> str:
|
||||
def tl(self, x: str, context: str | None = None, lang: str | None = None) -> str:
|
||||
"""Use the shorthand Dummy loader for the translate function."""
|
||||
return self.translate(x, context)
|
||||
return self.translate(x, context, lang)
|
||||
|
||||
def translate(self, x: str, context: str | None = None) -> str:
|
||||
def translate(self, x: str, context: str | None = None, lang: str | None = None) -> str: # noqa: CCR001
|
||||
"""
|
||||
Translate the given string to the current lang.
|
||||
Translate the given string to the current lang or an overriden lang.
|
||||
|
||||
:param x: The string to translate
|
||||
:param context: Whether or not to search the given directory for translation files, defaults to None
|
||||
:param context: Contains the full path to the file being localised, from which the plugin name is parsed and
|
||||
used to locate the plugin translation files, defaults to None
|
||||
:param lang: Contains a language code to override the EDMC language for this translation, defaults to None
|
||||
:return: The translated string
|
||||
"""
|
||||
plugin_name: str | None = None
|
||||
plugin_path: str | None = None
|
||||
|
||||
if context:
|
||||
# TODO: There is probably a better way to go about this now.
|
||||
context = context[len(config.plugin_dir)+1:].split(sep)[0]
|
||||
if self.translations[None] and context not in self.translations:
|
||||
logger.debug(f'No translations for {context!r}')
|
||||
plugin_name = context[len(config.plugin_dir)+1:].split(sep)[0]
|
||||
plugin_path = join(config.plugin_dir_path, plugin_name, LOCALISATION_DIR)
|
||||
|
||||
return self.translations.get(context, {}).get(x) or self.translate(x)
|
||||
if lang:
|
||||
contents: dict[str, str] = self.contents(lang=lang, plugin_path=plugin_path)
|
||||
|
||||
if not contents or type(contents) is not dict:
|
||||
logger.debug(f'Failure loading translations for overridden language {lang!r}')
|
||||
return self.translate(x)
|
||||
elif x not in contents.keys():
|
||||
logger.debug(f'Missing translation: {x!r} for overridden language {lang!r}')
|
||||
return self.translate(x)
|
||||
else:
|
||||
return contents.get(x) or self.translate(x)
|
||||
|
||||
if plugin_name:
|
||||
if self.translations[None] and plugin_name not in self.translations:
|
||||
logger.debug(f'No translations for {plugin_name!r}')
|
||||
|
||||
return self.translations.get(plugin_name, {}).get(x) or self.translate(x)
|
||||
|
||||
if self.translations[None] and x not in self.translations[None]:
|
||||
logger.debug(f'Missing translation: {x!r}')
|
||||
|
@ -1,12 +1,5 @@
|
||||
certifi==2024.2.2
|
||||
requests==2.31.0
|
||||
pillow==10.3.0
|
||||
# requests depends on this now ?
|
||||
charset-normalizer==3.3.2
|
||||
|
||||
watchdog==3.0.0
|
||||
# Commented out because this doesn't package well with py2exe
|
||||
infi.systray==0.1.12; sys_platform == 'win32'
|
||||
# argh==0.26.2 watchdog dep
|
||||
# pyyaml==5.3.1 watchdog dep
|
||||
semantic-version==2.10.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user