translatomatic 0.1.2 → 0.1.3
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 +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
@@ -1,116 +1,94 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Translatomatic::ResourceFile
|
4
|
-
# YAML resource file
|
5
|
-
# @see http://www.yaml.org/
|
6
|
-
class YAML < Base
|
7
|
-
|
8
|
-
# (see Translatomatic::ResourceFile::Base.extensions)
|
9
|
-
def self.extensions
|
10
|
-
%w{yml yaml}
|
11
|
-
end
|
12
|
-
|
13
|
-
# (see Translatomatic::ResourceFile::Base
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
path
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
out =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
def flatten_data(data)
|
98
|
-
result = {}
|
99
|
-
unless data.kind_of?(Hash)
|
100
|
-
@valid = false
|
101
|
-
return {}
|
102
|
-
end
|
103
|
-
data.each do |key, value|
|
104
|
-
if value.kind_of?(Hash)
|
105
|
-
children = flatten_data(value)
|
106
|
-
children.each do |ck, cv|
|
107
|
-
result[key + "." + ck] = cv
|
108
|
-
end
|
109
|
-
else
|
110
|
-
result[key] = value
|
111
|
-
end
|
112
|
-
end
|
113
|
-
result
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Translatomatic::ResourceFile
|
4
|
+
# YAML resource file
|
5
|
+
# @see http://www.yaml.org/
|
6
|
+
class YAML < Base
|
7
|
+
|
8
|
+
# (see Translatomatic::ResourceFile::Base.extensions)
|
9
|
+
def self.extensions
|
10
|
+
%w{yml yaml}
|
11
|
+
end
|
12
|
+
|
13
|
+
# (see Translatomatic::ResourceFile::Base.is_key_value?)
|
14
|
+
def self.is_key_value?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
# (see Translatomatic::ResourceFile::Base.supports_variable_interpolation?)
|
19
|
+
def self.supports_variable_interpolation?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# (see Translatomatic::ResourceFile::Base#locale_path)
|
24
|
+
# @note localization files in rails use the following file name
|
25
|
+
# convention: config/locales/en.yml.
|
26
|
+
def locale_path(locale)
|
27
|
+
if path.to_s.match(/config\/locales\/[-\w]+.yml$/)
|
28
|
+
# rails style
|
29
|
+
filename = locale.to_s + path.extname
|
30
|
+
path.dirname + filename
|
31
|
+
else
|
32
|
+
super(locale)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# (see Translatomatic::ResourceFile::Base#set)
|
37
|
+
def set(key, value)
|
38
|
+
super(key, value)
|
39
|
+
|
40
|
+
hash = @data
|
41
|
+
path = key.to_s.split(/\./)
|
42
|
+
last_key = path.pop
|
43
|
+
path.each { |i| hash = (hash[i] ||= {}) }
|
44
|
+
hash[last_key] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
# (see Translatomatic::ResourceFile::Base#save)
|
48
|
+
def save(target = path, options = {})
|
49
|
+
if @data
|
50
|
+
data = @data
|
51
|
+
data = data.transform_keys { locale.language } if ruby_i18n?
|
52
|
+
out = data.to_yaml
|
53
|
+
out.sub!(/^---\n/m, '')
|
54
|
+
out = comment(created_by) + "\n" + out unless options[:no_created_by]
|
55
|
+
target.write(out)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# (see Translatomatic::ResourceFile::Base#create_variable)
|
60
|
+
def create_variable(name)
|
61
|
+
return "%{#{name}}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# (see Translatomatic::ResourceFile::Base#variable_regex)
|
65
|
+
def variable_regex
|
66
|
+
/\%\s*\{.*?\}/
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def init
|
72
|
+
# yaml data
|
73
|
+
@data = {}
|
74
|
+
end
|
75
|
+
|
76
|
+
def load
|
77
|
+
@data = ::YAML.load_file(path.to_s) || {}
|
78
|
+
@properties = flatten(@data)
|
79
|
+
end
|
80
|
+
|
81
|
+
# true if this resource file looks like a ruby i18n data file.
|
82
|
+
def ruby_i18n?
|
83
|
+
if @data && @data.length == 1
|
84
|
+
lang = @data.keys[0]
|
85
|
+
Translatomatic::Locale.new(lang).valid?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def comment(text)
|
90
|
+
"# #{text}\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -1,78 +1,87 @@
|
|
1
|
-
|
2
|
-
module Translatomatic
|
3
|
-
# Provides methods to create resource files of various types.
|
4
|
-
module ResourceFile
|
5
|
-
class << self
|
6
|
-
include Translatomatic::Util
|
7
|
-
end
|
8
|
-
|
9
|
-
# Load a resource file. If locale is not specified, the locale of the
|
10
|
-
# file will be determined from the filename, or else the current default
|
11
|
-
# locale will be used.
|
12
|
-
# @param path [String] Path to the resource file
|
13
|
-
# @param locale [String] Locale of the resource file
|
14
|
-
# @return [Translatomatic::ResourceFile::Base] The resource file, or nil
|
15
|
-
# if the file type is unsupported.
|
16
|
-
def self.load(path, locale = nil)
|
17
|
-
path = path.kind_of?(Pathname) ? path : Pathname.new(path)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
# @
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
path.
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
75
|
-
|
76
|
-
require 'translatomatic/resource_file/
|
77
|
-
require 'translatomatic/resource_file/
|
78
|
-
require 'translatomatic/resource_file/
|
1
|
+
|
2
|
+
module Translatomatic
|
3
|
+
# Provides methods to create resource files of various types.
|
4
|
+
module ResourceFile
|
5
|
+
class << self
|
6
|
+
include Translatomatic::Util
|
7
|
+
end
|
8
|
+
|
9
|
+
# Load a resource file. If locale is not specified, the locale of the
|
10
|
+
# file will be determined from the filename, or else the current default
|
11
|
+
# locale will be used.
|
12
|
+
# @param path [String] Path to the resource file
|
13
|
+
# @param locale [String] Locale of the resource file
|
14
|
+
# @return [Translatomatic::ResourceFile::Base] The resource file, or nil
|
15
|
+
# if the file type is unsupported.
|
16
|
+
def self.load(path, locale = nil)
|
17
|
+
path = path.kind_of?(Pathname) ? path : Pathname.new(path)
|
18
|
+
types_for_path(path).each do |klass|
|
19
|
+
log.debug(t("file.loading", file: path, name: klass.name.demodulize))
|
20
|
+
return klass.new(path, locale: locale)
|
21
|
+
end
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# Create a new resource file
|
26
|
+
def self.create(path, locale = nil)
|
27
|
+
klass = const_get(klass_name)
|
28
|
+
klass.new
|
29
|
+
end
|
30
|
+
|
31
|
+
# Find all resource files under the given directory. Follows symlinks.
|
32
|
+
# @param path [String, Pathname] The path to search from
|
33
|
+
# @return [Array<Translatomatic::ResourceFile>] Resource files found
|
34
|
+
def self.find(path, options = {})
|
35
|
+
files = []
|
36
|
+
include_dot_directories = options[:include_dot_directories]
|
37
|
+
path = Pathname.new(path) unless path.kind_of?(Pathname)
|
38
|
+
path.find do |file|
|
39
|
+
if !include_dot_directories && file.basename.to_s[0] == ?.
|
40
|
+
Find.prune
|
41
|
+
else
|
42
|
+
resource = load(file)
|
43
|
+
files << resource if resource
|
44
|
+
end
|
45
|
+
end
|
46
|
+
files
|
47
|
+
end
|
48
|
+
|
49
|
+
# Find all configured resource file classes
|
50
|
+
# @return [Array<Class>] Available resource file classes
|
51
|
+
def self.types
|
52
|
+
@types ||= self.constants.map { |c| self.const_get(c) }.select do |klass|
|
53
|
+
klass.is_a?(Class) && klass != Base
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# find classes that can load the given path by file extension
|
60
|
+
def self.types_for_path(path)
|
61
|
+
path = path.kind_of?(Pathname) ? path : Pathname.new(path)
|
62
|
+
types.select { |klass| klass.enabled? && extension_match(klass, path) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.extension_match(klass, path)
|
66
|
+
filename = path.basename.to_s.downcase
|
67
|
+
klass.extensions.each do |extension|
|
68
|
+
# don't match end of line in case file has locale extension
|
69
|
+
return true if filename.match(/\.#{extension}/)
|
70
|
+
end
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
require 'translatomatic/resource_file/base'
|
77
|
+
require 'translatomatic/resource_file/yaml'
|
78
|
+
require 'translatomatic/resource_file/properties'
|
79
|
+
require 'translatomatic/resource_file/text'
|
80
|
+
require 'translatomatic/resource_file/xml'
|
81
|
+
require 'translatomatic/resource_file/html'
|
82
|
+
require 'translatomatic/resource_file/markdown'
|
83
|
+
require 'translatomatic/resource_file/xcode_strings'
|
84
|
+
require 'translatomatic/resource_file/plist'
|
85
|
+
require 'translatomatic/resource_file/resw'
|
86
|
+
require 'translatomatic/resource_file/subtitle'
|
87
|
+
require 'translatomatic/resource_file/csv'
|