ara2yml 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/ara2yml.gemspec +26 -0
- data/bin/ara2yml +6 -0
- data/lib/ara2yml.rb +84 -0
- data/lib/ara2yml/version.rb +3 -0
- metadata +111 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9e5a9bee604e260f91e9c1a1f2c5deefbc4e4418
|
|
4
|
+
data.tar.gz: e9fe3fec2d5be30992fc725ca12b016b5a0802a4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9709c921ff8ab39ed176b6d5e6e16b31c59b1505ce9ddf6a56e28895315a4d96e4dc6d375f8b3928033126a31afd4cc745ff71000e787b48555db49ce7d08df8
|
|
7
|
+
data.tar.gz: 637a98d727843577a70c0eccf13e879ddeeb62d4047da777f3f541f6b1648cc41f32a81078552dfc1577e5784f22cbdb7a4b7874e20b127ba8d9a8f77c6e6aa1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 AlexanderPavlenko
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Ara2yml
|
|
2
|
+
|
|
3
|
+
Convert proprietary file format of [Across v6](http://www.my-across.net/en/download-center.aspx) for exporting and (re-)importing projects into the YAML.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'ara2yml'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install ara2yml
|
|
20
|
+
|
|
21
|
+
Also, it requires `mdbtools` package.
|
|
22
|
+
|
|
23
|
+
sudo apt-get install mdbtools
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
CLI
|
|
28
|
+
|
|
29
|
+
ara2yml /tmp/ara /tmp/yml
|
|
30
|
+
|
|
31
|
+
API
|
|
32
|
+
|
|
33
|
+
Ara2yml.convert(ara_filename, yml_filename)
|
|
34
|
+
|
|
35
|
+
## Contributing
|
|
36
|
+
|
|
37
|
+
1. Fork it ( https://github.com/[my-github-username]/ara2yml/fork )
|
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ara2yml.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'ara2yml/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'ara2yml'
|
|
8
|
+
spec.version = Ara2yml::VERSION
|
|
9
|
+
spec.authors = ['AlexanderPavlenko']
|
|
10
|
+
spec.email = ['alerticus@gmail.com']
|
|
11
|
+
spec.summary = %q{Convert ARA to YAML}
|
|
12
|
+
spec.description = %q{Convert proprietary file format of Across v6 for exporting and (re-)importing projects into the YAML.}
|
|
13
|
+
spec.homepage = 'https://github.com/AlexanderPavlenko/ara2yml'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
23
|
+
|
|
24
|
+
spec.add_dependency 'rubyzip'
|
|
25
|
+
spec.add_dependency 'mdb'
|
|
26
|
+
end
|
data/bin/ara2yml
ADDED
data/lib/ara2yml.rb
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require_relative 'ara2yml/version'
|
|
2
|
+
require 'zip'
|
|
3
|
+
require 'mdb'
|
|
4
|
+
|
|
5
|
+
module Mdb
|
|
6
|
+
class Database
|
|
7
|
+
private
|
|
8
|
+
# monkeypatch in order to strip binary data, that only produces errors
|
|
9
|
+
def open_csv(table)
|
|
10
|
+
command = "mdb-export -bstrip -D '%F %T' -d #{Shellwords.escape(delimiter)} #{file_name} #{table}"
|
|
11
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
|
12
|
+
yield CSV.new(stdout, col_sep: delimiter)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module Ara2yml
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
def convert(input, output)
|
|
22
|
+
tempfile = extract_database(input)
|
|
23
|
+
translations = extract_translations(tempfile.path)
|
|
24
|
+
tempfile.unlink
|
|
25
|
+
dump_nice_yaml(translations, output)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def extract_database(ara_filename)
|
|
29
|
+
tempfile = Tempfile.new('ara2yml')
|
|
30
|
+
tempfile.close
|
|
31
|
+
Zip::File.open(ara_filename) do |zip_file|
|
|
32
|
+
entry = zip_file.entries[0]
|
|
33
|
+
$stderr.puts "Extracting #{entry.name} from #{ara_filename} into #{tempfile.path}"
|
|
34
|
+
entry.extract(tempfile.path) { true }
|
|
35
|
+
end
|
|
36
|
+
tempfile
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def extract_translations(db_filename)
|
|
40
|
+
db = Mdb.open(db_filename)
|
|
41
|
+
language_names = db['LanguageNames'].each_with_object({}) { |e, a|
|
|
42
|
+
a[e[:Id]] = e[:LName].to_sym
|
|
43
|
+
}
|
|
44
|
+
languages = db['Languages'].each_with_object({}) { |e, a|
|
|
45
|
+
a[e[:Id]] = language_names[e[:Id_LanguageName]]
|
|
46
|
+
}
|
|
47
|
+
result = db['Paragraphs'].each_with_object([]) { |e, a|
|
|
48
|
+
if (text = e[:XmlData])
|
|
49
|
+
start = text.index('<text>') + 6
|
|
50
|
+
finish = text.index('</text>')
|
|
51
|
+
text = text[start...finish]
|
|
52
|
+
end
|
|
53
|
+
(a[Integer(e[:PIndex])] ||= {})[languages[e[:Id_Language]]] = text
|
|
54
|
+
}
|
|
55
|
+
result.each_with_index { |v, k|
|
|
56
|
+
if !v || v.values.all?(&:nil?)
|
|
57
|
+
result.delete_at(k)
|
|
58
|
+
elsif v.values.all? { |s| s.strip.length == 0 }
|
|
59
|
+
result[k] = nil
|
|
60
|
+
end
|
|
61
|
+
}
|
|
62
|
+
result
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def dump_nice_yaml(translations, filename)
|
|
66
|
+
File.open(filename, 'w') { |f|
|
|
67
|
+
f.write "---\n"
|
|
68
|
+
translations.each { |e|
|
|
69
|
+
first_key = true
|
|
70
|
+
if e
|
|
71
|
+
f.write '- '
|
|
72
|
+
e.each { |k, v|
|
|
73
|
+
f.write ' ' unless first_key
|
|
74
|
+
f.write ":#{k}: |-\n"
|
|
75
|
+
f.write " #{v}\n"
|
|
76
|
+
first_key = false
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
f.write "-\n"
|
|
80
|
+
end
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ara2yml
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- AlexanderPavlenko
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubyzip
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: mdb
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Convert proprietary file format of Across v6 for exporting and (re-)importing
|
|
70
|
+
projects into the YAML.
|
|
71
|
+
email:
|
|
72
|
+
- alerticus@gmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- ara2yml
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- ara2yml.gemspec
|
|
84
|
+
- bin/ara2yml
|
|
85
|
+
- lib/ara2yml.rb
|
|
86
|
+
- lib/ara2yml/version.rb
|
|
87
|
+
homepage: https://github.com/AlexanderPavlenko/ara2yml
|
|
88
|
+
licenses:
|
|
89
|
+
- MIT
|
|
90
|
+
metadata: {}
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubyforge_project:
|
|
107
|
+
rubygems_version: 2.4.2
|
|
108
|
+
signing_key:
|
|
109
|
+
specification_version: 4
|
|
110
|
+
summary: Convert ARA to YAML
|
|
111
|
+
test_files: []
|