12 def dir_lang (file, lang
, lang_dir_index
):
13 path_components
= file.split ('/')
14 path_components
[lang_dir_index
] = lang
15 return os
.path
.join (*path_components
)
17 def do_file (file_name
, lang_codes
, buildlib
):
19 sys
.stderr
.write ('%s...\n' % file_name
)
20 split_file_name
= file_name
.split ('/')
21 d1
, d2
= split_file_name
[0:2]
25 elif d2
in lang_codes
:
31 raise Exception ('cannot determine language for ' + file_name
)
33 original
= dir_lang (file_name
, '', lang_dir_index
)
34 translated_contents
= open (file_name
).read ()
35 (diff_string
, error
) = buildlib
.check_translated_doc (original
, translated_contents
, color
=not update_mode
)
38 sys
.stderr
.write ('warning: %s: %s' % (file_name
, error
))
41 if error
or len (diff_string
) >= os
.path
.getsize (original
):
42 buildlib
.read_pipe (text_editor
+ ' ' + file_name
+ ' ' + original
)
44 diff_file
= original
+ '.diff'
45 f
= open (diff_file
, 'w')
48 buildlib
.read_pipe (text_editor
+ ' ' + file_name
+ ' ' + diff_file
)
51 sys
.stdout
.write (diff_string
)
54 sys
.stdout
.write (r
'''
56 check-translation [--language=LANG] [--verbose] [--update] BUILDSCRIPT-DIR FILE...
58 This script is licensed under the GNU GPL.
62 global lang
, verbose
, update_mode
64 p
= optparse
.OptionParser (usage
="check-translation [--language=LANG] [--verbose] FILE...",
65 description
="This script is licensed under the GNU GPL.")
66 p
.add_option ("--language",
70 p
.add_option ("--verbose",
74 help="the GIT directory to merge.")
75 p
.add_option ('-u', "--update",
79 help='call $EDITOR to update the translation')
81 (options
, files
) = p
.parse_args ()
82 verbose
= options
.verbose
83 lang
= options
.language
84 update_mode
= options
.update_mode
86 return (files
[0], files
[1:])
89 global update_mode
, text_editor
91 import_path
, files
= do_options ()
92 if 'EDITOR' in os
.environ
:
93 text_editor
= os
.environ
['EDITOR']
97 sys
.path
.append (import_path
)
100 buildlib
.verbose
= verbose
103 do_file (i
, langdefs
.LANGDICT
.keys (), buildlib
)
105 if __name__
== '__main__':