1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

[1812] Update Docs and Fix Compat Layer

This commit is contained in:
David Sangrey 2024-04-22 19:18:01 -04:00
parent 10be2c2031
commit 91e4e7998b
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC
2 changed files with 15 additions and 7 deletions

View File

@ -1193,19 +1193,27 @@ widget if you need to display routine status information.
## Localisation
You can localise your plugin to one of the languages that EDMarketConnector
itself supports. Add the following import near the top of each source
itself supports. Add the following boilerplate near the top of the source
file that contains strings that needs translating:
```python
from l10n import translations as tr
import l10n
import functools
plugin_tl = functools.partial(l10n.translations.tl, context=__file__)
```
Wrap each string that needs translating with the `tr.tl()` function, e.g.:
Wrap each string that needs translating with the `plugin_tl()` function, e.g.:
```python
somewidget["text"] = tr.tl("Happy!")
somewidget["text"] = plugin_tl("Happy!")
```
Note that you can name the "plugin_tl" function whatever you want - just make sure to stay consistent!
Many plugins use `_` as the singleton name. We discourage that in versions 5.11 onward, but it should still work.
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 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.

View File

@ -86,7 +86,7 @@ class Translations:
"""
self.translations = {None: {}}
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
# Migrate to calling Translations.translate directly.
# Migrate to calling translations.translate or tr.tl directly.
builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n')
def install(self, lang: str | None = None) -> None: # noqa: CCR001
@ -131,7 +131,7 @@ class Translations:
logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}')
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
# Migrate to calling Translations.translate directly.
# Migrate to calling translations.translate or tr.tl directly.
builtins.__dict__['_'] = self.translate
def contents(self, lang: str, plugin_path: str | None = None) -> dict[str, str]:
@ -351,7 +351,7 @@ class _Translations(Translations):
super().__init__()
Translations: Translations = _Translations() # type: ignore # Yes, I know this is awful. But we need it for compat.
Translations = translations # Yes, I know this is awful renaming garbage. But we need it for compat.
# End Deprecation Zone
# generate template strings file - like xgettext