Skip to content

Commit c815e55

Browse files
author
Thomas Eimers
committed
Get all Mycroft Skill Commands from the po translation files
0 parents  commit c815e55

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Mycroft.ai command lister
2+
3+
Get all Mycroft skill commands to generate Command Lists for Plugins.
4+
5+
6+
7+
Status: Draft for gras64

Translations.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from os.path import basename
2+
import requests
3+
import polib
4+
import zipfile
5+
import glob
6+
import os
7+
8+
9+
class Translations(object):
10+
lang = "de"
11+
EXTRACT_DIR = "extract"
12+
13+
def __init__(self, lang):
14+
self.lang = lang
15+
16+
# Get ZIP File (en-mycroft-skills.zip)
17+
def get_translations_and_extract(self):
18+
data = requests.get("https://translate.mycroft.ai/export/?path=/" + self.lang + "/mycroft-skills/")
19+
path_to_zip_file = self.lang + '-mycroft-skills.zip'
20+
open(path_to_zip_file, 'wb').write(data.content)
21+
22+
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
23+
zip_ref.extractall(self.EXTRACT_DIR)
24+
25+
os.remove(path_to_zip_file)
26+
27+
# get all mycroft PO files from skills
28+
def load_po_files(self):
29+
directory_with_po_files = self.EXTRACT_DIR + "/" + self.lang + '-mycroft-skills/' + self.lang + '/mycroft-skills/'
30+
print('Read po files from directory ' + directory_with_po_files)
31+
for file in glob.glob(directory_with_po_files + "*.po"):
32+
print('Read commands from plugin: ' + basename(file)[0:-3])
33+
po = polib.pofile(
34+
file
35+
)
36+
for entry in po:
37+
print(entry.msgid, entry.msgstr)

extract-commands.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from Translations import Translations
2+
3+
extract = Translations("en")
4+
extract.get_translations_and_extract()
5+
extract.load_po_files()

0 commit comments

Comments
 (0)