konjac 0.1.6.2 → 0.1.6.3

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/lib/konjac/cli.rb CHANGED
@@ -59,11 +59,15 @@ eos
59
59
  opt :editor, "A command indicating which editor to use (e.g. vi %s)"
60
60
  end
61
61
  Word.edit_docx_tags ARGV, opts
62
- when "extract", "export"
63
- Trollop::options do
62
+ when "export"
63
+ opts = Trollop::options do
64
64
  banner sc_banner
65
+ opt :from, "The language from which to translate", :type => :string
66
+ opt :to, "The language into which to translate", :type => :string
67
+ opt :using, "The names of dictionaries to use", :type => :string,
68
+ :default => "dict", :multi => true
65
69
  end
66
- Word.extract_docx_tags ARGV
70
+ Word.export_docx_tags ARGV, opts
67
71
  when "import"
68
72
  Trollop::options do
69
73
  banner sc_banner
@@ -86,7 +86,9 @@ module Konjac
86
86
  def verify_dictionary_exists(full_path)
87
87
  unless File.file?(full_path)
88
88
  FileUtils.mkpath File.dirname(full_path)
89
- FileUtils.touch full_path
89
+ File.open(full_path, "w") do |file|
90
+ file.puts "--- []"
91
+ end
90
92
  end
91
93
  end
92
94
 
@@ -128,6 +130,7 @@ module Konjac
128
130
 
129
131
  dictionaries.each do |path|
130
132
  dict = ::YAML.load_file(path)
133
+ puts dict
131
134
  found = false
132
135
  dict.each do |term|
133
136
  if term.has_key?(to_lang)
@@ -235,8 +238,10 @@ module Konjac
235
238
  full_path = File.expand_path("~/.konjac/#{file}.yml")
236
239
  end
237
240
 
238
- if File.basename(file) =~ /\*/
239
- FileUtils.touch full_path unless File.exists?(full_path)
241
+ unless File.basename(file) =~ /\*/ || File.exists?(full_path)
242
+ File.open(full_path, "w") do |file|
243
+ file.puts "--- []"
244
+ end
240
245
  end
241
246
 
242
247
  paths += Dir.glob(full_path)
@@ -17,12 +17,16 @@ module Konjac
17
17
  end
18
18
  end
19
19
 
20
+ # Loads the dictionary, then translates a word or phrase from the
21
+ # specified language into another language
20
22
  def translate_word(word, from_lang, to_lang, opts = {})
21
23
  load_dictionary from_lang, to_lang, opts
22
24
 
23
25
  translate_content word
24
26
  end
25
27
 
28
+ # Translates content according to the current dictionaries and to/from
29
+ # languages
26
30
  def translate_content(content)
27
31
  @pairs.each do |pair|
28
32
  search, replace = pair
@@ -32,8 +36,7 @@ module Konjac
32
36
  content
33
37
  end
34
38
 
35
- private
36
-
39
+ # Loads the parsed contents of a dictionary into the translator
37
40
  def load_dictionary(from_lang, to_lang, opts)
38
41
  @pairs = Dictionary.load(from_lang, to_lang, opts)
39
42
  end
@@ -1,3 +1,3 @@
1
1
  module Konjac
2
- VERSION = "0.1.6.2"
2
+ VERSION = "0.1.6.3"
3
3
  end
data/lib/konjac/word.rb CHANGED
@@ -5,7 +5,7 @@ module Konjac
5
5
  class << self
6
6
  # Extracts the text content from a Microsoft Word 2003+ Document
7
7
  def import_docx_tags(files)
8
- sub_files = Utils.force_extension(files, ".docx")
8
+ sub_files = Utils.parse_files(files, ".docx")
9
9
  sub_files.each do |sub_file|
10
10
  # Build the list of paths we need to work with
11
11
  dirname = File.dirname(sub_file)
@@ -46,9 +46,19 @@ module Konjac
46
46
  end
47
47
  end
48
48
 
49
- # Extracts the text content from a Microsoft Word 2003+ Document
50
- def extract_docx_tags(files)
51
- sub_files = Utils.force_extension(files, ".docx")
49
+ # Exports the text content from a Microsoft Word 2003+ Document
50
+ def export_docx_tags(files, opts = {})
51
+ # Determine whether to attempt translating
52
+ if opts[:from_given] && opts[:to_given]
53
+ from_lang = Language.find(opts[:from])
54
+ to_lang = Language.find(opts[:to])
55
+ unless from_lang.nil? || to_lang.nil?
56
+ Translator.load_dictionary from_lang, to_lang, opts
57
+ attempting_to_translate = true
58
+ end
59
+ end
60
+
61
+ sub_files = Utils.parse_files(files, ".docx")
52
62
  sub_files.each do |sub_file|
53
63
  # Build a list of all the paths we're working with
54
64
  dirname = File.dirname(sub_file)
@@ -87,9 +97,15 @@ module Konjac
87
97
 
88
98
  # Write the tags file
89
99
  index = 0
100
+
90
101
  cleaner.xpath("//w:t").each do |node|
91
102
  tags_file.puts "[[KJ-%i]]%s" % [index, additional_info(node)]
92
103
  tags_file.puts "> %s" % node.content
104
+ if attempting_to_translate
105
+ tags_file.puts Translator.translate_content(node.content)
106
+ else
107
+ tags_file.puts node.content
108
+ end
93
109
  index += 1
94
110
  end
95
111
  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.1.6.2
4
+ version: 0.1.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-15 00:00:00.000000000 Z
12
+ date: 2012-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70333404173540 !ruby/object:Gem::Requirement
16
+ requirement: &70141602595920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70333404173540
24
+ version_requirements: *70141602595920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: term-ansicolor
27
- requirement: &70333404173120 !ruby/object:Gem::Requirement
27
+ requirement: &70141602595480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70333404173120
35
+ version_requirements: *70141602595480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: trollop
38
- requirement: &70333404172700 !ruby/object:Gem::Requirement
38
+ requirement: &70141602595060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70333404172700
46
+ version_requirements: *70141602595060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: autotest
49
- requirement: &70333404172280 !ruby/object:Gem::Requirement
49
+ requirement: &70141602594640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70333404172280
57
+ version_requirements: *70141602594640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: autotest-fsevent
60
- requirement: &70333404171800 !ruby/object:Gem::Requirement
60
+ requirement: &70141602594220 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70333404171800
68
+ version_requirements: *70141602594220
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: autotest-growl
71
- requirement: &70333404171320 !ruby/object:Gem::Requirement
71
+ requirement: &70141602593800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70333404171320
79
+ version_requirements: *70141602593800
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bundler
82
- requirement: &70333404199700 !ruby/object:Gem::Requirement
82
+ requirement: &70141602593380 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70333404199700
90
+ version_requirements: *70141602593380
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &70333404199280 !ruby/object:Gem::Requirement
93
+ requirement: &70141602614720 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70333404199280
101
+ version_requirements: *70141602614720
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sdoc
104
- requirement: &70333404198780 !ruby/object:Gem::Requirement
104
+ requirement: &70141602614300 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70333404198780
112
+ version_requirements: *70141602614300
113
113
  description: A Ruby command-line utility for translating files using a YAML wordlist
114
114
  email:
115
115
  - bryan.mckelvey@gmail.com