blob: 07364dd0d431bb007072cfe75c3a52c06aac7a53 (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import metabook
import re
class ArticleTranslated(metabook.Article):
lang = "en" # default language code
trans = "" # translated title
def __init__(self,attributes):
title = attributes["title"]
parts = title.split("/")
#if len(parts) < 2:
# self.include = False
# return
if len(parts) == 1:
# title = "blabla"
self.title = title
if len(parts) == 2:
# title = "Category/englishTitle"
self.title = parts[1]
if len(parts) == 3:
# title = "Category/englishTitle/langCode"
self.lang = parts[2]
self.title = parts[1]
comment = attributes["comment"]
if '{Lang|' in comment:
# Language-tag exists
r = re.search("\{Lang\|([^\}]*)\}",comment)
trans = r.group(1)
self.trans = trans
else:
self.trans = self.title
attr = {}
attr["title"] = attributes["title"]
attr["displaytitle"] = self.trans
attr["lang"] = self.lang
self.attributes = attr
class MetabookTranslated(metabook.Metabook):
"""
This concrete metabook expects article titles in this form:
Category/Title/lang
Comments include this:
{{Lang|translatedTitle}}
"""
ArticleClass=ArticleTranslated
artTags = ["title","comment"]
def splitByLanguage(self):
"""
@return List of Metabook
"""
pass
|