forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhedyweb.py
27 lines (22 loc) · 860 Bytes
/
hedyweb.py
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
import collections
from website.yaml_file import YamlFile
import glob
from os import path
class PageTranslations:
def __init__(self, page):
self.data = {}
if page in ['start', 'join', 'learn-more', 'for-teachers']:
translations = glob.glob('content/pages/*.yaml')
else:
translations = glob.glob('content/pages/' + page + '/*.yaml')
for file in translations:
lang = path.splitext(path.basename(file))[0]
self.data[lang] = YamlFile.for_file(file)
def exists(self):
"""Whether or not any content was found for this page."""
return len(self.data) > 0
def get_page_translations(self, language):
d = collections.defaultdict(lambda: '')
d.update(**self.data.get('en', {}))
d.update(**self.data.get(language, {}))
return d