-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathupdate-page-language.py
More file actions
executable file
·32 lines (23 loc) · 1.02 KB
/
Copy pathupdate-page-language.py
File metadata and controls
executable file
·32 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python3
import ws.ArchWiki.lang as lang
from ws.client import API
from ws.interactive import require_login
def update_page_language(api: API) -> None:
# ensure that we are authenticated
require_login(api)
namespaces = [0, 4, 10, 12, 14]
for ns in namespaces:
for page in api.generator(generator="allpages", gapnamespace=ns, gaplimit="max", prop="info"):
title = page["title"]
pagelanguage = page["pagelanguage"]
pure, langname = lang.detect_language(title)
langtag = lang.tag_for_langname(langname)
if pagelanguage != langtag:
api.set_page_language(title, langtag, "update language based on the page title")
if __name__ == "__main__":
import ws.config
api = ws.config.object_from_argparser(
API,
description="Updates the page language property in the wiki's database based on the ArchWiki page naming: https://wiki.archlinux.org/title/Help:I18n#Page_titles",
)
update_page_language(api)