[2188] Support Translation Language Override
Description
The default l10n.Translations.translate() function only works with the language currently selected by the user and loaded in l10n.Translations.install(). This PR adds an additional optional lang parameter to translate() which, when passed will temporarily load an alternative language and translate the passed string using that language.
Type of change
Enhancement
Implementation notes
- Some flake8 issues were flagged with the pre-existing imports. These were fixed.
- Some flake8 issues were flagged with the Darwin imports. These were not fixed as Darwin will be removed in 2186.
- The existing
contextparameter, passed to the function, was not well documented so this has been rewritten. Also, this parameter was modified inside the function, to strip it down to just the plugin name, and then used. IMHO this creates difficult to read code so I have introduced a newplugin_namevariable to the existing code, to take this value, and the originalcontextparameter is now left untouched. - I noted the comment "# TODO: There is probably a better way to go about this now." against the above extraction of the plugin name from
contextand would be happy to include a rework of this line if you can let me know what's the latest thinking on the approach. - Apologies for the automatic trailing space removals from
PLUGINS.md, I didn't spot these on commit but they don't seem unreasonable as a cleanup?
How has this been tested?
By running EDMC in various languages and by modifying a plugin to use the new optional parameter.
Resolves #2188
This in the pipe for review after #1812, @aussig this PR may require minor updates and edits after 1812 is merged due to potential conflicts.
No problem @Rixxan, I'll await the merge on that. I took the opportunity to update this PR to the latest develop, resolving one conflict with imports caused by the removal of Darwin, I've used the latest imports from develop (I note you are ignoring Flake8 rule I001 - import alpha ordering - so I did the same)
@aussig This is ready for a re-review given the new translation system. Just ping me when it's been given a once-over :)
@Rixxan I've merged in the latest changes to develop, adding in the optional lang parameter to the new tl().
Love it! Great work. Seems to test fine on my end.