~ywarnier/ubuntu-community-accomplishments/ywarnier-beginner-branch

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import glob
import os
from random import randint
import ConfigParser
import subprocess

files = glob.glob("accomplishments/*/en/*")

translatedsections = [
    { "title" :
        "A short description of the accomplishment.\n \
        NOTE: Describe this in the past tense as if it has been achieved (e.g. Registered On Launchpad). " },
    { "description" :
        "Add a descriptive single-line summary of the accomplishment." },
    { "summary" :
        "Introduce the accomplishment, explain what the different concepts are that are involved, and provide guidance on how to accomplish it.\n \
        NOTE: Break this into paragraphs by putting each paragraph on a new line. \n \
        FORMATTING ALLOWED: <i> <strong> <tt>" },
    { "steps" :
        "Add a series of step-by-step instructions for how to accomplish this trophy.\n \
        NOTE: Put each step on a new line\n \
        FORMATTING ALLOWED: <i> <strong> <tt>" },
    { "tips" :
        "Add tips and best practise for accomplishing this trophy.\n \
        NOTE: Put each tip on a new line\n \
        FORMATTING ALLOWED: <i> <strong> <tt>" },
    { "pitfalls" :
        "Add things the user should not do when working to accomplish this trophy.\n \
        NOTE: Put each pitfall on a new line\n \
        FORMATTING ALLOWED: <i> <strong> <tt>" },
    { "links" :
        "Add related web addresses (don't include a HTML link).\n \
        NOTE: Put each URL on a new line" },
    { "help" :
        "Add related help resources (e.g. IRC channel names).\n \
        NOTE: Put each help resource on a new line\n \
        FORMATTING ALLOWED: <i> <strong> <tt>" }]
    
generatedaccomplishmentsdir = "generated/accomplishments"
podir = "generated/po"

if not os.path.exists(generatedaccomplishmentsdir):
    os.makedirs(generatedaccomplishmentsdir)

if not os.path.exists(podir):
    os.makedirs(podir)
    
potfilesin = open(os.path.join(podir, "POTFILES.in"), "w")

print "Processing files:"

for f in files:
    print "..." + str(f)
    accomplishmentname = os.path.split(f)[1].split(".")[0]
    tempfile = open(os.path.join(generatedaccomplishmentsdir, accomplishmentname + ".c"), "w")
    config = ConfigParser.RawConfigParser()
    config.read(f)
    title = config.get("accomplishment", "title")
    items = config.items("accomplishment")
    tempfile.write("[accomplishment]\n")
    for i in items:
        for sec in translatedsections:
            if i[0] in sec.keys():
                output = "// ACCOMPLISHMENT: " + title + " ('" + i[0] + "' field)\n"
                output = output + "// .\n"
                origitemlines = config.get("accomplishment", i[0]).split("\n")
                origitem = ""
                for l in origitemlines:
                    origitem = origitem + ("// " + l + "\n")

                output = output + ("// ENGLISH TRANSLATION:\n")
                output = output + (origitem + "\n")
                output = output + "// .\n"
                output = output + "// ----- TRANSLATION INSTRUCTIONS ----- \n"
                for c in sec.values()[0].split("\n"):
                    output = output + ("// " + c + "\n")
                output = output + ("_(\"" + accomplishmentname + "_" + i[0] + "\")\n")
                tempfile.write(output)
    tempfile.close()

    # write POTFILES.in
    potfilesin.write(os.path.join("accomplishments", accomplishmentname + ".c\n"))

potfilesin.close()

os.chdir(podir)
print "Generating POT file"
subprocess.call(["intltool-update", "-pot", "--gettext-package=template"])
print "...done."