konjac 0.2.6.3 → 0.2.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/konjac/cli.rb CHANGED
@@ -12,8 +12,8 @@ module Konjac
12
12
 
13
13
  class << self
14
14
  # A list of valid subcommands
15
- SUB_COMMANDS = ["add", "edit", "export", "import", "language", "suggest",
16
- "translate"]
15
+ SUB_COMMANDS = ["add", "edit", "export", "import", "language", "list",
16
+ "suggest", "translate", "use"]
17
17
 
18
18
  # The banner to displaying when requesting help through the command line
19
19
  BANNER = <<-eos
@@ -48,7 +48,7 @@ eos
48
48
 
49
49
  # Get subcommand
50
50
  cmd = ARGV.shift
51
- ARGV << "-h" if ARGV.empty?
51
+ ARGV << "-h" if ARGV.empty? && cmd != "list"
52
52
  sc_banner = BANNER % [I18n.t(cmd, :scope => :subcommands), cmd, "%s", "\n"]
53
53
  cmd_opts = case cmd
54
54
  when "add"
@@ -59,7 +59,7 @@ eos
59
59
  opt :from, I18n.t(:from, :scope => :opts), :type => :string
60
60
  opt :to, I18n.t(:to, :scope => :opts), :type => :string
61
61
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
62
- :default => "dict", :multi => true
62
+ :default => Config.dictionary, :multi => true
63
63
  opt :help, I18n.t(:help, :scope => :opts)
64
64
  end
65
65
  Dictionary.add_word opts
@@ -79,25 +79,17 @@ eos
79
79
  opt :force, I18n.t(:force, :scope => :opts), :default => false,
80
80
  :short => :y
81
81
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
82
- :default => "dict", :multi => true
82
+ :default => Config.dictionary, :multi => true
83
83
  opt :help, I18n.t(:help, :scope => :opts)
84
84
  end
85
- if ARGV == ["doc"]
86
- system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_export")
87
- else
88
- Word.export_tags ARGV, opts
89
- end
85
+ Word.export_tags ARGV, opts
90
86
  when "import"
91
87
  opts = Trollop::options do
92
88
  banner sc_banner % I18n.t(:filenames_arg)
93
89
  opt :output, I18n.t(:output, :scope => :opts), :type => :string
94
90
  opt :help, I18n.t(:help, :scope => :opts)
95
91
  end
96
- if ARGV == ["doc"]
97
- system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_import")
98
- else
99
- Word.import_tags ARGV, opts
100
- end
92
+ Word.import_tags ARGV, opts
101
93
  when "language"
102
94
  Trollop::options do
103
95
  banner sc_banner % I18n.t(:word_arg)
@@ -105,13 +97,21 @@ eos
105
97
  end
106
98
  Config.language = ARGV[0]
107
99
  Config.save
100
+ when "list"
101
+ Trollop::options do
102
+ banner sc_banner % I18n.t(:word_arg)
103
+ opt :help, I18n.t(:help, :scope => :opts)
104
+ end
105
+ Config.list.each do |line|
106
+ puts line
107
+ end
108
108
  when "suggest"
109
109
  opts = Trollop::options do
110
110
  banner sc_banner % I18n.t(:word_arg)
111
111
  opt :from, I18n.t(:from, :scope => :opts), :type => :string
112
112
  opt :to, I18n.t(:to, :scope => :opts), :type => :string
113
113
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
114
- :default => "dict", :multi => true
114
+ :default => Config.dictionary, :multi => true
115
115
  opt :use_cache, I18n.t(:use_cache, :scope => :opts),
116
116
  :default => false, :short => :c
117
117
  opt :help, I18n.t(:help, :scope => :opts)
@@ -129,7 +129,7 @@ eos
129
129
  opt :force, I18n.t(:force, :scope => :opts), :default => false,
130
130
  :short => :y
131
131
  opt :using, I18n.t(:using, :scope => :opts), :type => :string,
132
- :default => "dict", :multi => true
132
+ :default => Config.dictionary, :multi => true
133
133
  opt :use_cache, I18n.t(:use_cache, :scope => :opts),
134
134
  :default => false, :short => :c
135
135
  opt :word, I18n.t(:word, :scope => :opts), :default => false
@@ -137,6 +137,12 @@ eos
137
137
  end
138
138
  result = translate(ARGV, opts)
139
139
  puts result if opts[:word]
140
+ when "use"
141
+ Trollop::options do
142
+ banner sc_banner % I18n.t(:word_arg)
143
+ opt :help, I18n.t(:help, :scope => :opts)
144
+ end
145
+ Config.use ARGV[0]
140
146
  else
141
147
  if global_opts[:quiet]
142
148
  raise SystemExit
data/lib/konjac/config.rb CHANGED
@@ -18,6 +18,38 @@ module Konjac
18
18
  save
19
19
  end
20
20
 
21
+ # Lists the dictionaries available in <tt>~/.konjac/*.yml</tt>
22
+ def list
23
+ lines = []
24
+ current_found = false
25
+ Dir[File.expand_path("~/.konjac/*.yml")].each do |dict|
26
+ name = File.basename(dict, ".*")
27
+ unless name == "config"
28
+ current_found = true
29
+ lines << "%s %s" % [current?(name) ? "***" : " ", name]
30
+ end
31
+ end
32
+ lines << "*** %s" % dictionary unless current_found
33
+ lines
34
+ end
35
+
36
+ # The current dictionary
37
+ def dictionary
38
+ @config[:dict] || "dict"
39
+ end
40
+
41
+ # Determines whether the specified name of a dictionary is the one
42
+ # currently set as the default
43
+ def current?(dict)
44
+ dict == dictionary
45
+ end
46
+
47
+ # Specifies the name of the dictionary to use
48
+ def use(dict)
49
+ @config[:dict] = dict.to_s unless dict.to_s == "config"
50
+ save
51
+ end
52
+
21
53
  # The current interface language
22
54
  def language
23
55
  I18n.locale
data/lib/konjac/utils.rb CHANGED
@@ -45,6 +45,7 @@ module Konjac
45
45
  def parse_files(files, opts = {})
46
46
  opts = { :extension => nil, :directory => nil }.merge opts
47
47
  files = [files] unless files.is_a?(Array)
48
+ search_text = files.join(" ")
48
49
  parsed_files = []
49
50
  while !files.empty?
50
51
  file = files.shift
@@ -56,6 +57,7 @@ module Konjac
56
57
  end
57
58
  parsed_files += Dir.glob(File.expand_path(file))
58
59
  end
60
+ puts I18n.t(:no_match) % search_text if parsed_files.empty?
59
61
  parsed_files.uniq
60
62
  end
61
63
 
@@ -1,4 +1,4 @@
1
1
  module Konjac
2
2
  # The current version number of Konjac
3
- VERSION = "0.2.6.3"
3
+ VERSION = "0.2.6.4"
4
4
  end
data/lib/konjac/word.rb CHANGED
@@ -7,6 +7,7 @@ module Konjac
7
7
  # Word}[http://office.microsoft.com/en-us/word/] 2003+ document
8
8
  def import_tags(files, opts = {})
9
9
  sub_files = Utils.parse_files(files)
10
+ return if sub_files.empty?
10
11
  sub_files.each do |sub_file|
11
12
  case File.extname(sub_file)
12
13
  when ".doc"
@@ -68,6 +69,7 @@ module Konjac
68
69
  end
69
70
 
70
71
  sub_files = Utils.parse_files(files)
72
+ return if sub_files.empty?
71
73
  sub_files.each do |sub_file|
72
74
  case File.extname(sub_file)
73
75
  when ".doc"
data/lib/locales/en.yml CHANGED
@@ -3,6 +3,7 @@ en:
3
3
  filenames_arg: <filenames>+
4
4
  filenames_or_word_arg: <filenames>+ OR <text>
5
5
  me: Bryan McKelvey
6
+ no_match: "No files matching \"%s\" found!"
6
7
  options: options
7
8
  overwrite: "Overwrite %s? (y/n [n]) "
8
9
  subcommand: subcommand
@@ -29,9 +30,11 @@ en:
29
30
  word: Translate a word or phrase
30
31
  subcommands:
31
32
  add: Add a definition to translation memory
32
- edit: Edit the tags file for a .docx file
33
- export: Export text tags from a .docx file
34
- import: Import text tags into a .docx file
33
+ edit: Edit the tags file for a .doc or .docx file
34
+ export: Export text tags from a .doc or .docx file
35
+ import: Import text tags into a .doc or .docx file
35
36
  language: Sets the default language
37
+ list: List available dictionaries
36
38
  suggest: Suggest similar words using fuzzy matching
37
39
  translate: Translate a file, word or phrase
40
+ use: Choose a default dictionary
data/lib/locales/ja.yml CHANGED
@@ -3,6 +3,7 @@ ja:
3
3
  filenames_arg: <ファイル名>+
4
4
  filenames_or_word_arg: <ファイル名>+ または <テキスト>
5
5
  me: ブライアン・マッケルビー
6
+ no_match: "「%s」をマッチするファイルは存在しません。"
6
7
  options: オプション
7
8
  overwrite: "%sを上書きしますか。 (y/n [n]) "
8
9
  subcommand: サブコマンド
@@ -29,9 +30,11 @@ ja:
29
30
  word: 文字列を翻訳する
30
31
  subcommands:
31
32
  add: 翻訳メモリに定義を追加する
32
- edit: .docxファイルに当たるタグファイルを編集する
33
- export: .docxファイルからタグを抽出する
34
- import: .docxファイルにタグをインポートする
33
+ edit: .docまたは.docxファイルに当たるタグファイルを編集する
34
+ export: .docまたは.docxファイルからタグを抽出する
35
+ import: .docまたは.docxファイルにタグをインポートする
35
36
  language: 言語を設定する
36
- suggest: Suggest similar words
37
+ list: List available dictionaries
38
+ suggest: ファジーマッチングで似た言葉をサジェストする
37
39
  translate: ファイル・文字列を翻訳する
40
+ use: Choose a default dictionary
data/spec/config_spec.rb CHANGED
@@ -10,32 +10,44 @@ describe Konjac::Config do
10
10
  @env_language = ENV["LANG"]
11
11
  end
12
12
 
13
+ # Restore the original configuration file
13
14
  after :all do
14
15
  FileUtils.mv @backup_path, @config_path if File.exists?(@backup_path)
15
16
  ENV["LANG"] = @env_language || ""
16
17
  end
17
18
 
18
- before :each do
19
- File.open(@config_path, "w") do |file|
20
- file.puts "--- {}"
19
+ describe "when the configuration file is blank" do
20
+ # Create a new configuration file before each test
21
+ before :each do
22
+ File.open(@config_path, "w") do |file|
23
+ file.puts "--- {}"
24
+ end
21
25
  end
22
- end
23
26
 
24
- it "should default to English when no system language is found" do
25
- ENV["LANG"] = ""
26
- Konjac::Config.load
27
- Konjac::Config.language.should == :en
28
- end
27
+ it "should default to English when no system language is found" do
28
+ ENV["LANG"] = ""
29
+ Konjac::Config.load
30
+ Konjac::Config.language.should == :en
31
+ end
29
32
 
30
- it "should default to English when specified" do
31
- ENV["LANG"] = "en"
32
- Konjac::Config.load
33
- Konjac::Config.language.should == :en
34
- end
33
+ it "should default to English when specified" do
34
+ ENV["LANG"] = "en"
35
+ Konjac::Config.load
36
+ Konjac::Config.language.should == :en
37
+ end
35
38
 
36
- it "should default to a foreign language when specified" do
37
- ENV["LANG"] = "ja"
38
- Konjac::Config.load
39
- Konjac::Config.language.should == :ja
39
+ it "should default to a foreign language when specified" do
40
+ ENV["LANG"] = "ja"
41
+ Konjac::Config.load
42
+ Konjac::Config.language.should == :ja
43
+ end
44
+
45
+ it "should default to dict as the default dictionary" do
46
+ Konjac::Config.dictionary.should == "dict"
47
+ end
48
+
49
+ it "should list the available dictionaries, including dict as default" do
50
+ Konjac::Config.list.should include "*** dict"
51
+ end
40
52
  end
41
53
  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.6.3
4
+ version: 0.2.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amatch
16
- requirement: &70209462561300 !ruby/object:Gem::Requirement
16
+ requirement: &70357977450520 !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: *70209462561300
24
+ version_requirements: *70357977450520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70209462560880 !ruby/object:Gem::Requirement
27
+ requirement: &70357977450100 !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: *70209462560880
35
+ version_requirements: *70357977450100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &70209462560440 !ruby/object:Gem::Requirement
38
+ requirement: &70357977449680 !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: *70209462560440
46
+ version_requirements: *70357977449680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &70209462560000 !ruby/object:Gem::Requirement
49
+ requirement: &70357977449240 !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: :runtime
56
56
  prerelease: false
57
- version_requirements: *70209462560000
57
+ version_requirements: *70357977449240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sdoc
60
- requirement: &70209462559580 !ruby/object:Gem::Requirement
60
+ requirement: &70357977448760 !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: :runtime
67
67
  prerelease: false
68
- version_requirements: *70209462559580
68
+ version_requirements: *70357977448760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: term-ansicolor
71
- requirement: &70209462580140 !ruby/object:Gem::Requirement
71
+ requirement: &70357977448180 !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: :runtime
78
78
  prerelease: false
79
- version_requirements: *70209462580140
79
+ version_requirements: *70357977448180
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: trollop
82
- requirement: &70209462579580 !ruby/object:Gem::Requirement
82
+ requirement: &70357977447620 !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: :runtime
89
89
  prerelease: false
90
- version_requirements: *70209462579580
90
+ version_requirements: *70357977447620
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: autotest
93
- requirement: &70209462578660 !ruby/object:Gem::Requirement
93
+ requirement: &70357977463360 !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: *70209462578660
101
+ version_requirements: *70357977463360
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: autotest-fsevent
104
- requirement: &70209462577640 !ruby/object:Gem::Requirement
104
+ requirement: &70357977462680 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70209462577640
112
+ version_requirements: *70357977462680
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: autotest-growl
115
- requirement: &70209462577220 !ruby/object:Gem::Requirement
115
+ requirement: &70357977462080 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70209462577220
123
+ version_requirements: *70357977462080
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: bundler
126
- requirement: &70209462576800 !ruby/object:Gem::Requirement
126
+ requirement: &70357977461460 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70209462576800
134
+ version_requirements: *70357977461460
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rspec
137
- requirement: &70209462576200 !ruby/object:Gem::Requirement
137
+ requirement: &70357977460780 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70209462576200
145
+ version_requirements: *70357977460780
146
146
  description: A Ruby command-line utility for translating files using a YAML wordlist
147
147
  email:
148
148
  - bryan.mckelvey@gmail.com