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 56 57 58
|
#!/usr/bin/python3
import os
import glob
import datetime
import sys
import codecs
from gi.repository import GLib
GROUP = "Nemo Action"
class Main:
def __init__(self):
if len(sys.argv) > 1:
action_files = glob.glob(os.path.join(sys.argv[1], "*.nemo_action.in"))
else:
action_files = glob.glob(os.path.join(os.getcwd(), "*.nemo_action.in"))
if len(action_files) > 0:
dt = datetime.datetime
outstring = """
'''
This is a dummy file for translating Nemo Action files
It was generated by the extract_action_strings script on %s UTC.
'''
""" % (dt.utcnow())
outstring += "\n"
for fn in action_files:
keyfile = GLib.KeyFile.new()
if keyfile.load_from_file(fn, GLib.KeyFileFlags.NONE):
if keyfile.has_group(GROUP):
friendly_fn = os.path.split(fn)[1].replace(".", "_")
try:
name = keyfile.get_string(GROUP, "Name")
name_line = '%s_Name = _("%s")\n' % (friendly_fn, name)
outstring += (name_line)
except GLib.GError:
name = None
try:
tooltip = keyfile.get_string(GROUP, "Comment")
tooltip_line = '%s_Tooltip = _("%s")\n' % (friendly_fn, tooltip)
outstring += (tooltip_line)
except GLib.GError:
tooltip = None
if len(sys.argv) > 1:
outfilename = os.path.join(sys.argv[1], "action_i18n_strings.py")
else:
outfilename = os.path.join(os.getcwd(), "action_i18n_strings.py")
if os.path.exists(outfilename):
os.remove(outfilename)
outfile = codecs.open(outfilename, 'w', 'utf-8')
outfile.write(outstring)
outfile.close()
print("Extraction complete. Run makepot now")
if __name__ == "__main__":
Main()
|