File: prepare_i18n_xslt

package info (click to toggle)
tellico 3.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 23,468 kB
  • sloc: cpp: 73,731; xml: 8,383; ansic: 7,003; javascript: 3,059; python: 603; perl: 63; ada: 32; sh: 28; makefile: 22
file content (53 lines) | stat: -rwxr-xr-x 1,529 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# little script to insert Tellico's xslt template names into i18n
#
# 2004 by Robby Stephenson <robby@periapsis.org>

import sys
import os
import re

i18n = re.compile(r'<i18n>(.*?)</i18n>', re.DOTALL)
ws   = re.compile('\s+')

def line_of_char(s, c):
    return s.count('\n', 0, c) + 1

def extract_i18n(filename):
    f = open(filename, 'r')
    text = f.read()
    for m in i18n.finditer(text):
        sys.stdout.write("// i18n: file: ")
        sys.stdout.write(filename)
        sys.stdout.write(":")
        sys.stdout.write(str(line_of_char(text, m.start(1))))
        sys.stdout.write("\n")
        sys.stdout.write("i18n(\"")
        sys.stdout.write(ws.sub(' ', m.group(1)))
        sys.stdout.write("\");\n")

def get_xsl_files(dir):
    files = []
    nodes = [f for f in os.listdir(dir)]
    for n in nodes:
        if n[-4:] == ".xsl":
            files.append(os.path.join(dir,n))

    return files

def print_output(dir):
    files = get_xsl_files(dir)
    for f in files:
        name = os.path.basename(f)[:-4].replace('_', ' ')
        sys.stdout.write("\n// i18n: file: ")
        sys.stdout.write(f)
        sys.stdout.write("\ni18nc(\"")
        sys.stdout.write(name + " XSL Template\", \"" + name)
        sys.stdout.write("\");\n")
        extract_i18n(f)

if __name__ == "__main__":
    print_output("xslt/entry-templates")
    print_output("xslt/report-templates")
    # I don't want "tellico2html" translated, so just grab i18n strings
    extract_i18n("xslt/tellico2html.xsl")