logaling-command 0.1.4 → 0.1.5
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/CHANGES +6 -0
- data/lib/logaling/command/application.rb +45 -10
- data/lib/logaling/command/version.rb +1 -1
- data/lib/logaling/external_glossaries/mozilla_japan.rb +1 -1
- data/lib/logaling/external_glossaries/tmx.rb +58 -0
- data/lib/logaling/external_glossary.rb +37 -6
- data/lib/logaling/glossary_db.rb +2 -2
- data/lib/logaling/repository.rb +11 -0
- data/spec/logaling/command_spec.rb +8 -5
- metadata +19 -18
data/CHANGES
CHANGED
@@ -74,7 +74,7 @@ module Logaling::Command
|
|
74
74
|
@dotfile_path = options["logaling-config"] ? options["logaling-config"] : find_dotfile
|
75
75
|
@project_config_path = File.join(@dotfile_path, 'config')
|
76
76
|
@config.load(@project_config_path)
|
77
|
-
|
77
|
+
register_and_index
|
78
78
|
end
|
79
79
|
say "Successfully created #{logaling_config_path}"
|
80
80
|
else
|
@@ -84,29 +84,39 @@ module Logaling::Command
|
|
84
84
|
|
85
85
|
desc 'import', 'Import external glossary'
|
86
86
|
method_option "list", type: :boolean, default: false
|
87
|
-
def import(external_glossary=nil)
|
87
|
+
def import(external_glossary=nil, *args)
|
88
88
|
require "logaling/external_glossary"
|
89
89
|
Logaling::ExternalGlossary.load
|
90
90
|
if options["list"]
|
91
91
|
Logaling::ExternalGlossary.list.each {|glossary| say "#{glossary.name.bright} : #{glossary.description}" }
|
92
92
|
else
|
93
|
-
|
94
|
-
|
93
|
+
case external_glossary
|
94
|
+
when 'tmx'
|
95
|
+
glossary_info = initialize_import_parameter(args)
|
96
|
+
check_import_parameter(glossary_info)
|
97
|
+
@repository.import_tmx(Logaling::ExternalGlossary.get(external_glossary), glossary_info)
|
98
|
+
@repository.index
|
99
|
+
else
|
100
|
+
@repository.import(Logaling::ExternalGlossary.get(external_glossary))
|
101
|
+
@repository.index
|
102
|
+
end
|
95
103
|
end
|
96
104
|
rescue Logaling::CommandFailed => e
|
97
105
|
say e.message
|
98
106
|
rescue Logaling::ExternalGlossaryNotFound
|
99
107
|
say "'#{external_glossary}' can't find in import list."
|
100
108
|
say "Try 'loga import --list' and confirm import list."
|
109
|
+
rescue Logaling::GlossaryNotFound => e
|
110
|
+
say e.message
|
101
111
|
end
|
102
112
|
|
103
113
|
desc 'register', 'Register .logaling'
|
104
114
|
def register
|
105
|
-
|
115
|
+
raise Logaling::CommandFailed, "Can't use '-g <glossary>' option." if options["glossary"]
|
116
|
+
@config.check_required_option("glossary" => "Do 'loga register' at project directory.")
|
106
117
|
raise Logaling::CommandFailed, "Try 'loga new' first." unless File.exist?(@dotfile_path)
|
107
118
|
|
108
|
-
|
109
|
-
@repository.index
|
119
|
+
register_and_index
|
110
120
|
say "#{@config.glossary} is now registered to logaling."
|
111
121
|
rescue Logaling::CommandFailed => e
|
112
122
|
say e.message
|
@@ -116,7 +126,8 @@ module Logaling::Command
|
|
116
126
|
|
117
127
|
desc 'unregister', 'Unregister .logaling'
|
118
128
|
def unregister
|
119
|
-
|
129
|
+
raise Logaling::CommandFailed, "Can't use '-g <glossary>' option." if options["glossary"]
|
130
|
+
@config.check_required_option("glossary" => "Do 'loga unregister' at project directory.")
|
120
131
|
|
121
132
|
@repository.unregister(@config.glossary)
|
122
133
|
@repository.index
|
@@ -132,7 +143,7 @@ module Logaling::Command
|
|
132
143
|
def config(key, value)
|
133
144
|
if options["global"]
|
134
145
|
unless File.exist?(@logaling_home)
|
135
|
-
FileUtils.mkdir_p(@logaling_home) rescue raise Logaling::CommandFailed, "
|
146
|
+
FileUtils.mkdir_p(@logaling_home) rescue raise Logaling::CommandFailed, "Input existing directory as logaling-home."
|
136
147
|
end
|
137
148
|
config_path = File.join(@logaling_home, "config")
|
138
149
|
else
|
@@ -378,7 +389,7 @@ module Logaling::Command
|
|
378
389
|
|
379
390
|
def check_logaling_home_exists
|
380
391
|
unless File.exist?(@logaling_home)
|
381
|
-
raise Logaling::CommandFailed, "
|
392
|
+
raise Logaling::CommandFailed, "Input existing directory as logaling-home."
|
382
393
|
end
|
383
394
|
end
|
384
395
|
|
@@ -408,5 +419,29 @@ module Logaling::Command
|
|
408
419
|
puts("\n]") if i == last-1
|
409
420
|
end
|
410
421
|
end
|
422
|
+
|
423
|
+
def check_import_parameter(glossary_info)
|
424
|
+
unless glossary_info[:name] && glossary_info[:url]
|
425
|
+
raise Logaling::CommandFailed, "Do 'loga import tmx <glossary name> <url or path>'"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
def initialize_import_parameter(arr)
|
430
|
+
glossary_info = {}
|
431
|
+
url = arr[1]
|
432
|
+
if url && !URI.parse(url).host
|
433
|
+
url = File::expand_path(url)
|
434
|
+
end
|
435
|
+
glossary_info[:name] = arr[0]
|
436
|
+
glossary_info[:url] = url
|
437
|
+
glossary_info[:source_language] = arr[2]
|
438
|
+
glossary_info[:target_language] = arr[3]
|
439
|
+
glossary_info
|
440
|
+
end
|
441
|
+
|
442
|
+
def register_and_index
|
443
|
+
@repository.register(@dotfile_path, @config.glossary)
|
444
|
+
@repository.index
|
445
|
+
end
|
411
446
|
end
|
412
447
|
end
|
@@ -32,7 +32,7 @@ module Logaling
|
|
32
32
|
doc.css("dl[@class='terminology en-ja']").each do |dl|
|
33
33
|
dl.children.each_slice(2) do |dt, dd|
|
34
34
|
dd.text.split("|").each do |ddt|
|
35
|
-
ddt = ddt.gsub(/\s/, '')
|
35
|
+
ddt = ddt.gsub(/\s|\u{a0}/, '')
|
36
36
|
unless ddt.empty?
|
37
37
|
csv << [dust_to_tilda(dt.text), dust_to_tilda(ddt)]
|
38
38
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (C) 2012 Miho SUZUKI
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'open-uri'
|
17
|
+
require 'nokogiri'
|
18
|
+
module Logaling
|
19
|
+
class Tmx < ExternalGlossary
|
20
|
+
description 'TMX 1.4b formatted glossary (http://www.gala-global.org/oscarStandards/tmx/)'
|
21
|
+
source_language 'en'
|
22
|
+
target_language 'ja'
|
23
|
+
output_format 'csv'
|
24
|
+
|
25
|
+
private
|
26
|
+
def convert_to_csv(csv, glossary_info)
|
27
|
+
doc = ::Nokogiri::XML(open(glossary_info[:url], "r"))
|
28
|
+
tu_nodes = doc.xpath('//tmx/body/tu')
|
29
|
+
tu_nodes.each do |tu|
|
30
|
+
original = ""
|
31
|
+
translation = ""
|
32
|
+
notes = []
|
33
|
+
tu.children.each do |tuv|
|
34
|
+
if tuv.name == "tuv"
|
35
|
+
lang = convert_language_code_iso_639(tuv["lang"])
|
36
|
+
if lang == glossary_info[:source_language]
|
37
|
+
tuv.children.each do |child|
|
38
|
+
original = child.text.strip if child.name == "seg"
|
39
|
+
notes << child.text.strip if child.name == "note"
|
40
|
+
end
|
41
|
+
elsif lang == glossary_info[:target_language]
|
42
|
+
tuv.children.each do |child|
|
43
|
+
translation = child.text.strip if child.name == "seg"
|
44
|
+
notes << child.text.strip if child.name == "note"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
csv << [original, translation, notes.join(" | ")] if original && translation
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert_language_code_iso_639(code)
|
54
|
+
# use two-letter codes
|
55
|
+
code.downcase.sub(/-.*\z/, "")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -14,6 +14,8 @@
|
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
16
|
require 'active_support/inflector'
|
17
|
+
require 'open-uri'
|
18
|
+
require 'net/http'
|
17
19
|
|
18
20
|
class Logaling::ExternalGlossary
|
19
21
|
class << self
|
@@ -66,13 +68,22 @@ class Logaling::ExternalGlossary
|
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
|
-
def import
|
70
|
-
|
71
|
+
def import(glossary_info=nil)
|
72
|
+
if glossary_info && glossary_info[:url]
|
73
|
+
unless file_exists?(glossary_info[:url])
|
74
|
+
raise Logaling::GlossaryNotFound, "Failed open url/path <#{glossary_info[:url]}>"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
File.open(import_file_name(glossary_info), "w") do |output|
|
71
78
|
output_format = self.class.output_format
|
72
79
|
output_format = output_format.to_s if output_format.is_a?(Symbol)
|
73
80
|
case output_format
|
74
81
|
when "csv"
|
75
|
-
|
82
|
+
if glossary_info
|
83
|
+
convert_to_csv(CSV.new(output), glossary_info)
|
84
|
+
else
|
85
|
+
convert_to_csv(CSV.new(output))
|
86
|
+
end
|
76
87
|
else
|
77
88
|
raise UnsupportedFormat, "unsupported format: <#{output_format}>"
|
78
89
|
end
|
@@ -80,8 +91,28 @@ class Logaling::ExternalGlossary
|
|
80
91
|
end
|
81
92
|
|
82
93
|
private
|
83
|
-
def import_file_name
|
84
|
-
|
85
|
-
|
94
|
+
def import_file_name(glossary_info=nil)
|
95
|
+
if glossary_info
|
96
|
+
glossary_info[:name] ||= self.class.name
|
97
|
+
glossary_info[:source_language] ||= self.class.source_language
|
98
|
+
glossary_info[:target_language] ||= self.class.target_language
|
99
|
+
|
100
|
+
[glossary_info[:name], glossary_info[:source_language],
|
101
|
+
glossary_info[:target_language], self.class.output_format].join('.')
|
102
|
+
else
|
103
|
+
[self.class.name, self.class.source_language,
|
104
|
+
self.class.target_language, self.class.output_format].join('.')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def file_exists?(url_org)
|
109
|
+
url = URI.parse(url_org)
|
110
|
+
if url.host
|
111
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
112
|
+
http.head(url.request_uri).code == "200"
|
113
|
+
end
|
114
|
+
else
|
115
|
+
File.exist?(url_org)
|
116
|
+
end
|
86
117
|
end
|
87
118
|
end
|
data/lib/logaling/glossary_db.rb
CHANGED
@@ -108,7 +108,7 @@ module Logaling
|
|
108
108
|
{:key=>"source_term", :order=>'ascending'},
|
109
109
|
{:key=>"target_term", :order=>'ascending'}])
|
110
110
|
|
111
|
-
options = {:width =>
|
111
|
+
options = {:width => 5000,
|
112
112
|
:html_escape => true,
|
113
113
|
:normalize => true}
|
114
114
|
snippet = records_selected.expression.snippet(["<snippet>", "</snippet>"], options)
|
@@ -144,7 +144,7 @@ module Logaling
|
|
144
144
|
{:key=>"source_term", :order=>'ascending'},
|
145
145
|
{:key=>"target_term", :order=>'ascending'}])
|
146
146
|
|
147
|
-
options = {:width =>
|
147
|
+
options = {:width => 5000,
|
148
148
|
:html_escape => true,
|
149
149
|
:normalize => true}
|
150
150
|
snippet = records_selected.expression.snippet(["<snippet>", "</snippet>"], options)
|
data/lib/logaling/repository.rb
CHANGED
@@ -54,6 +54,17 @@ module Logaling
|
|
54
54
|
raise Logaling::CommandFailed, "Failed import #{glossary.class.name} to #{cache_path}."
|
55
55
|
end
|
56
56
|
|
57
|
+
def import_tmx(glossary, glossary_info)
|
58
|
+
FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
|
59
|
+
Dir.chdir(cache_path) do
|
60
|
+
glossary.import(glossary_info)
|
61
|
+
end
|
62
|
+
rescue Logaling::GlossaryNotFound => e
|
63
|
+
raise e
|
64
|
+
rescue
|
65
|
+
raise Logaling::CommandFailed, "Failed import_tmx #{glossary.class.name} to #{cache_path}."
|
66
|
+
end
|
67
|
+
|
57
68
|
def lookup(source_term, glossary_source, dictionary=false)
|
58
69
|
raise GlossaryDBNotFound unless File.exist?(logaling_db_home)
|
59
70
|
|
@@ -90,6 +90,7 @@ describe Logaling::Command::Application do
|
|
90
90
|
context "when can not find .logaling" do
|
91
91
|
before(:all) do
|
92
92
|
FileUtils.rm_rf(logaling_config)
|
93
|
+
base_options["glossary"] = nil
|
93
94
|
@stdout = capture(:stdout) {command.register}
|
94
95
|
end
|
95
96
|
|
@@ -97,8 +98,8 @@ describe Logaling::Command::Application do
|
|
97
98
|
Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects
|
98
99
|
end
|
99
100
|
|
100
|
-
it "print message \"
|
101
|
-
@stdout.should be_include "
|
101
|
+
it "print message \"Do 'loga register' at project directory.\"" do
|
102
|
+
@stdout.should be_include "Do 'loga register' at project directory."
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
@@ -131,13 +132,14 @@ describe Logaling::Command::Application do
|
|
131
132
|
@stdout = capture(:stdout) {command.unregister}
|
132
133
|
end
|
133
134
|
|
134
|
-
it "should print message '
|
135
|
-
@stdout.should be_include "
|
135
|
+
it "should print message 'Do \'loga unregister\' at ...'" do
|
136
|
+
@stdout.should be_include "Do 'loga unregister' at project directory."
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
139
140
|
context "and call with option" do
|
140
141
|
before do
|
142
|
+
command.options = base_options.merge("glossary" => nil)
|
141
143
|
command.new('spec', 'en', 'ja')
|
142
144
|
@stdout = capture(:stdout) {command.unregister}
|
143
145
|
end
|
@@ -150,6 +152,7 @@ describe Logaling::Command::Application do
|
|
150
152
|
context 'when find .logaling' do
|
151
153
|
context 'and .logaling registered' do
|
152
154
|
before do
|
155
|
+
command.options = base_options.merge("glossary" => nil)
|
153
156
|
command.new('spec', 'en', 'ja')
|
154
157
|
command.register
|
155
158
|
command.unregister
|
@@ -163,7 +166,7 @@ describe Logaling::Command::Application do
|
|
163
166
|
|
164
167
|
context "and .logaling is not registered" do
|
165
168
|
before do
|
166
|
-
command.options = base_options.merge("no-register" => true)
|
169
|
+
command.options = base_options.merge("no-register" => true, "glossary" => nil)
|
167
170
|
command.new('spec', 'en', 'ja')
|
168
171
|
@stdout = capture(:stdout) {command.unregister}
|
169
172
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logaling-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,11 +13,11 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2012-
|
16
|
+
date: 2012-05-02 00:00:00.000000000Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: thor
|
20
|
-
requirement: &
|
20
|
+
requirement: &2161067140 !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
23
23
|
- - ! '>='
|
@@ -25,10 +25,10 @@ dependencies:
|
|
25
25
|
version: 0.14.6
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
|
-
version_requirements: *
|
28
|
+
version_requirements: *2161067140
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: bundler
|
31
|
-
requirement: &
|
31
|
+
requirement: &2161066660 !ruby/object:Gem::Requirement
|
32
32
|
none: false
|
33
33
|
requirements:
|
34
34
|
- - ! '>='
|
@@ -36,10 +36,10 @@ dependencies:
|
|
36
36
|
version: '1.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
|
-
version_requirements: *
|
39
|
+
version_requirements: *2161066660
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rroonga
|
42
|
-
requirement: &
|
42
|
+
requirement: &2161066180 !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
45
45
|
- - ! '>='
|
@@ -47,10 +47,10 @@ dependencies:
|
|
47
47
|
version: 1.3.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
|
-
version_requirements: *
|
50
|
+
version_requirements: *2161066180
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: rainbow
|
53
|
-
requirement: &
|
53
|
+
requirement: &2161065800 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
56
|
- - ! '>='
|
@@ -58,10 +58,10 @@ dependencies:
|
|
58
58
|
version: '0'
|
59
59
|
type: :runtime
|
60
60
|
prerelease: false
|
61
|
-
version_requirements: *
|
61
|
+
version_requirements: *2161065800
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: nokogiri
|
64
|
-
requirement: &
|
64
|
+
requirement: &2161065340 !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
@@ -69,10 +69,10 @@ dependencies:
|
|
69
69
|
version: '0'
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
|
-
version_requirements: *
|
72
|
+
version_requirements: *2161065340
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: activesupport
|
75
|
-
requirement: &
|
75
|
+
requirement: &2161064920 !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
77
77
|
requirements:
|
78
78
|
- - ! '>='
|
@@ -80,10 +80,10 @@ dependencies:
|
|
80
80
|
version: '0'
|
81
81
|
type: :runtime
|
82
82
|
prerelease: false
|
83
|
-
version_requirements: *
|
83
|
+
version_requirements: *2161064920
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rake
|
86
|
-
requirement: &
|
86
|
+
requirement: &2153870360 !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
89
89
|
- - ! '>='
|
@@ -91,10 +91,10 @@ dependencies:
|
|
91
91
|
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
|
-
version_requirements: *
|
94
|
+
version_requirements: *2153870360
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rspec
|
97
|
-
requirement: &
|
97
|
+
requirement: &2153869940 !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|
100
100
|
- - ! '>='
|
@@ -102,7 +102,7 @@ dependencies:
|
|
102
102
|
version: '0'
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
|
-
version_requirements: *
|
105
|
+
version_requirements: *2153869940
|
106
106
|
description: A command line interface for logaling.
|
107
107
|
email:
|
108
108
|
- koji.shimada@enishi-tech.com
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/logaling/external_glossaries/gnome_project.rb
|
136
136
|
- lib/logaling/external_glossaries/mozilla_japan.rb
|
137
137
|
- lib/logaling/external_glossaries/postgresql_manual.rb
|
138
|
+
- lib/logaling/external_glossaries/tmx.rb
|
138
139
|
- lib/logaling/external_glossary.rb
|
139
140
|
- lib/logaling/glossary.rb
|
140
141
|
- lib/logaling/glossary_db.rb
|