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
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:
| Status | Subtype | Assigned | Task | ||
|---|---|---|---|---|---|
| Open | None | T218467 edit_restricted_templates to support all Wikipedias | |||
| Open | None | T173103 Use wikidata item Q5828850 for category redirect templates on wikimedia families | |||
| Resolved | Lichinsol | T219094 Load l10n dicts using i18n.translate |
Change 507974 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] use i18n.translate instead of getCommonscatTemplate class method
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
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
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
Change #1119711 had a related patch set uploaded (by Lichinsol; author: Lichinsol):
[pywikibot/core@master] [IMPR] use i18n.translate instead of dictonaries directly.
Change #1119711 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] use i18n.translate instead of dictonaries directly.
Hi, @Xqt It gives the following:
Command line:
python pwb.py cosmetic_changes -always -page:"موضيل:Resolve category redirect" -lang:ary
Output:
Retrieving 1 pages from wikipedia:ary.
>>> موضيل:Resolve category redirect <<<
1 read operation
Execution time:
Read operation time: 0.0 seconds
Script terminated by exception:
ERROR: cannot unpack non-iterable NoneType object (TypeError)
Traceback (most recent call last):
File "C:\Users\Mohammed\Downloads\core\pwb.py", line 40, in <module>
sys.exit(main())
~~~~^^
File "C:\Users\Mohammed\Downloads\core\pwb.py", line 36, in main
runpy.run_path(str(path), run_name='__main__')
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen runpy>", line 287, in run_path
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 554, in <module>
main()
~~~~^^
File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 538, in main
if not execute():
~~~~~~~^^
File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 525, in execute
run_python_file(filename, script_args, module)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 154, in run_python_file
exec(compile(source, filename, 'exec', dont_inherit=True),
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
main_mod.__dict__)
^^^^^^^^^^^^^^^^^^
File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 131, in <module>
main()
~~~~^^
File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 127, in main
bot.run()
~~~~~~~^^
File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1583, in run
self.treat(page)
~~~~~~~~~~^^^^^^
File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1830, in treat
self.treat_page()
~~~~~~~~~~~~~~~^^
File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 85, in treat_page
new_text = cc_toolkit.change(old_text)
File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 318, in change
new_text = self._change(text)
File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 312, in _change
text = self.safe_execute(method, text)
File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 298, in safe_execute
result = method(text)
File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 377, in standardizePageFooter
tmpl, loc = i18n.translate(self.site.code, moved_links)
^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object
CRITICAL: Exiting due to uncaught exception TypeError: cannot unpack non-iterable NoneType objectThe site code "ary" does not exist in the moved_links dictionary, hence the error may have come. Only a code named "ar" exists.
A similar error is coming even with the older version (when directly using moved_links dictionary) of cosmetic_changes.py, which may indicate that the issue may not be
due to this change.
This is my understanding, though not fully sure.
Change #1154390 had a related patch set uploaded (by Xqt; author: Xqt):
[pywikibot/core@master] [Bugfix] Fix i18n.translate calls
The previous implementation raises a KeyError if the key (like 'ary') does not exist, The new implementation raises a TypeError when trying to unpack a NoneType object because i18n.translate() gives just None if the key was not found. The KeyError is only raised in translate() if fallback is True.
Sorry I haven't checked this issue enough during review,
Change #1154390 merged by jenkins-bot:
[pywikibot/core@master] [Bugfix] Fix i18n.translate calls