Page MenuHomePhabricator

Load l10n dicts using i18n.translate
Open, LowPublic

Description

There are some l10n dicts all over Pywikibot, that are loaded using get(code) or dict[code]. These should be loaded using i18n.translate to standardize their behavior.

Examples:

  • primary_topic_format
  • ignoreTemplates
  • moved_links
  • nowCommonsTemplate

Event Timeline

Change 507974 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] use i18n.translate instead of getCommonscatTemplate class method

https://gerrit.wikimedia.org/r/507974

Xqt triaged this task as Low priority.May 3 2019, 6:13 PM

getCommonscatTemplate was the best example of a method that should be replaced by i18n.translate in this task

Change 507974 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] use i18n.translate instead of getCommonscatTemplate class method

https://gerrit.wikimedia.org/r/507974

Change 758949 had a related patch set uploaded (by Lorcan; author: Lorcan):

[pywikibot/core@master] [IMPR] use i18n.translate instead of whitelists[code] dictionary retrieval

https://gerrit.wikimedia.org/r/758949

Hi, I am new to open source contributions but wanted to help if possible. I presumed this was still open and noted in other patches there not really being a requirement to ask for permission, especially given this is several years old.

I also had a look at edit_restricted_templates, however it seemed that the function i18n.translate would have to be updated due to the contents of the dictionary being different from what is defined in the translate method.

Hi Lorcan, thank you for your contribution and your help. Yes, this task is still open.

Can you explain your assumption that i18n has to be updated?

I was probably hasty in assuming that the translate message needed to be changed.

When I took a similar approach that was taken for 'getCommonscatTemplate', for 'edit_restricted_templates', my IDE highlighted that the expected type was different from what I was passing in. The edit_restricted_templates dictionary values being a tuple rather than a string threw me off and I assumed Typing would complain due to the wrong type in the dictionary's values (although I don't have experience with Typing).

Expected type 'Union[str, Mapping[str, str]]', got 'Dict[str, Tuple[str, ...]]' instead

Removed unrelated templates. family dicts should never be translated because they are inherited already. Also I removed dicts of archived scripts

Change 758949 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] use i18n.translate instead of whitelists[code] dictionary retrieval

https://gerrit.wikimedia.org/r/758949