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
) = buildlib
.check_translated_doc (original
, translated_contents
, color
=use_colors
and not update_mode
)
42 sys
.stderr
.write ('warning: %s: %s' % (file_name
, error
))
45 if error
or len (diff_string
) >= os
.path
.getsize (original
):
46 buildlib
.read_pipe (text_editor
+ ' ' + file_name
+ ' ' + original
)
48 diff_file
= original
+ '.diff'
49 f
= open (diff_file
, 'w')
52 buildlib
.read_pipe (text_editor
+ ' ' + file_name
+ ' ' + diff_file
)
55 sys
.stdout
.write (diff_string
)
58 sys
.stdout
.write (r
'''
60 check-translation [--language=LANG] [--verbose] [--update] FILE...
62 This script is licensed under the GNU GPL.
66 global lang
, verbose
, update_mode
, use_colors
68 p
= optparse
.OptionParser (usage
="check-translation [--language=LANG] [--verbose] FILE...",
69 description
="This script is licensed under the GNU GPL.")
70 p
.add_option ("--language",
74 p
.add_option ("--no-color",
78 help="do not print ANSI-cooured output")
79 p
.add_option ("--verbose",
83 help="print details, including executed shell commands")
84 p
.add_option ('-u', "--update",
88 help='call $EDITOR to update the translation')
90 (options
, files
) = p
.parse_args ()
91 verbose
= options
.verbose
92 lang
= options
.language
93 use_colors
= options
.color
94 update_mode
= options
.update_mode
99 global update_mode
, text_editor
101 files
= do_options ()
102 if 'EDITOR' in os
.environ
:
103 text_editor
= os
.environ
['EDITOR']
107 buildlib
.verbose
= verbose
110 do_file (i
, langdefs
.LANGDICT
.keys (), buildlib
)
112 if __name__
== '__main__':