1
|
#! /usr/bin/env python
|
2
|
|
3
|
import os
|
4
|
import requests
|
5
|
import xml.etree.ElementTree as ET
|
6
|
import polib
|
7
|
|
8
|
urls = ['https://www.oasis-eu.org/footer.xml', 'https://www.oasis-eu.org/header.xml']
|
9
|
langs = {}
|
10
|
for url in urls:
|
11
|
response = requests.get(url)
|
12
|
menuset = ET.fromstring(response.text.encode('utf-8'))
|
13
|
for menu in menuset.findall('menu'):
|
14
|
locale = menu.find('locale').text
|
15
|
langs[locale] = []
|
16
|
for item in menu.findall('item'):
|
17
|
if 'href' in item.attrib:
|
18
|
langs[locale].append(item.attrib['href'])
|
19
|
langs[locale].append(item.text)
|
20
|
else:
|
21
|
langs[locale].append('#')
|
22
|
langs[locale].append('')
|
23
|
|
24
|
for lang in os.listdir('i18n'):
|
25
|
path = os.path.join('i18n', lang, 'LC_MESSAGES', 'ckanext.po')
|
26
|
if not os.path.exists(path):
|
27
|
continue
|
28
|
catalog = dict(zip(langs['en'], langs[lang]))
|
29
|
pofile = polib.pofile(path)
|
30
|
changed = False
|
31
|
for entry in pofile:
|
32
|
if entry.msgid in catalog:
|
33
|
if entry.msgstr != catalog.get(entry.msgid):
|
34
|
entry.msgstr = catalog.get(entry.msgid)
|
35
|
if 'fuzzy' in entry.flags:
|
36
|
entry.flags.remove('fuzzy')
|
37
|
changed = True
|
38
|
if changed:
|
39
|
pofile.save(path)
|