yaml2tmx 1.0.0
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/Gemfile +5 -0
- data/History.txt +3 -0
- data/Rakefile +7 -0
- data/bin/yaml2tmx +117 -0
- data/lib/yaml2tmx/version.rb +3 -0
- data/yaml2tmx.gemspec +21 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95411c8753b165a339292a636a11ea54ee20f6db
|
4
|
+
data.tar.gz: 3deb030b8d6f647cf5f6e7d216b77f5bce367ee2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: affe6c11ca9e7cfe1743e24da3b89ca5b3a534e615cf3db851e2ba54e9533d74a10f3bc39f231f1f9ec43a13e69938aa1462aff998d7409ce26ca5b29f5a324d
|
7
|
+
data.tar.gz: 31c86d1bb6b97a75332722cc1f977acef6f9d69d3a62db286985753c89587407cbd4eaa364068f32e7054f6482a36359e3a8b3123ab95531bf9e8790616e4b7d
|
data/Gemfile
ADDED
data/History.txt
ADDED
data/Rakefile
ADDED
data/bin/yaml2tmx
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'xml-write-stream'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
$options = {}
|
8
|
+
|
9
|
+
option_parser = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: yaml2tmx [options]"
|
11
|
+
|
12
|
+
opts.on('-s', '--source [file]', 'YAML file containing phrases in the source locale.') do |source|
|
13
|
+
$options[:source] = source
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on('-t', '--target [file]', 'YAML file containing translations in the target locale.') do |target|
|
17
|
+
$options[:target] = target
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-o', '--output [file]', 'The TMX output file to write. If not specified, output is printed to stdout.') do |output|
|
21
|
+
$options[:output] = output
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-h', '--help', 'Prints this help message.') do
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
option_parser.parse!
|
31
|
+
|
32
|
+
# load source and target phrases
|
33
|
+
source_phrases = YAML.load_file($options[:source])
|
34
|
+
target_phrases = YAML.load_file($options[:target])
|
35
|
+
|
36
|
+
source_locale = source_phrases.keys.first
|
37
|
+
target_locale = target_phrases.keys.first
|
38
|
+
|
39
|
+
source_phrases = source_phrases[source_locale]
|
40
|
+
target_phrases = target_phrases[target_locale]
|
41
|
+
|
42
|
+
def each_phrase(phrases, path, &block)
|
43
|
+
case phrases
|
44
|
+
when Hash
|
45
|
+
phrases.each_pair do |key, value|
|
46
|
+
each_phrase(value, path + [key], &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
when Array
|
50
|
+
phrases.each_with_index do |element, idx|
|
51
|
+
each_phrase(element, path + [idx], &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
when String
|
55
|
+
yield phrases, path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# correlate source and target phrases
|
60
|
+
trans_map = {}
|
61
|
+
|
62
|
+
phrase_count = 0
|
63
|
+
|
64
|
+
each_phrase(source_phrases, []) do |phrase, path|
|
65
|
+
phrase_count += 1
|
66
|
+
|
67
|
+
translation = path.inject(:start) do |ret, seg|
|
68
|
+
if ret == :start
|
69
|
+
target_phrases[seg]
|
70
|
+
elsif ret
|
71
|
+
if seg.is_a?(Numeric) && ret.is_a?(Array)
|
72
|
+
ret[seg] # array index case
|
73
|
+
elsif seg.is_a?(String) && ret.is_a?(Hash)
|
74
|
+
ret[seg] # hash key case
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
trans_map[phrase] = translation if translation
|
80
|
+
end
|
81
|
+
|
82
|
+
STDERR.write("Matched #{trans_map.size} of #{phrase_count} source phrases\n")
|
83
|
+
|
84
|
+
stream = if $options[:output]
|
85
|
+
File.open($options[:output], 'w+')
|
86
|
+
else
|
87
|
+
STDOUT
|
88
|
+
end
|
89
|
+
|
90
|
+
writer = XmlWriteStream.from_stream(stream)
|
91
|
+
writer.open_tag('tmx', version: '1.4')
|
92
|
+
writer.open_single_line_tag('header', srclang: source_locale, datatype: 'plaintext', segtype: 'paragraph')
|
93
|
+
writer.close_tag
|
94
|
+
|
95
|
+
writer.open_tag('body')
|
96
|
+
|
97
|
+
trans_map.each_pair do |source_phrase, target_phrase|
|
98
|
+
writer.open_tag('tu')
|
99
|
+
writer.open_tag('tuv', 'xml:lang' => source_locale)
|
100
|
+
writer.open_single_line_tag('seg')
|
101
|
+
writer.write_text(source_phrase)
|
102
|
+
writer.close_tag # seg
|
103
|
+
writer.close_tag # tuv
|
104
|
+
|
105
|
+
writer.open_tag('tuv', 'xml:lang' => target_locale)
|
106
|
+
writer.open_single_line_tag('seg')
|
107
|
+
writer.write_text(target_phrase)
|
108
|
+
writer.close_tag # seg
|
109
|
+
writer.close_tag # tuv
|
110
|
+
writer.close_tag # tu
|
111
|
+
end
|
112
|
+
|
113
|
+
writer.close
|
114
|
+
|
115
|
+
if $options[:output]
|
116
|
+
STDERR.write("Wrote #{$options[:output]}\n")
|
117
|
+
end
|
data/yaml2tmx.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'yaml2tmx/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "yaml2tmx"
|
6
|
+
s.version = ::Yaml2Tmx::VERSION
|
7
|
+
s.authors = ["Cameron Dutro"]
|
8
|
+
s.email = ["camertron@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/camertron"
|
10
|
+
|
11
|
+
s.description = s.summary = "A command-line tool to convert Rails locale-specific yaml files to the standard TMX format for translation memories."
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.has_rdoc = true
|
15
|
+
|
16
|
+
s.add_dependency 'xml-write-stream', '~> 1.0'
|
17
|
+
s.executables << 'yaml2tmx'
|
18
|
+
|
19
|
+
s.require_path = 'lib'
|
20
|
+
s.files = Dir["{lib,spec}/**/*", "Gemfile", "History.txt", "README.md", "Rakefile", "yaml2tmx.gemspec"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaml2tmx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Dutro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xml-write-stream
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: A command-line tool to convert Rails locale-specific yaml files to the
|
28
|
+
standard TMX format for translation memories.
|
29
|
+
email:
|
30
|
+
- camertron@gmail.com
|
31
|
+
executables:
|
32
|
+
- yaml2tmx
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Gemfile
|
37
|
+
- History.txt
|
38
|
+
- Rakefile
|
39
|
+
- bin/yaml2tmx
|
40
|
+
- lib/yaml2tmx/version.rb
|
41
|
+
- yaml2tmx.gemspec
|
42
|
+
homepage: http://github.com/camertron
|
43
|
+
licenses: []
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: A command-line tool to convert Rails locale-specific yaml files to the standard
|
65
|
+
TMX format for translation memories.
|
66
|
+
test_files: []
|