File tree 3 files changed +49
-0
lines changed
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
1
+ from Translations import Translations
2
+
3
+ extract = Translations ("en" )
4
+ extract .get_translations_and_extract ()
5
+ extract .load_po_files ()
You can’t perform that action at this time.
0 commit comments