2727 from distutils .command .build_py import build_py
2828
2929try :
30- import msgfmt
30+ from babel .messages .frontend import compile_catalog as _compile_catalog
31+ from babel .messages .frontend import extract_messages # as _extract_messages
32+
33+ class compile_catalog (_compile_catalog ):
34+ def initialize_options (self ):
35+ """Simply set default domain and directory attributes to the
36+ correct path for bpython."""
37+ _compile_catalog .initialize_options (self )
38+
39+ self .domain = 'bpython'
40+ self .directory = os .path .join ('i18n' , 'locale' )
41+
42+ build .sub_commands .append (('compile_catalog' , None ))
43+ using_translations = True
3144except ImportError :
32- pass
45+ using_translations = False
3346
3447if platform .system () == 'FreeBSD' :
3548 man_dir = 'man'
3649else :
3750 man_dir = 'share/man'
3851
39-
40-
41- class build_translation (cmd .Command ):
42- """Internationalization suport for bpython.
43- Compile .po files into .mo files"""
44-
45- description = __doc__
46- user_options = []
47-
48- def initialize_options (self ):
49- pass
50-
51- def finalize_options (self ):
52- pass
53-
54- def run (self ):
55- for src in glob .iglob (os .path .join ('po' , '[a-z][a-z]_[A-Z][A-Z].po' )):
56-
57- # remove 'po/' (the directory) and '.po' (the extension)
58- lang = src [3 :- 3 ]
59- dest_path = os .path .join ('build' , 'share' , 'locale' ,
60- lang , 'LC_MESSAGES' , '' )
61- dest = dest_path + 'bpython.mo'
62-
63- if not os .path .exists (dest_path ):
64- os .makedirs (dest_path )
65- if (not os .path .exists (dest ) or
66- os .stat (src )[8 ] > os .stat (dest )[8 ]):
67- print ('Adding translation: %s' % lang )
68- msgfmt .make (src , dest )
69-
70- build .sub_commands .insert (0 , ('build_translation' , None ))
71-
72-
7352data_files = [
7453 # man pages
7554 (os .path .join (man_dir , 'man1' ), ['doc/bpython.1' ]),
@@ -78,9 +57,10 @@ def run(self):
7857 (os .path .join ('share' , 'applications' ), ['data/bpython.desktop' ]),
7958]
8059# localization
81- for langfile in glob .iglob (os .path .join ('po' , '[a-z][a-z]_[A-Z][A-Z].po' )):
82- lang_path = os .path .join ('share' , 'locale' , langfile [3 :- 3 ], 'LC_MESSAGES' )
83- data_files .append ((lang_path , ['build/%s/bpython.mo' % lang_path ]))
60+ if using_translations :
61+ for lang in os .listdir ('i18n' ):
62+ lang_path = os .path .join ('' , 'locale' , lang , 'LC_MESSAGES' , 'bpython.mo' )
63+ data_files .append (('share' + lang_path , ['i18n' + lang_path ]))
8464
8565
8666setup (
@@ -107,9 +87,10 @@ def run(self):
10787 },
10888 scripts = ([] if using_setuptools else ['data/bpython' ,
10989 'data/bpython-gtk' ]),
110- cmdclass = dict (build_py = build_py ,
111- build = build ,
112- build_translation = build_translation )
90+ cmdclass = dict (build_py = build_py ,
91+ build = build ,
92+ compile_catalog = compile_catalog ,
93+ extract_messages = extract_messages )
11394)
11495
11596# vim: encoding=utf-8 sw=4 ts=4 sts=4 ai et sta
0 commit comments