konjac 0.2.5.2 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -39,20 +39,23 @@ Use multiple dictionaries:
39
39
  konjac translate financial_report_en.txt --to japanese --using {finance,fluffery}
40
40
  konjac translate financial_report_en.txt -t ja -u {finance,fluffery}
41
41
 
42
- Extract text from a .docx document (creates a plain-text <tt>test.konjac</tt> file from
43
- <tt>test.docx</tt>):
42
+ Extract text from a .docx? document (creates a plain-text <tt>test.konjac</tt>
43
+ file from <tt>test.docx</tt>):
44
44
 
45
- konjac export test
45
+ konjac export test.doc
46
+ konjac export test.docx
46
47
 
47
48
  Extract text from a .docx document and process with a dictionary
48
49
 
49
50
  konjac export test.docx --from japanese --to english --using pre
50
51
  konjac export test.docx -f ja -t en -u pre
51
52
 
52
- Import tags file back into .docx document (file created is named
53
+ Import tags file back into .docx document (for .doc files, this opens the file
54
+ in word and imports the changes; for .docx files this outputs a new file named
53
55
  <tt>test_imported.docx</tt>):
54
56
 
55
- konjac import test
57
+ konjac import test.doc
58
+ konjac import test.docx
56
59
 
57
60
  Add a word to your dictionary:
58
61
 
@@ -64,6 +67,11 @@ Translate a word using your dictionary:
64
67
  konjac translate dog --from english --to japanese --word
65
68
  konjac translate dog -f en -t ja -w
66
69
 
70
+ Suggest a word using your dictionary:
71
+
72
+ konjac suggest dog --from english --to japanese
73
+ konjac suggest dog -f en -t ja
74
+
67
75
  == Dictionary Format
68
76
 
69
77
  Store terms in <tt>~/.konjac/dict.yml</tt>.
data/konjac.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_runtime_dependency "amatch"
23
+ s.add_runtime_dependency "highline"
23
24
  s.add_runtime_dependency "i18n"
24
25
  s.add_runtime_dependency "nokogiri"
25
26
  s.add_runtime_dependency "sdoc"
@@ -1,10 +1,19 @@
1
1
  #!/usr/bin/osascript
2
+ -- round up ASCII characters used for formatting in Word
3
+ global bell
4
+ global line_feed
5
+ global form_feed
6
+ global carriage_return
7
+ global format_chars
8
+
9
+ -- strip line breaks and formatting characters
2
10
  to strip_line_breaks(this_line)
3
11
  try
4
- repeat while last character of this_line is in {ASCII character 13, ASCII character 10, ASCII character 7}
12
+ -- remove last character until no it's no longer an excluded character
13
+ repeat while last character of this_line is in format_chars
5
14
  set this_line to characters 1 thru -2 of this_line as string
6
15
  end repeat
7
- return this_line
16
+ return this_line as text
8
17
  on error
9
18
  return ""
10
19
  end try
@@ -14,60 +23,88 @@ to get_posix_path(mac_path)
14
23
  set result to POSIX path of mac_path
15
24
  end get_posix_path
16
25
 
17
- tell application "Microsoft Word"
18
- activate
19
- set active_document to active document
20
- set carriage_return to ASCII character 13
21
- set line_feed to ASCII character 10
22
- set ignored_content to {missing value, "", line_feed}
23
-
24
- -- set tags path to full path to active presentation with a .tags extension
25
- set tags_path to ((path of active_document) & ".diff")
26
-
27
- -- delete tags file if it already exists
28
- tell application "Finder"
29
- if exists file tags_path then
30
- delete file tags_path
31
- end if
32
- end tell
33
-
34
- -- open tags file for writing
35
- set tags_file to open for access file tags_path with write permission
36
- set eof of tags_file to 0
26
+ to extract(filename)
27
+ tell application "Microsoft Word"
28
+ activate
29
+ open filename
30
+ set active_document to active document
31
+ set ignored_content to {missing value, "", line_feed}
32
+
33
+ -- set tags path to full path to active presentation with a .tags extension
34
+ set tags_path to ((path of active_document) & ".diff")
35
+
36
+ -- delete tags file if it already exists
37
+ tell application "Finder"
38
+ if exists file tags_path then
39
+ delete file tags_path
40
+ end if
41
+ end tell
42
+
43
+ -- open tags file for writing
44
+ set tags_file to open for access file tags_path with write permission
45
+ set eof of tags_file to 0
46
+
47
+ write ("--- " & my get_posix_path(path of active_document)) to tags_file
48
+ write line_feed to tags_file
49
+ write ("+++ " & my get_posix_path(path of active_document)) to tags_file
50
+ write line_feed to tags_file
51
+
52
+ -- iterate through paragraphs
53
+ set paragraph_index to 1
54
+ set current_paragraph to paragraph 1 in active document
37
55
 
38
- write ("---" & my get_posix_path(path of active_document)) to tags_file
39
- write line_feed to tags_file
40
- write ("+++" & my get_posix_path(path of active_document)) to tags_file
41
- write line_feed to tags_file
56
+ -- save old delimiters
57
+
58
+ repeat
59
+ -- get text content if it's available
60
+ set text_content to my strip_line_breaks(content of text object of current_paragraph) as string
42
61
 
43
- -- iterate through paragraphs
44
- set paragraph_index to 1
45
- set current_paragraph to paragraph 1 in active document
46
-
47
- repeat
48
- -- get text content if it's available
49
- set text_content to my strip_line_breaks(content of text object of current_paragraph as text)
62
+ -- replace "soft returns" (vertical tabs) with real returns
63
+ set old_delimiters to AppleScript's text item delimiters
64
+ set AppleScript's text item delimiters to {ASCII character 11}
65
+ set split_content to every text item of text_content
66
+ set AppleScript's text item delimiters to old_delimiters
50
67
 
51
- if text_content is not in ignored_content then
52
- write ("@@ " & paragraph_index & " @@") to tags_file
53
- write line_feed to tags_file
54
- write ("-" & text_content) to tags_file as «class utf8»
55
- write line_feed to tags_file
56
- write ("+" & text_content) to tags_file as «class utf8»
57
- write line_feed to tags_file
58
- end if
68
+ if text_content is not in ignored_content then
69
+ write ("@@ " & paragraph_index & " @@") to tags_file
70
+ write line_feed to tags_file
71
+ repeat with text_line in split_content
72
+ write ("-" & text_line) to tags_file as «class utf8»
73
+ write line_feed to tags_file
74
+ end repeat
75
+ repeat with text_line in split_content
76
+ write ("+" & text_line) to tags_file as «class utf8»
77
+ write line_feed to tags_file
78
+ end repeat
79
+ end if
59
80
 
60
- -- increment paragraph index
61
- set paragraph_index to (paragraph_index + 1)
81
+ -- increment paragraph index
82
+ set paragraph_index to (paragraph_index + 1)
83
+
84
+ -- try to find the next paragraph
85
+ try
86
+ set current_paragraph to next paragraph of current_paragraph
87
+ on error
88
+ exit repeat
89
+ end try
90
+ end repeat
91
+
92
+ -- close everything
93
+ close access tags_file
94
+ end tell
95
+ end extract
96
+
97
+ -- initialize global variables, just formatting characters here
98
+ to init_globals()
99
+ set bell to ASCII character 7
100
+ set line_feed to ASCII character 10
101
+ set form_feed to ASCII character 12
102
+ set carriage_return to ASCII character 13
103
+ set format_chars to {bell, line_feed, form_feed, carriage_return}
104
+ end init_globals
62
105
 
63
- -- try to find the next paragraph
64
- try
65
- set current_paragraph to next paragraph of current_paragraph
66
- on error
67
- exit repeat
68
- end try
69
- end repeat
70
-
71
- -- close everything
72
- close access tags_file
73
- end tell
106
+ -- main()
107
+ on run argv
108
+ init_globals()
109
+ extract(item 1 of argv)
110
+ end
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/osascript
2
- set numbers_as_text to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
2
+ global numbers_as_text
3
+ global line_feed
4
+ global vertical_tab
5
+ global carriage_return
3
6
 
4
7
  -- parses the headers/separators inside the tags file
5
8
  to parse_header(header)
@@ -16,34 +19,87 @@ to get_posix_path(mac_path)
16
19
  set result to POSIX path of mac_path
17
20
  end get_posix_path
18
21
 
19
- tell application "Microsoft Word"
20
- activate
21
- set active_document to active document
22
- set carriage_return to ASCII character 13
23
- set line_feed to ASCII character 10
24
- set ignored_content to {missing value, "", line_feed}
25
-
26
- -- set tags path to full path to active presentation with a .tags extension
27
- set tags_path to ((path of active_document) & ".diff")
28
-
29
- -- read in tags
30
- set tags_file to open for access file tags_path
31
- set tags to (read tags_file for (get eof tags_file) as «class utf8» using delimiter line_feed)
32
- close access tags_file
33
-
34
- -- iterate through paragraphs
35
- set paragraph_index to 0
36
- repeat with current_line in tags
37
- if current_line starts with "@@ " then
38
- set space_offset to my parse_header(current_line)
39
- set paragraph_index to text 4 thru space_offset of current_line as number
40
- else if current_line starts with "+" then
41
- if paragraph_index is not 0 then
42
- set current_content to text object of paragraph paragraph_index of active document
43
- set my_range to create range active document start (start of content of current_content) end (end of content of current_content)
22
+ to import(filename)
23
+ tell application "Microsoft Word"
24
+ activate
25
+ open filename
26
+ set active_document to active document
27
+ set ignored_content to {missing value, "", line_feed}
28
+
29
+ -- set tags path to full path to active presentation with a .tags extension
30
+ set tags_path to ((path of active_document) & ".diff")
31
+
32
+ -- read in tags
33
+ set tags_file to open for access file tags_path
34
+ set tags to (read tags_file for (get eof tags_file) ¬
35
+ as «class utf8» using delimiter line_feed)
36
+ set tag_index to 0
37
+ set tag_length to length of tags
38
+ close access tags_file
39
+
40
+ set text_content to ""
41
+
42
+ -- iterate through paragraphs
43
+ set paragraph_index to 0
44
+ set prev_paragraph_index to 0
45
+ set is_new_tag to false
46
+
47
+ repeat with current_line in tags
48
+ if current_line starts with "@@ " then
49
+ set space_offset to my parse_header(current_line)
50
+ set paragraph_index to text 4 thru space_offset ¬
51
+ of current_line as number
52
+ set is_new_tag to true
53
+ else if current_line starts with "+" then
54
+ if paragraph_index is not 0 then
55
+ set prev_paragraph_index to paragraph_index
56
+
57
+ -- handle blank lines with soft returns
58
+ if current_line is "+"
59
+ set this_content to ""
60
+ else
61
+ set this_content to text 2 thru (length of current_line) ¬
62
+ of current_line
63
+ end if
64
+
65
+ -- add to text content, joining with a soft return for multiple lines
66
+ if text_content is "" then
67
+ set text_content to this_content
68
+ else
69
+ set text_content to (text_content & vertical_tab & this_content)
70
+ end if
71
+ set is_new_tag to false
72
+ end if
73
+ end if
74
+
75
+ -- increment tag index
76
+ set tag_index to tag_index + 1
77
+
78
+ -- write if we've moved to a new tag or reached the end of the file
79
+ if text_content is not "" and (tag_index is tag_length or is_new_tag)
80
+ set current_content to text object of paragraph prev_paragraph_index ¬
81
+ of active document
82
+ set my_range to create range active document ¬
83
+ start (start of content of current_content) ¬
84
+ end (end of content of current_content)
44
85
  select my_range
45
- type text selection text (text 2 thru (length of current_line) of current_line)
86
+ type text selection text text_content
87
+ set text_content to ""
46
88
  end if
47
- end if
48
- end repeat
49
- end tell
89
+ end repeat
90
+ end tell
91
+ end import
92
+
93
+ -- initialize global variables
94
+ to init_globals()
95
+ set numbers_as_text to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
96
+ set line_feed to ASCII character 10
97
+ set vertical_tab to ASCII character 11
98
+ set carriage_return to ASCII character 13
99
+ end init_globals
100
+
101
+ -- main()
102
+ on run argv
103
+ init_globals()
104
+ import(item 1 of argv)
105
+ end run
data/lib/konjac/cli.rb CHANGED
@@ -75,6 +75,7 @@ eos
75
75
  banner sc_banner % I18n.t(:filenames_arg)
76
76
  opt :from, I18n.t(:from, :scope => :opts), :type => :string
77
77
  opt :to, I18n.t(:to, :scope => :opts), :type => :string
78
+ opt :output, I18n.t(:output, :scope => :opts), :type => :string
78
79
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
79
80
  :default => "dict", :multi => true
80
81
  opt :help, I18n.t(:help, :scope => :opts)
@@ -82,14 +83,19 @@ eos
82
83
  if ARGV == ["doc"]
83
84
  system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_export")
84
85
  else
85
- Word.export_docx_tags ARGV, opts
86
+ Word.export_tags ARGV, opts
86
87
  end
87
88
  when "import"
88
- Trollop::options do
89
+ opts = Trollop::options do
89
90
  banner sc_banner % I18n.t(:filenames_arg)
91
+ opt :output, I18n.t(:output, :scope => :opts), :type => :string
90
92
  opt :help, I18n.t(:help, :scope => :opts)
91
93
  end
92
- Word.import_docx_tags ARGV
94
+ if ARGV == ["doc"]
95
+ system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_import")
96
+ else
97
+ Word.import_tags ARGV, opts
98
+ end
93
99
  when "language"
94
100
  Trollop::options do
95
101
  banner sc_banner % I18n.t(:word_arg)
@@ -117,6 +123,9 @@ eos
117
123
  banner sc_banner % I18n.t(:filenames_or_word_arg)
118
124
  opt :from, I18n.t(:from, :scope => :opts), :type => :string
119
125
  opt :to, I18n.t(:to, :scope => :opts), :type => :string
126
+ opt :output, I18n.t(:output, :scope => :opts), :type => :string
127
+ opt :force, I18n.t(:force, :scope => :opts), :default => false,
128
+ :short => :y
120
129
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
121
130
  :default => "dict", :multi => true
122
131
  opt :use_cache, I18n.t(:use_cache, :scope => :opts),
@@ -25,8 +25,17 @@ module Konjac
25
25
  end
26
26
  end
27
27
  end
28
- target = Utils.build_converted_file_name(source, from_lang, to_lang)
29
- FileUtils.mv temp_file.path, target
28
+
29
+ # Set output file
30
+ if opts[:output].nil?
31
+ target = source
32
+ else
33
+ target = File.expand_path(opts[:output])
34
+ end
35
+
36
+ if Utils.user_allows_overwrite?(target, opts)
37
+ FileUtils.mv temp_file.path, target
38
+ end
30
39
  end
31
40
  end
32
41
 
data/lib/konjac/utils.rb CHANGED
@@ -14,6 +14,20 @@ module Konjac
14
14
  end
15
15
  end
16
16
 
17
+ # Prompts user whether to overwrite the specified file. Passing
18
+ # <tt>:force => true</tt> after the filename will cause this message to
19
+ # be ignored and always return +true+
20
+ def user_allows_overwrite?(file, opts = {})
21
+ if File.exist?(File.expand_path(file)) && !opts[:force]
22
+ print I18n.t(:overwrite) % file
23
+ answer = HighLine::SystemExtensions.get_character.chr
24
+ puts answer
25
+ return answer =~ /^y/i
26
+ else
27
+ return true
28
+ end
29
+ end
30
+
17
31
  # Build converted file name by appending "_converted" to the file name
18
32
  def build_converted_file_name(source, from_lang, to_lang)
19
33
  # Get components of filename
@@ -1,4 +1,4 @@
1
1
  module Konjac
2
2
  # The current version number of Konjac
3
- VERSION = "0.2.5.2"
3
+ VERSION = "0.2.6"
4
4
  end
data/lib/konjac/word.rb CHANGED
@@ -5,51 +5,58 @@ module Konjac
5
5
  class << self
6
6
  # Imports the text content of a tag file into a {Microsoft
7
7
  # Word}[http://office.microsoft.com/en-us/word/] 2003+ document
8
- def import_docx_tags(files)
9
- sub_files = Utils.parse_files(files, :extension => :docx)
8
+ def import_tags(files)
9
+ sub_files = Utils.parse_files(files)
10
10
  sub_files.each do |sub_file|
11
- # Build the list of paths we need to work with
12
- dirname = File.dirname(sub_file)
13
- basename = File.basename(sub_file, ".*")
14
- orig_docx = "#{dirname}/#{basename}.docx"
15
- new_path = "#{dirname}/#{basename}_imported.docx"
16
- xml_path = "#{dirname}/#{basename}.xml"
17
- tags_path = "#{dirname}/#{basename}.diff"
18
- out_path = "#{dirname}/word/document.xml"
19
-
20
- # Open the original XML file and the updated tags
21
- writer = Nokogiri::XML(File.read(xml_path))
22
- nodes = writer.xpath("//w:t")
23
- tags = TagManager.new(tags_path)
24
-
25
- # Overwrite each <w:t> tag's content with the new tag
26
- tags.all.each do |tag|
27
- if tag.translated?
28
- nodes[tag.index].content = tag.translated
11
+ case File.extname(sub_file)
12
+ when ".doc"
13
+ system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_import"), sub_file
14
+ when ".docx"
15
+ # Build the list of paths we need to work with
16
+ dirname = File.dirname(sub_file)
17
+ basename = File.basename(sub_file, ".*")
18
+ orig_docx = "#{dirname}/#{basename}.docx"
19
+ new_path = "#{dirname}/#{basename}_imported.docx"
20
+ xml_path = "#{dirname}/#{basename}.xml"
21
+ tags_path = "#{dirname}/#{basename}.diff"
22
+ out_path = "#{dirname}/word/document.xml"
23
+
24
+ # Open the original XML file and the updated tags
25
+ writer = Nokogiri::XML(File.read(xml_path))
26
+ nodes = writer.xpath("//w:t")
27
+ tags = TagManager.new(tags_path)
28
+
29
+ # Overwrite each <w:t> tag's content with the new tag
30
+ tags.all.each do |tag|
31
+ if tag.translated?
32
+ nodes[tag.index].content = tag.translated
33
+ end
29
34
  end
30
- end
31
35
 
32
- # Create a directory for word/document.xml if necessary
33
- unless File.directory?("#{dirname}/word")
34
- FileUtils.mkdir "#{dirname}/word"
35
- end
36
+ # Create a directory for word/document.xml if necessary
37
+ unless File.directory?("#{dirname}/word")
38
+ FileUtils.mkdir "#{dirname}/word"
39
+ end
36
40
 
37
- # Write the modified XML to a file
38
- File.open(out_path, "w") do |file|
39
- file.write writer.to_xml.gsub(/\n\s*/, "").sub(/\?></, "?>\n<")
40
- end
41
+ # Write the modified XML to a file
42
+ File.open(out_path, "w") do |file|
43
+ file.write writer.to_xml.gsub(/\n\s*/, "").sub(/\?></, "?>\n<")
44
+ end
41
45
 
42
- # Copy the original file
43
- FileUtils.cp orig_docx, new_path
46
+ # Copy the original file
47
+ FileUtils.cp orig_docx, new_path
44
48
 
45
- # Add the new document XML to the copied file
46
- system "cd #{dirname} && zip -q #{new_path} word/document.xml"
49
+ # Add the new document XML to the copied file
50
+ system "cd #{dirname} && zip -q #{new_path} word/document.xml"
51
+ else
52
+ puts I18n.t(:unknown) % sub_file
53
+ end
47
54
  end
48
55
  end
49
56
 
50
57
  # Exports the text content of {Microsoft
51
- # Word}[http://office.microsoft.com/en-us/word/] 2003+ document
52
- def export_docx_tags(files, opts = {})
58
+ # Word}[http://office.microsoft.com/en-us/word/] documents
59
+ def export_tags(files, opts = {})
53
60
  # Determine whether to attempt translating
54
61
  if opts[:from_given] && opts[:to_given]
55
62
  from_lang = Language.find(opts[:from])
@@ -60,60 +67,67 @@ module Konjac
60
67
  end
61
68
  end
62
69
 
63
- sub_files = Utils.parse_files(files, :extension => :docx)
70
+ sub_files = Utils.parse_files(files)
64
71
  sub_files.each do |sub_file|
65
- # Build a list of all the paths we're working with
66
- dirname = File.dirname(sub_file)
67
- basename = File.basename(sub_file, ".*")
68
- orig_docx = "#{dirname}/#{basename}.docx"
69
- xml_path = "#{dirname}/#{basename}_orig.xml"
70
- clean_path = "#{dirname}/#{basename}.xml"
71
- tags_path = "#{dirname}/#{basename}.diff"
72
-
73
- # Unzip the DOCX's word/document.xml file and pipe the output into
74
- # an XML with the same base name as the DOCX
75
- system "unzip -p #{orig_docx} word/document.xml > #{xml_path}"
76
-
77
- # Read in the XML file and extract the content from each <w:t> tag
78
- cleaner = Nokogiri::XML(File.read(xml_path))
79
- File.open(tags_path, "w") do |tags_file|
80
- # Remove all grammar and spellcheck tags
81
- cleaner.xpath("//w:proofErr").remove
82
-
83
- nodes = cleaner.xpath("//w:r")
84
- prev = nil
85
- nodes.each do |node|
86
- unless prev.nil?
87
- if (prev.next_sibling == node) && compare_nodes(prev, node)
88
- begin
89
- node.at_xpath("w:t").content = prev.at_xpath("w:t").content +
90
- node.at_xpath("w:t").content
91
- prev.remove
92
- rescue
72
+ case File.extname(sub_file)
73
+ when ".doc"
74
+ system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_export"), sub_file
75
+ when ".docx"
76
+ # Build a list of all the paths we're working with
77
+ dirname = File.dirname(sub_file)
78
+ basename = File.basename(sub_file, ".*")
79
+ orig_docx = "#{dirname}/#{basename}.docx"
80
+ xml_path = "#{dirname}/#{basename}_orig.xml"
81
+ clean_path = "#{dirname}/#{basename}.xml"
82
+ tags_path = "#{dirname}/#{basename}.diff"
83
+
84
+ # Unzip the DOCX's word/document.xml file and pipe the output into
85
+ # an XML with the same base name as the DOCX
86
+ system "unzip -p #{orig_docx} word/document.xml > #{xml_path}"
87
+
88
+ # Read in the XML file and extract the content from each <w:t> tag
89
+ cleaner = Nokogiri::XML(File.read(xml_path))
90
+ File.open(tags_path, "w") do |tags_file|
91
+ # Remove all grammar and spellcheck tags
92
+ cleaner.xpath("//w:proofErr").remove
93
+
94
+ nodes = cleaner.xpath("//w:r")
95
+ prev = nil
96
+ nodes.each do |node|
97
+ unless prev.nil?
98
+ if (prev.next_sibling == node) && compare_nodes(prev, node)
99
+ begin
100
+ node.at_xpath("w:t").content = prev.at_xpath("w:t").content +
101
+ node.at_xpath("w:t").content
102
+ prev.remove
103
+ rescue
104
+ end
93
105
  end
94
106
  end
107
+
108
+ prev = node
95
109
  end
96
-
97
- prev = node
98
- end
99
110
 
100
- # Write the tags file
101
- tags_file.puts "---" + orig_docx
102
- tags_file.puts "+++" + orig_docx
103
- cleaner.xpath("//w:t").each_with_index do |node, index|
104
- tags_file.puts "@@ %i @@" % [index, additional_info(node)]
105
- tags_file.puts "-" + node.content
106
- if attempting_to_translate
107
- tags_file.puts "+" + Translator.translate_content(node.content)
108
- else
109
- tags_file.puts "+" + node.content
111
+ # Write the tags file
112
+ tags_file.puts "---" + orig_docx
113
+ tags_file.puts "+++" + orig_docx
114
+ cleaner.xpath("//w:t").each_with_index do |node, index|
115
+ tags_file.puts "@@ %i @@" % [index, additional_info(node)]
116
+ tags_file.puts "-" + node.content
117
+ if attempting_to_translate
118
+ tags_file.puts "+" + Translator.translate_content(node.content)
119
+ else
120
+ tags_file.puts "+" + node.content
121
+ end
110
122
  end
111
123
  end
112
- end
113
124
 
114
- # Write the cleaned-up XML to a file for inspection
115
- File.open(clean_path, "w") do |xml|
116
- xml.puts cleaner.to_xml
125
+ # Write the cleaned-up XML to a file for inspection
126
+ File.open(clean_path, "w") do |xml|
127
+ xml.puts cleaner.to_xml
128
+ end
129
+ else
130
+ puts I18n.t(:unknown) % sub_file
117
131
  end
118
132
  end
119
133
  end
data/lib/konjac.rb CHANGED
@@ -2,6 +2,7 @@ require "konjac/version"
2
2
  require "konjac/exception"
3
3
  autoload :Amatch, "amatch"
4
4
  autoload :FileUtils, "fileutils"
5
+ autoload :HighLine, "highline/system_extensions"
5
6
  autoload :I18n, "i18n"
6
7
  autoload :Nokogiri, "nokogiri"
7
8
  autoload :Tempfile, "tempfile"
data/lib/locales/en.yml CHANGED
@@ -4,6 +4,7 @@ en:
4
4
  filenames_or_word_arg: <filenames>+ OR <text>
5
5
  me: Bryan McKelvey
6
6
  options: options
7
+ overwrite: "Overwrite %s? (y/n [n]) "
7
8
  subcommand: subcommand
8
9
  unknown_subcommand: "Unknown subcommand: %s"
9
10
  usage: "Usage:"
@@ -13,9 +14,12 @@ en:
13
14
  opts:
14
15
  dry_run: Don't actually do anything
15
16
  editor: A command to run to pass the file to an editor (e.g. vi %s)
17
+ force: Automatically overwrite files
16
18
  from: The language from which to translate
17
19
  help: Show this message
18
20
  original: The untranslated original text
21
+ output: The name of the output file
22
+ prompt: Prompt before overwriting a file
19
23
  quiet: Suppress error messages
20
24
  to: The language into which to translate
21
25
  translation: The translated text
data/lib/locales/ja.yml CHANGED
@@ -4,6 +4,7 @@ ja:
4
4
  filenames_or_word_arg: <ファイル名>+ または <テキスト>
5
5
  me: ブライアン・マッケルビー
6
6
  options: オプション
7
+ overwrite: "%sを上書しますか。 (y/n [n]) "
7
8
  subcommand: サブコマンド
8
9
  unknown_subcommand: 不明なサブコマンド:%s
9
10
  usage: 使い方:
@@ -13,9 +14,12 @@ ja:
13
14
  opts:
14
15
  dry_run: 実際には何も出力しない
15
16
  editor: 結果ファイルをエディターで開くコマンド(例:vi %s)
17
+ force: 自動にファイルを上書する
16
18
  from: ソース言語
17
19
  help: このメッセージを表示する
18
20
  original: ソーステキスト
21
+ output: 出力ファイル名
22
+ prompt: ファイルをする場合に警告する
19
23
  quiet: エラーメッセージを抑止する
20
24
  to: ターゲット言語
21
25
  translation: ターゲットテキスト
data/spec/cli_spec.rb CHANGED
@@ -31,16 +31,17 @@ describe CLI do
31
31
  @english.write "I like dogs."
32
32
  @english.rewind
33
33
 
34
+ @converted = Utils.build_converted_file_name(@english.path, "en", "ja")
35
+
34
36
  # Set ARGV
35
37
  set_argv "translate", "-t", "japanese", "-u", @dictionary.path,
36
- @english.path
38
+ @english.path, "-y", "-o", @converted
37
39
  end
38
40
 
39
41
  it "should correctly translate English text" do
40
42
  CLI.start
41
- converted_path = Utils.build_converted_file_name(@english.path, "en", "ja")
42
43
  File.read(@english.path).should == "I like dogs."
43
- File.open(converted_path, "r") do |file|
44
+ File.open(@converted, "r") do |file|
44
45
  file.each do |line|
45
46
  line.chomp.should == "I like 犬."
46
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konjac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.2
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amatch
16
- requirement: &70206891941760 !ruby/object:Gem::Requirement
16
+ requirement: &70281458370660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70206891941760
24
+ version_requirements: *70281458370660
25
+ - !ruby/object:Gem::Dependency
26
+ name: highline
27
+ requirement: &70281458369820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70281458369820
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: i18n
27
- requirement: &70206891941140 !ruby/object:Gem::Requirement
38
+ requirement: &70281458368920 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70206891941140
46
+ version_requirements: *70281458368920
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: nokogiri
38
- requirement: &70206891940480 !ruby/object:Gem::Requirement
49
+ requirement: &70281458368020 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *70206891940480
57
+ version_requirements: *70281458368020
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: sdoc
49
- requirement: &70206891939860 !ruby/object:Gem::Requirement
60
+ requirement: &70281458367420 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :runtime
56
67
  prerelease: false
57
- version_requirements: *70206891939860
68
+ version_requirements: *70281458367420
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: term-ansicolor
60
- requirement: &70206891939240 !ruby/object:Gem::Requirement
71
+ requirement: &70281458366840 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :runtime
67
78
  prerelease: false
68
- version_requirements: *70206891939240
79
+ version_requirements: *70281458366840
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: trollop
71
- requirement: &70206891955060 !ruby/object:Gem::Requirement
82
+ requirement: &70281458366420 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :runtime
78
89
  prerelease: false
79
- version_requirements: *70206891955060
90
+ version_requirements: *70281458366420
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: autotest
82
- requirement: &70206891954560 !ruby/object:Gem::Requirement
93
+ requirement: &70281458365940 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70206891954560
101
+ version_requirements: *70281458365940
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: autotest-fsevent
93
- requirement: &70206891954040 !ruby/object:Gem::Requirement
104
+ requirement: &70281458365500 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70206891954040
112
+ version_requirements: *70281458365500
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: autotest-growl
104
- requirement: &70206891953400 !ruby/object:Gem::Requirement
115
+ requirement: &70281458365000 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70206891953400
123
+ version_requirements: *70281458365000
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: bundler
115
- requirement: &70206891952540 !ruby/object:Gem::Requirement
126
+ requirement: &70281458364500 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: '0'
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70206891952540
134
+ version_requirements: *70281458364500
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: rspec
126
- requirement: &70206891952120 !ruby/object:Gem::Requirement
137
+ requirement: &70281458363800 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,7 +142,7 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *70206891952120
145
+ version_requirements: *70281458363800
135
146
  description: A Ruby command-line utility for translating files using a YAML wordlist
136
147
  email:
137
148
  - bryan.mckelvey@gmail.com