16 def dir_lang (file, lang, lang_dir_index):
17 path_components = file.split ('/')
18 path_components[lang_dir_index] = lang
19 return os.path.join (*path_components)
21 def do_file (file_name, lang_codes, buildlib):
23 sys.stderr.write ('%s...\n' % file_name)
24 split_file_name = file_name.split ('/')
25 d1, d2 = split_file_name[0:2]
29 elif d2 in lang_codes:
35 raise Exception ('cannot determine language for ' + file_name)
37 original = dir_lang (file_name, '', lang_dir_index)
38 translated_contents = open (file_name).read ()
39 (diff_string, error) \
40 = buildlib.check_translated_doc (original,
43 color=use_colors and not update_mode)
46 sys.stderr.write ('warning: %s: %s' % (file_name, error))
49 if error or len (diff_string) >= os.path.getsize (original):
50 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
52 diff_file = original + '.diff'
53 f = open (diff_file, 'w')
56 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
59 sys.stdout.write (diff_string)
62 sys.stdout.write (r'''
64 check-translation [--language=LANG] [--verbose] [--update] FILE...
66 This script is licensed under the GNU GPL.
70 global lang, verbose, update_mode, use_colors
72 p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
73 description="This script is licensed under the GNU GPL.")
74 p.add_option ("--language",
78 p.add_option ("--no-color",
82 help="do not print ANSI-cooured output")
83 p.add_option ("--verbose",
87 help="print details, including executed shell commands")
88 p.add_option ('-u', "--update",
92 help='call $EDITOR to update the translation')
94 (options, files) = p.parse_args ()
95 verbose = options.verbose
96 lang = options.language
97 use_colors = options.color
98 update_mode = options.update_mode
103 global update_mode, text_editor
105 files = do_options ()
106 if 'EDITOR' in os.environ:
107 text_editor = os.environ['EDITOR']
111 buildlib.verbose = verbose
114 do_file (i, langdefs.LANGDICT.keys (), buildlib)
116 if __name__ == '__main__':