~ubuntu-branches/ubuntu/karmic/openoffice.org-l10n/karmic

« back to all changes in this revision

Viewing changes to debian/gsifilter.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-04-27 19:29:22 UTC
  • Revision ID: james.westby@ubuntu.com-20060427192922-2dburxv3b63f8v0u
Tags: 2.0.2-2ubuntu5
* Copy of the openoffice.org source.
  - debian/control.in: Change source name.
  - debian/changelog: Change source name.
  - debian/control: Regenerate control file.
* Add kurdish translations exported from Rosetta (2006-04-18).
* Workaround bad message strings in recently included GSI files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
import os
 
4
import sys
 
5
from translate.storage import oo
 
6
 
 
7
debug = False
 
8
 
 
9
def dupfilter(mf, comment, fn):
 
10
    n_all = n_translated = n_untranslated = n_same = 0
 
11
    new_sources = []
 
12
    for oofile in mf.listsubfiles():
 
13
        of = mf.getoofile(oofile)
 
14
        if oofile.startswith('helpcontent2'):
 
15
            for el in of.ooelements:
 
16
                n_all += 1
 
17
                if len(el.lines) == 1:
 
18
                    if debug:
 
19
                        print "WARNING: %s: no translation (%d lines)" % (helpfile, len(el.lines))
 
20
                    n_untranslated += 1
 
21
                    continue
 
22
                if len(el.lines) > 2:
 
23
                    if debug:
 
24
                        print "WARNING: %s: too many translations (%d lines)" % (helpfile, len(el.lines))
 
25
                        print "   ", el.lines[0].project, el.lines[0].sourcefile, el.lines[0].groupid,el.lines[0].localid
 
26
                    continue
 
27
                if el.lines[0].text == el.lines[1].text \
 
28
                   and el.lines[0].helptext == el.lines[1].helptext \
 
29
                   and el.lines[0].quickhelptext == el.lines[1].quickhelptext:
 
30
                    n_same += 1
 
31
                    if debug:
 
32
                        print "Not translated: %s/%s/%s" % (el.lines[0].text, el.lines[0].helptext, el.lines[0].quickhelptext)
 
33
                        print "                %s/%s/%s" % (el.lines[1].text, el.lines[1].helptext, el.lines[1].quickhelptext)
 
34
                    el.lines = [line for line in el.lines if line.languageid == "en-US"]
 
35
                else:
 
36
                    n_translated += 1
 
37
        new_sources.append(str(of))
 
38
 
 
39
    try:
 
40
        ratio = n_translated / float(n_all) * 100
 
41
    except:
 
42
        ratio = 0.0
 
43
    print "%s: %15s: %4.1f%%, lines=%5d, translated=%5d, untranslated=%5d, same=%5d" \
 
44
          % (comment, os.path.basename(fn), ratio, n_all, n_translated, n_untranslated, n_same)
 
45
    print "\tremoved %d translations with same text" % n_same
 
46
    sys.stdout.flush()
 
47
 
 
48
    return ''.join(new_sources)
 
49
 
 
50
if __name__ == '__main__':
 
51
    for fn in sys.argv[1:]:
 
52
        try:
 
53
            mf = oo.oomultifile(fn)
 
54
        except Exception, msg:
 
55
            sys.stdout.write("ERROR reading %s: %s\n" % (fn, msg))
 
56
            sys.stdout.flush()
 
57
            sys.exit(1)
 
58
 
 
59
        filtered = dupfilter(mf, "help", fn)
 
60
 
 
61
        fd = file(fn + '.tmp', 'w')
 
62
        fd.write(filtered)
 
63
        fd.close()