~crf-team/crf-irp/crf-irp

« back to all changes in this revision

Viewing changes to WebContent/js/extjs-2/examples/locale/create_languages_js.py

  • Committer: Thomas
  • Date: 2010-03-10 23:55:46 UTC
  • Revision ID: thomas@daisybox-port-20100310235546-23635dk6x5asb1ca
Upgrade ExtJs 3.1.1
Upgrade Spring 3.0.1 + dependencies
Change Jawr JS post processor : YUI
Upgrade to last build of dwr 3 trunk 69 revision 3019(after build 116), upgrade jawr-dwr plugin 1.4 unofficiale from jose noheda, Jawr 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import sys, os, re
4
 
 
5
 
try:
6
 
    import chardet
7
 
except ImportError:
8
 
    print "You need universal encoding detector for this script"
9
 
    print " http://chardet.feedparser.org or apt-get install python-chardet"
10
 
    sys.exit()
11
 
 
12
 
regexp_language = re.compile("\* +(.+) +translation", re.IGNORECASE)
13
 
js_template = """/* This file is automaticly generated by create_language_js.py */
14
 
 
15
 
// some data used in the examples
16
 
Ext.namespace('Ext.exampledata');
17
 
 
18
 
// TODO: complete and sort the list
19
 
Ext.exampledata.languages = [
20
 
%s
21
 
];
22
 
"""
23
 
 
24
 
 
25
 
lang_dubs = {}
26
 
def lang_name(file):
27
 
    language = os.path.basename(file)
28
 
    m = regexp_language.search(open(file).read(512))
29
 
    if m:
30
 
        language = m.groups()[0]
31
 
        if not lang_dubs.has_key(language):
32
 
            lang_dubs[language] = file
33
 
        else:
34
 
            raise Exception('Duplicate language '+language+' for file '+file)
35
 
    return language
36
 
 
37
 
def print_locale(lang_code):
38
 
    print lang_code,
39
 
    sys.stdout.flush()
40
 
    return True
41
 
 
42
 
def main():
43
 
    base_dir = "../../src/locale"
44
 
    base_file = lambda f: os.path.join(base_dir, f)
45
 
    try:
46
 
        locales = os.listdir(base_dir)
47
 
    except IOError:
48
 
        print "Cannot find source locale directory: %s ... exiting" % base_dir
49
 
        sys.exit()
50
 
    
51
 
    valid_file = lambda e: e.endswith(".js") and e.startswith("ext-lang-")
52
 
    char_set = lambda f: chardet.detect(open(f).read())['encoding']
53
 
    lang_code = lambda f: f[9:f.rfind(".js")]
54
 
    info_set = lambda f: (lang_name(base_file(f)), (lang_code(f), char_set(base_file(f))))
55
 
    locales = dict(info_set(file) for file in locales if valid_file(file) and print_locale(lang_code(file)))
56
 
    print "... done"
57
 
    locale_strarray = ',\n'.join(["\t[%r, %r, %r]" % (code, name, charset) \
58
 
                                     for name, (code, charset) in sorted(locales.items())])
59
 
    # create languages.js
60
 
    open("languages.js", "w").write(js_template % locale_strarray)
61
 
    print "saved %d languages to languages.js" % len(locales)
62
 
        
63
 
if __name__=="__main__":
64
 
    main()