File: prepare_i18n_xslt

package info (click to toggle)
tellico 2.3.9%2Bdfsg.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,536 kB
  • ctags: 8,997
  • sloc: cpp: 67,150; ansic: 8,315; xml: 2,103; python: 1,977; ruby: 189; perl: 52; ada: 32; makefile: 11; sh: 11
file content (53 lines) | stat: -rwxr-xr-x 1,488 bytes parent folder | download | duplicates (3)
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+')
title = re.compile(r'<title>(.*?)</title>', re.DOTALL)

def extract_i18n_z3950(filename):
    f = open(filename, 'r')
    text = f.read()
    for m in title.finditer(text):
        sys.stdout.write("i18n(\"")
        sys.stdout.write(ws.sub(' ', m.group(1)))
        sys.stdout.write("\");\n")

def extract_i18n(filename):
    f = open(filename, 'r')
    text = f.read()
    for m in i18n.finditer(text):
        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("\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")