8
print "You need universal encoding detector for this script"
9
print " http://chardet.feedparser.org or apt-get install python-chardet"
12
regexp_language = re.compile("\* +(.+) +translation", re.IGNORECASE)
13
js_template = """/* This file is automaticly generated by create_language_js.py */
15
// some data used in the examples
16
Ext.namespace('Ext.exampledata');
18
// TODO: complete and sort the list
19
Ext.exampledata.languages = [
27
language = os.path.basename(file)
28
m = regexp_language.search(open(file).read(512))
30
language = m.groups()[0]
31
if not lang_dubs.has_key(language):
32
lang_dubs[language] = file
34
raise Exception('Duplicate language '+language+' for file '+file)
37
def print_locale(lang_code):
43
base_dir = "../../src/locale"
44
base_file = lambda f: os.path.join(base_dir, f)
46
locales = os.listdir(base_dir)
48
print "Cannot find source locale directory: %s ... exiting" % base_dir
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)))
57
locale_strarray = ',\n'.join(["\t[%r, %r, %r]" % (code, name, charset) \
58
for name, (code, charset) in sorted(locales.items())])
60
open("languages.js", "w").write(js_template % locale_strarray)
61
print "saved %d languages to languages.js" % len(locales)
63
if __name__=="__main__":