15 def dir_lang (file, lang, lang_dir_index):
16 path_components = file.split ('/')
17 path_components[lang_dir_index] = lang
18 return os.path.join (*path_components)
20 def do_file (file_name, lang_codes, buildlib):
22 sys.stderr.write ('%s...\n' % file_name)
23 split_file_name = file_name.split ('/')
24 d1, d2 = split_file_name[0:2]
28 elif d2 in lang_codes:
34 raise Exception ('cannot determine language for ' + file_name)
36 original = dir_lang (file_name, '', lang_dir_index)
37 translated_contents = open (file_name).read ()
38 (diff_string, error) = buildlib.check_translated_doc (original, translated_contents, color=not update_mode)
41 sys.stderr.write ('warning: %s: %s' % (file_name, error))
44 if error or len (diff_string) >= os.path.getsize (original):
45 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
47 diff_file = original + '.diff'
48 f = open (diff_file, 'w')
51 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
54 sys.stdout.write (diff_string)
57 sys.stdout.write (r'''
59 check-translation [--language=LANG] [--verbose] [--update] FILE...
61 This script is licensed under the GNU GPL.
65 global lang, verbose, update_mode
67 p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
68 description="This script is licensed under the GNU GPL.")
69 p.add_option ("--language",
73 p.add_option ("--verbose",
77 help="the GIT directory to merge.")
78 p.add_option ('-u', "--update",
82 help='call $EDITOR to update the translation')
84 (options, files) = p.parse_args ()
85 verbose = options.verbose
86 lang = options.language
87 update_mode = options.update_mode
92 global update_mode, text_editor
95 if 'EDITOR' in os.environ:
96 text_editor = os.environ['EDITOR']
100 buildlib.verbose = verbose
103 do_file (i, langdefs.LANGDICT.keys (), buildlib)
105 if __name__ == '__main__':