Closed Athanasius closed 4 months ago
Honestly, I'm looking at just dropping forcing the builtin entirely. It confuses type checking, it makes things look weird, and it's not very clear where it's set or what it's doing.
It'd be easier to just add a dummy function to the l10n _Translation class and accept one more direct import.
I don't think it's too much of a design sacrifice to do something along these lines:
Add this to l10n's _Translations class
def tl(self, *args) -> str:
"""
Dummy loader for the translate function. Used as shorthand.
"""
return self.translate(*args)
and in files where we need translations
from l10n import Translations as Tr
...
def somefunc():
foo = Tr.tl("My String Here")
...
instead of the traditional
def somefunc():
foo = _("My String Here")
Mocked up what would need to be done in https://github.com/HullSeals/EDMarketConnector/tree/enhancement/1812/rename_underscore_translate Tasks:
Some of this may relate to #2188 and may need revisited if/when it gets merged in.
As per comments in Discord, I'd take this opportunity to move to the standard ways of naming things in Python.
Translations
is currently the singleton. This should not be capitalised!Tr
shouldn't be capitalised either.So:
_Translations
class (note the leading underscore) to Translations
.Translations
singleton to translations
.from l10n import translations as tr
, and end up with tr.tl(...)
replacing _(...)
.
An unfortunate side-effect of forcing
_()
intobuiltins
for translation of strings is that it means the_
for things like "I don't care about this return value" clashes. In general it was a REALLY bad choice given the uses of_
normally.Here I've changed
new_data
in the function call to_
. After this the use of_("string to be translated")
breaks:Proposal: Change the translation
_()
to_t()
- it's only one extra character.Issues: minor - PLUGINS.md mentions manually setting this up (does that code even work ?), that needs updating. But as plugins would have to manually set things up in this manner nothing will break by changing this in core code.
Follow-ups: Identify any places where
_
as "throw this away" would be appropriate and update them. There's at least some killswitch related code. Check over all the developer documentation to be sure it's up to date with the change.