translatomatic 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.translatomatic/config.yml +18 -0
- data/.travis.yml +33 -33
- data/Gemfile +6 -4
- data/README.de.md +53 -18
- data/README.es.md +55 -20
- data/README.fr.md +54 -19
- data/README.it.md +58 -23
- data/README.ja.md +54 -19
- data/README.ko.md +58 -23
- data/README.md +167 -141
- data/README.ms.md +51 -16
- data/README.pt.md +58 -23
- data/README.ru.md +53 -18
- data/README.sv.md +53 -18
- data/README.zh.md +53 -18
- data/bin/translatomatic +6 -6
- data/bin/travis +24 -26
- data/config/locales/translatomatic/de.yml +22 -11
- data/config/locales/translatomatic/en.yml +21 -12
- data/config/locales/translatomatic/es.yml +22 -11
- data/config/locales/translatomatic/fr.yml +22 -12
- data/config/locales/translatomatic/it.yml +22 -11
- data/config/locales/translatomatic/ja.yml +22 -11
- data/config/locales/translatomatic/ko.yml +22 -11
- data/config/locales/translatomatic/ms.yml +22 -11
- data/config/locales/translatomatic/pt.yml +22 -11
- data/config/locales/translatomatic/ru.yml +22 -11
- data/config/locales/translatomatic/sv.yml +22 -11
- data/config/locales/translatomatic/zh.yml +22 -11
- data/db/migrate/201712170000_initial.rb +25 -25
- data/lib/translatomatic/cli/base.rb +81 -73
- data/lib/translatomatic/cli/config.rb +110 -81
- data/lib/translatomatic/cli/main.rb +85 -72
- data/lib/translatomatic/cli/translate.rb +141 -106
- data/lib/translatomatic/cli.rb +8 -8
- data/lib/translatomatic/config.rb +302 -155
- data/lib/translatomatic/converter.rb +28 -260
- data/lib/translatomatic/database.rb +134 -134
- data/lib/translatomatic/define_options.rb +22 -0
- data/lib/translatomatic/escaped_unicode.rb +0 -0
- data/lib/translatomatic/extractor/base.rb +16 -16
- data/lib/translatomatic/extractor/ruby.rb +6 -6
- data/lib/translatomatic/extractor.rb +5 -5
- data/lib/translatomatic/file_translator.rb +269 -0
- data/lib/translatomatic/http_request.rb +162 -162
- data/lib/translatomatic/locale.rb +76 -76
- data/lib/translatomatic/logger.rb +23 -23
- data/lib/translatomatic/model/locale.rb +25 -25
- data/lib/translatomatic/model/text.rb +19 -19
- data/lib/translatomatic/model.rb +1 -1
- data/lib/translatomatic/option.rb +37 -41
- data/lib/translatomatic/progress_updater.rb +13 -13
- data/lib/translatomatic/resource_file/base.rb +269 -192
- data/lib/translatomatic/resource_file/csv.rb +37 -0
- data/lib/translatomatic/resource_file/html.rb +54 -47
- data/lib/translatomatic/resource_file/markdown.rb +50 -55
- data/lib/translatomatic/resource_file/plist.rb +153 -19
- data/lib/translatomatic/resource_file/po.rb +107 -0
- data/lib/translatomatic/resource_file/properties.rb +91 -90
- data/lib/translatomatic/resource_file/resw.rb +50 -30
- data/lib/translatomatic/resource_file/subtitle.rb +75 -0
- data/lib/translatomatic/resource_file/text.rb +24 -30
- data/lib/translatomatic/resource_file/xcode_strings.rb +75 -80
- data/lib/translatomatic/resource_file/xml.rb +98 -91
- data/lib/translatomatic/resource_file/yaml.rb +94 -116
- data/lib/translatomatic/resource_file.rb +87 -78
- data/lib/translatomatic/string.rb +188 -188
- data/lib/translatomatic/tmx/document.rb +99 -99
- data/lib/translatomatic/translation_result.rb +63 -63
- data/lib/translatomatic/{converter_stats.rb → translation_stats.rb} +17 -17
- data/lib/translatomatic/translator/base.rb +1 -1
- data/lib/translatomatic/translator/google.rb +2 -0
- data/lib/translatomatic/translator.rb +10 -2
- data/lib/translatomatic/util.rb +45 -45
- data/lib/translatomatic/version.rb +7 -7
- data/lib/translatomatic.rb +52 -49
- data/translatomatic.gemspec +3 -2
- metadata +25 -5
@@ -0,0 +1,75 @@
|
|
1
|
+
module Translatomatic::ResourceFile
|
2
|
+
# Subtitle resource file.
|
3
|
+
# requires 'titlekit' gem
|
4
|
+
class Subtitle < Base
|
5
|
+
|
6
|
+
# (see Translatomatic::ResourceFile::Base.extensions)
|
7
|
+
def self.extensions
|
8
|
+
%w{srt ass ssa}
|
9
|
+
end
|
10
|
+
|
11
|
+
# (see Translatomatic::ResourceFile::Base.enabled?)
|
12
|
+
def self.enabled?
|
13
|
+
@enabled ||= begin
|
14
|
+
require 'titlekit'
|
15
|
+
true
|
16
|
+
rescue LoadError
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# (see Translatomatic::ResourceFile::Base#set)
|
22
|
+
def set(key, value)
|
23
|
+
super(key, value)
|
24
|
+
if @subtitle_map.include?(key)
|
25
|
+
@subtitle_map[key][:lines] = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# (see Translatomatic::ResourceFile::Base#save)
|
30
|
+
def save(target = path, options = {})
|
31
|
+
export(target)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def init
|
37
|
+
@subtitle_map = {}
|
38
|
+
@subtitles = []
|
39
|
+
end
|
40
|
+
|
41
|
+
def load
|
42
|
+
@subtitles = import(@path)
|
43
|
+
init_subtitle_map
|
44
|
+
init_properties
|
45
|
+
end
|
46
|
+
|
47
|
+
def init_subtitle_map
|
48
|
+
# map of key1 => subtitle, key2 => subtitle, ...
|
49
|
+
@keynum = 1
|
50
|
+
@subtitles.each_with_index do |subtitle, i|
|
51
|
+
key = "key#{@keynum}"
|
52
|
+
@keynum += 1
|
53
|
+
@subtitle_map[key] = subtitle
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def init_properties
|
58
|
+
@properties = @subtitle_map.transform_values { |i| i[:lines] }
|
59
|
+
end
|
60
|
+
|
61
|
+
def import(path)
|
62
|
+
import_export_class(path).import(read_contents(path))
|
63
|
+
end
|
64
|
+
|
65
|
+
def export(target, options = {})
|
66
|
+
content = import_export_class(target).export(@subtitles) || ''
|
67
|
+
target.write(content.chomp)
|
68
|
+
end
|
69
|
+
|
70
|
+
def import_export_class(path)
|
71
|
+
class_name = path.extname.sub(/^\./, '').upcase
|
72
|
+
Titlekit.const_get(class_name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,30 +1,24 @@
|
|
1
|
-
module Translatomatic::ResourceFile
|
2
|
-
# Text resource file
|
3
|
-
class Text < Base
|
4
|
-
|
5
|
-
# (see Translatomatic::ResourceFile::Base.extensions)
|
6
|
-
def self.extensions
|
7
|
-
%w{txt text}
|
8
|
-
end
|
9
|
-
|
10
|
-
# (see Translatomatic::ResourceFile::Base#
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def read(path)
|
26
|
-
text = path.read
|
27
|
-
{ "text" => text }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
module Translatomatic::ResourceFile
|
2
|
+
# Text resource file
|
3
|
+
class Text < Base
|
4
|
+
|
5
|
+
# (see Translatomatic::ResourceFile::Base.extensions)
|
6
|
+
def self.extensions
|
7
|
+
%w{txt text}
|
8
|
+
end
|
9
|
+
|
10
|
+
# (see Translatomatic::ResourceFile::Base#save)
|
11
|
+
def save(target = path, options = {})
|
12
|
+
values = @properties.values.collect { |i| i.strip + "\n" }
|
13
|
+
target.write(values.join)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def load
|
19
|
+
text = read_contents(@path)
|
20
|
+
@properties = { "text" => text }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -1,80 +1,75 @@
|
|
1
|
-
module Translatomatic::ResourceFile
|
2
|
-
|
3
|
-
# @!visibility private
|
4
|
-
module XCodeStringsLocalePath
|
5
|
-
|
6
|
-
# (see Translatomatic::ResourceFile::Base#locale_path)
|
7
|
-
# @note localization files in XCode use the following file name
|
8
|
-
# convention:
|
9
|
-
def locale_path(locale)
|
10
|
-
if path.to_s.match(
|
11
|
-
# xcode style
|
12
|
-
filename = path.basename
|
13
|
-
path.parent.parent + (locale.to_s + ".lproj") + filename
|
14
|
-
else
|
15
|
-
super(locale)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# XCode strings resource file
|
21
|
-
# @see https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
|
22
|
-
class XCodeStrings < Base
|
23
|
-
include Translatomatic::ResourceFile::XCodeStringsLocalePath
|
24
|
-
|
25
|
-
# (see Translatomatic::ResourceFile::Base.extensions)
|
26
|
-
def self.extensions
|
27
|
-
%w{strings}
|
28
|
-
end
|
29
|
-
|
30
|
-
# (see Translatomatic::ResourceFile::Base
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
key =
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
string ? string.gsub(/["']/) { |i| "\\#{i}" } : ''
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
1
|
+
module Translatomatic::ResourceFile
|
2
|
+
|
3
|
+
# @!visibility private
|
4
|
+
module XCodeStringsLocalePath
|
5
|
+
|
6
|
+
# (see Translatomatic::ResourceFile::Base#locale_path)
|
7
|
+
# @note localization files in XCode use the following file name
|
8
|
+
# convention: locale.lproj/filename
|
9
|
+
def locale_path(locale)
|
10
|
+
if path.to_s.match(/\b([-\w]+).lproj\/.+$/)
|
11
|
+
# xcode style
|
12
|
+
filename = path.basename
|
13
|
+
path.parent.parent + (locale.to_s + ".lproj") + filename
|
14
|
+
else
|
15
|
+
super(locale)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# XCode strings resource file
|
21
|
+
# @see https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
|
22
|
+
class XCodeStrings < Base
|
23
|
+
include Translatomatic::ResourceFile::XCodeStringsLocalePath
|
24
|
+
|
25
|
+
# (see Translatomatic::ResourceFile::Base.extensions)
|
26
|
+
def self.extensions
|
27
|
+
%w{strings}
|
28
|
+
end
|
29
|
+
|
30
|
+
# (see Translatomatic::ResourceFile::Base.is_key_value?)
|
31
|
+
def self.is_key_value?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
# (see Translatomatic::ResourceFile::Base#save)
|
36
|
+
def save(target = path, options = {})
|
37
|
+
out = ""
|
38
|
+
out += comment(created_by) unless options[:no_created_by]
|
39
|
+
properties.each do |key, value|
|
40
|
+
key = escape(key)
|
41
|
+
value = escape(value)
|
42
|
+
out += %Q{"#{key}" = "#{value}";\n}
|
43
|
+
end
|
44
|
+
target.write(out)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def load
|
50
|
+
result = {}
|
51
|
+
content = read_contents(@path)
|
52
|
+
uncommented = content.gsub(/\/\*.*?\*\//, '')
|
53
|
+
key_values = uncommented.scan(/"(.*?[^\\])"\s*=\s*"(.*?[^\\])"\s*;/m)
|
54
|
+
key_values.each do |entry|
|
55
|
+
key, value = entry
|
56
|
+
result[unescape(key)] = unescape(value)
|
57
|
+
end
|
58
|
+
|
59
|
+
@properties = result
|
60
|
+
end
|
61
|
+
|
62
|
+
def comment(text)
|
63
|
+
"/* #{text} */\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
def unescape(string)
|
67
|
+
string ? string.gsub(/\\(["'])/) { |i| i } : ''
|
68
|
+
end
|
69
|
+
|
70
|
+
def escape(string)
|
71
|
+
string ? string.gsub(/["']/) { |i| "\\#{i}" } : ''
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -1,96 +1,103 @@
|
|
1
|
-
module Translatomatic::ResourceFile
|
1
|
+
module Translatomatic::ResourceFile
|
2
2
|
# XML resource file
|
3
|
-
class XML < Base
|
4
|
-
|
5
|
-
# (see Translatomatic::ResourceFile::Base.extensions)
|
6
|
-
def self.extensions
|
7
|
-
%w{xml}
|
8
|
-
end
|
9
|
-
|
10
|
-
# (see Translatomatic::ResourceFile::Base#
|
11
|
-
def
|
12
|
-
super(
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
3
|
+
class XML < Base
|
4
|
+
|
5
|
+
# (see Translatomatic::ResourceFile::Base.extensions)
|
6
|
+
def self.extensions
|
7
|
+
%w{xml}
|
8
|
+
end
|
9
|
+
|
10
|
+
# (see Translatomatic::ResourceFile::Base#set)
|
11
|
+
def set(key, value)
|
12
|
+
super(key, value)
|
13
|
+
if @nodemap.include?(key)
|
14
|
+
@nodemap[key].content = value
|
15
|
+
else
|
16
|
+
create_node(key, value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# (see Translatomatic::ResourceFile::Base#save)
|
21
|
+
def save(target = path, options = {})
|
22
|
+
if @doc
|
23
|
+
add_created_by unless options[:no_created_by]
|
24
|
+
target.write(@doc.to_xml(indent: 2))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def init
|
31
|
+
@nodemap = {}
|
32
|
+
@doc = empty_doc
|
33
|
+
end
|
34
|
+
|
35
|
+
def load
|
36
|
+
# parse xml with nokogiri
|
37
|
+
@doc = read_doc
|
38
|
+
init_nodemap
|
39
|
+
init_properties
|
40
|
+
end
|
41
|
+
|
42
|
+
def comment(text)
|
43
|
+
@doc.create_comment(text)
|
44
|
+
end
|
37
45
|
|
38
46
|
def add_created_by
|
39
47
|
@created_by ||= @doc.root.add_previous_sibling(comment(created_by))
|
40
48
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end # module
|
49
|
+
|
50
|
+
def init_properties
|
51
|
+
@properties = @nodemap.transform_values { |i| i ? i.content : nil }
|
52
|
+
end
|
53
|
+
|
54
|
+
# initialize nodemap and properties hash from nokogiri document
|
55
|
+
def init_nodemap
|
56
|
+
# map of key1 => node, key2 => node, ...
|
57
|
+
@keynum = 1
|
58
|
+
text_nodes = @doc.search(text_nodes_xpath)
|
59
|
+
text_nodes.each { |node| add_node(node) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def read_doc
|
63
|
+
doc = Nokogiri::XML(@path.open) do |config|
|
64
|
+
config.noblanks
|
65
|
+
end
|
66
|
+
parsing_error(doc.errors[0]) if doc.errors.present?
|
67
|
+
doc
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_node(key, value)
|
71
|
+
# separate nodes by whitespace
|
72
|
+
text_node = Nokogiri::XML::Text.new("\n", @doc)
|
73
|
+
@doc.root.add_child(text_node)
|
74
|
+
|
75
|
+
# create the key/value node
|
76
|
+
node = Nokogiri::XML::Node.new(key, @doc)
|
77
|
+
node.content = value
|
78
|
+
@doc.root.add_child(node)
|
79
|
+
|
80
|
+
@nodemap[key] = node
|
81
|
+
@properties[key] = node.content
|
82
|
+
end
|
83
|
+
|
84
|
+
def add_node(node)
|
85
|
+
return if whitespace?(node.content)
|
86
|
+
key = "key#{@keynum}"
|
87
|
+
@nodemap[key] = node
|
88
|
+
@keynum += 1
|
89
|
+
end
|
90
|
+
|
91
|
+
def empty_doc
|
92
|
+
Nokogiri::XML("<root />")
|
93
|
+
end
|
94
|
+
|
95
|
+
def text_nodes_xpath
|
96
|
+
'//text()'
|
97
|
+
end
|
98
|
+
|
99
|
+
def whitespace?(text)
|
100
|
+
text == nil || text.strip.length == 0
|
101
|
+
end
|
102
|
+
end # class
|
103
|
+
end # module
|