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,81 +1,110 @@
|
|
1
|
-
module Translatomatic::CLI
|
2
|
-
# Configuration functions for the command line interface
|
3
|
-
class Config < Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
# @param
|
19
|
-
# @return [
|
20
|
-
def
|
21
|
-
run { conf.
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "
|
25
|
-
thor_options(self, Translatomatic::CLI::CommonOptions)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "
|
35
|
-
thor_options(self, Translatomatic::CLI::CommonOptions)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
print_config_table(:key, :
|
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
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
1
|
+
module Translatomatic::CLI
|
2
|
+
# Configuration functions for the command line interface
|
3
|
+
class Config < Base
|
4
|
+
|
5
|
+
define_options(
|
6
|
+
{ name: :context, type: :string, aliases: "-c",
|
7
|
+
desc: t("cli.config.context"),
|
8
|
+
enum: Translatomatic::Config::CONTEXTS,
|
9
|
+
command_line_only: true
|
10
|
+
},
|
11
|
+
)
|
12
|
+
|
13
|
+
desc "set key value", t("cli.config.set")
|
14
|
+
thor_options(self, Translatomatic::CLI::CommonOptions)
|
15
|
+
thor_options(self, Translatomatic::CLI::Config)
|
16
|
+
# Change a configuration setting
|
17
|
+
# @param key [String] configuration key
|
18
|
+
# @param value [String] new value for the configuration
|
19
|
+
# @return [String] the new value
|
20
|
+
def set(key, *value)
|
21
|
+
run { conf.set(key, value, cli_option(:context)) }
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "remove key", t("cli.config.remove")
|
25
|
+
thor_options(self, Translatomatic::CLI::CommonOptions)
|
26
|
+
thor_options(self, Translatomatic::CLI::Config)
|
27
|
+
# Remove a configuration setting
|
28
|
+
# @param key [String] configuration key to remove
|
29
|
+
# @return [void]
|
30
|
+
def remove(key)
|
31
|
+
run { conf.remove(key, cli_option(:context)) }
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "list", t("cli.config.list")
|
35
|
+
thor_options(self, Translatomatic::CLI::CommonOptions)
|
36
|
+
thor_options(self, Translatomatic::CLI::Config)
|
37
|
+
# List current configuration settings
|
38
|
+
def list
|
39
|
+
run do
|
40
|
+
print_config_table(columns: [:key, :value],
|
41
|
+
context: cli_option(:context),
|
42
|
+
skip_blanks: true
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "describe", t("cli.config.describe")
|
48
|
+
thor_options(self, Translatomatic::CLI::CommonOptions)
|
49
|
+
thor_options(self, Translatomatic::CLI::Config)
|
50
|
+
# Describe available configuration settings
|
51
|
+
def describe
|
52
|
+
run do
|
53
|
+
print_config_table(columns: [:key, :type, :desc])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
CONFIG_HEADING_MAP = {
|
60
|
+
key: t("cli.config.name"),
|
61
|
+
type: t("cli.config.type"),
|
62
|
+
value: t("cli.config.value"),
|
63
|
+
desc: t("cli.config.desc"),
|
64
|
+
}
|
65
|
+
|
66
|
+
def print_config_table(options)
|
67
|
+
columns = options[:columns]
|
68
|
+
context = options[:context]
|
69
|
+
rows = []
|
70
|
+
|
71
|
+
if context
|
72
|
+
puts t("cli.config.context_configuration", context: context)
|
73
|
+
else
|
74
|
+
puts t("cli.config.configuration")
|
75
|
+
end
|
76
|
+
puts
|
77
|
+
Translatomatic::Config.options.each do |option|
|
78
|
+
key = option.name.to_s
|
79
|
+
next if option.command_line_only
|
80
|
+
next if options[:skip_blanks] && !conf.include?(key, context)
|
81
|
+
value = conf.get(key, context)
|
82
|
+
data = []
|
83
|
+
columns.each do |column|
|
84
|
+
data << case column
|
85
|
+
when :key
|
86
|
+
key
|
87
|
+
when :value
|
88
|
+
value.nil? ? "-" : value
|
89
|
+
when :type
|
90
|
+
t("config.types.#{option.type}")
|
91
|
+
when :desc
|
92
|
+
option.description
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rows << data
|
96
|
+
end
|
97
|
+
|
98
|
+
if rows.empty?
|
99
|
+
puts t("cli.config.no_config")
|
100
|
+
else
|
101
|
+
rows.sort_by { |i| i[0] }
|
102
|
+
headings = columns.collect { |i| CONFIG_HEADING_MAP[i] }
|
103
|
+
rows.unshift headings.collect { |i| i.gsub(/\w/, '=') }
|
104
|
+
rows.unshift headings
|
105
|
+
print_table(rows, indent: 2)
|
106
|
+
end
|
107
|
+
puts
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
|
-
# Command line interface to translatomatic
|
1
|
+
# Command line interface to translatomatic
|
2
2
|
module Translatomatic::CLI
|
3
3
|
# Main command line interface
|
4
|
-
class Main < Base
|
4
|
+
class Main < Base
|
5
|
+
|
6
|
+
default_task :translate
|
5
7
|
|
6
8
|
begin
|
7
|
-
|
8
|
-
I18n.default_locale = config.default_locale
|
9
|
+
I18n.default_locale = Translatomatic.config.default_locale
|
9
10
|
end
|
10
|
-
|
11
|
-
package_name "Translatomatic"
|
12
|
-
map %W[-v --version] => :version
|
11
|
+
|
12
|
+
package_name "Translatomatic"
|
13
|
+
map %W[-v --version] => :version
|
13
14
|
map %W[-L --list] => :translators
|
14
15
|
|
15
16
|
desc "translate", t("cli.translate.subcommand")
|
@@ -20,8 +21,8 @@ module Translatomatic::CLI
|
|
20
21
|
|
21
22
|
desc "config", t("cli.config.subcommand")
|
22
23
|
subcommand "config", Config
|
23
|
-
|
24
|
-
desc "display file [key...]", t("cli.display_values")
|
24
|
+
|
25
|
+
desc "display file [key...]", t("cli.display_values")
|
25
26
|
thor_options(self, Translatomatic::CLI::CommonOptions)
|
26
27
|
method_option :locales, type: :string, desc: t("cli.locales_to_display")
|
27
28
|
method_option :sentences, type: :boolean, desc: t("cli.display_sentences")
|
@@ -29,84 +30,96 @@ module Translatomatic::CLI
|
|
29
30
|
# @param file [String] Path to resource file
|
30
31
|
# @param keys [Array<String>] Optional list of locales
|
31
32
|
# @return [void]
|
32
|
-
def display(file, *keys)
|
33
|
-
run do
|
34
|
-
source = Translatomatic::ResourceFile.load(file)
|
35
|
-
keys = source.properties.keys if keys.empty?
|
36
|
-
display_keys(source, keys)
|
37
|
-
|
38
|
-
# TODO: if locales not specified, determine the list of locales from
|
33
|
+
def display(file, *keys)
|
34
|
+
run do
|
35
|
+
source = Translatomatic::ResourceFile.load(file)
|
36
|
+
keys = source.properties.keys if keys.empty?
|
37
|
+
display_keys(source, keys)
|
38
|
+
|
39
|
+
# TODO: if locales not specified, determine the list of locales from
|
39
40
|
# all the files in the resource bundle.
|
40
41
|
locales = parse_list(options[:locales])
|
41
42
|
locales << Translatomatic::Locale.default.to_s if locales.empty?
|
42
43
|
locales.each do |tag|
|
43
44
|
locale = locale(tag)
|
44
45
|
next if locale == source.locale
|
45
|
-
display_properties(source, keys, locale)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
46
|
+
display_properties(source, keys, locale)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
50
51
|
desc "strings file [file...]", t("cli.extract_strings")
|
51
52
|
thor_options(self, Translatomatic::CLI::CommonOptions)
|
52
53
|
# Extract strings from non-resource files
|
53
54
|
# @param files [Array<String>] List of paths to files
|
54
|
-
# @return [void]
|
55
|
-
def strings(*files)
|
56
|
-
run do
|
57
|
-
strings = []
|
58
|
-
files.each do |file|
|
59
|
-
extractor = Translatomatic::Extractor::Base.new(file)
|
60
|
-
strings << extractor.extract
|
61
|
-
end
|
62
|
-
puts strings.join("\n")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
55
|
+
# @return [void]
|
56
|
+
def strings(*files)
|
57
|
+
run do
|
58
|
+
strings = []
|
59
|
+
files.each do |file|
|
60
|
+
extractor = Translatomatic::Extractor::Base.new(file)
|
61
|
+
strings << extractor.extract
|
62
|
+
end
|
63
|
+
puts strings.join("\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "convert source target", t("cli.convert")
|
68
|
+
# Convert a resource file from one format to another
|
69
|
+
# @param source [String] An existing resource file
|
70
|
+
# @param target [String] The name of a target resource file
|
71
|
+
# @return [void]
|
72
|
+
def convert(source, target)
|
73
|
+
run do
|
74
|
+
converter = Translatomatic::Converter.new
|
75
|
+
converter.convert(source, target)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
66
79
|
desc "services", t("cli.list_backends")
|
67
80
|
thor_options(self, Translatomatic::CLI::CommonOptions)
|
68
81
|
# List available translator services
|
69
|
-
# @return [void]
|
70
|
-
def services
|
71
|
-
run { puts Translatomatic::Translator.list }
|
72
|
-
end
|
73
|
-
|
82
|
+
# @return [void]
|
83
|
+
def services
|
84
|
+
run { puts Translatomatic::Translator.list }
|
85
|
+
end
|
86
|
+
|
74
87
|
desc 'version', t("cli.display_version")
|
75
88
|
thor_options(self, Translatomatic::CLI::CommonOptions)
|
76
89
|
# Display version number
|
77
|
-
# @return [void]
|
78
|
-
def version
|
79
|
-
puts "Translatomatic v#{Translatomatic::VERSION}"
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
def display_properties(source, keys, locale)
|
85
|
-
path = source.locale_path(locale)
|
86
|
-
if path.exist?
|
87
|
-
resource = Translatomatic::ResourceFile.load(path)
|
88
|
-
display_keys(resource, keys)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def display_keys(source, keys)
|
90
|
+
# @return [void]
|
91
|
+
def version
|
92
|
+
puts "Translatomatic v#{Translatomatic::VERSION}"
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def display_properties(source, keys, locale)
|
98
|
+
path = source.locale_path(locale)
|
99
|
+
if path.exist?
|
100
|
+
resource = Translatomatic::ResourceFile.load(path)
|
101
|
+
display_keys(resource, keys)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def display_keys(source, keys)
|
93
106
|
puts t("cli.file_source", file: source)
|
94
|
-
rows = []
|
95
|
-
keys.each do |key|
|
96
|
-
value = source.get(key)
|
97
|
-
rows << [key + ":", value]
|
98
|
-
end
|
99
|
-
print_table(rows, indent: 2)
|
100
|
-
|
101
|
-
if options[:sentences]
|
107
|
+
rows = []
|
108
|
+
keys.each do |key|
|
109
|
+
value = source.get(key)
|
110
|
+
rows << [key + ":", value]
|
111
|
+
end
|
112
|
+
print_table(rows, indent: 2)
|
113
|
+
|
114
|
+
if options[:sentences]
|
102
115
|
puts t("cli.sentences")
|
103
|
-
source.sentences.each do |sentence|
|
104
|
-
puts "- " + sentence.to_s
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
puts
|
109
|
-
end
|
110
|
-
|
111
|
-
end # class
|
112
|
-
end # module
|
116
|
+
source.sentences.each do |sentence|
|
117
|
+
puts "- " + sentence.to_s
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
puts
|
122
|
+
end
|
123
|
+
|
124
|
+
end # class
|
125
|
+
end # module
|
@@ -1,16 +1,25 @@
|
|
1
|
-
|
1
|
+
require 'ruby-progressbar'
|
2
|
+
|
3
|
+
# Command line interface to translatomatic
|
2
4
|
module Translatomatic::CLI
|
3
|
-
# Translation functions for the command line interface
|
4
|
-
class Translate < Base
|
5
|
+
# Translation functions for the command line interface
|
6
|
+
class Translate < Base
|
7
|
+
|
8
|
+
default_task :file
|
5
9
|
|
6
10
|
define_options(
|
7
11
|
{ name: :translator, type: :array, aliases: "-t",
|
8
|
-
desc: t("
|
12
|
+
desc: t("cli.translate.translator"),
|
13
|
+
enum: Translatomatic::Translator.names
|
9
14
|
},
|
10
15
|
{ name: :source_locale, desc: t("cli.source_locale") },
|
11
16
|
{ name: :share, desc: t("cli.share"), default: false },
|
12
17
|
{ name: :target_locales, desc: t("cli.target_locales"),
|
13
|
-
type: :array
|
18
|
+
type: :array
|
19
|
+
},
|
20
|
+
{ name: :source_files, desc: t("cli.source_files"),
|
21
|
+
type: :array
|
22
|
+
},
|
14
23
|
)
|
15
24
|
|
16
25
|
desc "string text locale...", t("cli.translate.string")
|
@@ -19,11 +28,13 @@ module Translatomatic::CLI
|
|
19
28
|
thor_options(self, Translatomatic::Translator.modules)
|
20
29
|
# Translate a string to target locales
|
21
30
|
# @param text [String] String to translate
|
22
|
-
# @param locales [Array<String>] List of target locales
|
31
|
+
# @param locales [Array<String>] List of target locales, can also be set
|
32
|
+
# with the --target-locales option
|
23
33
|
# @return [void]
|
24
34
|
def string(text, *locales)
|
25
35
|
run do
|
26
|
-
setup_translation
|
36
|
+
setup_translation
|
37
|
+
determine_target_locales(locales)
|
27
38
|
|
28
39
|
puts "(%s) %s" % [@source_locale, text]
|
29
40
|
@translators.each do |translator|
|
@@ -38,109 +49,133 @@ module Translatomatic::CLI
|
|
38
49
|
finish_log
|
39
50
|
end
|
40
51
|
end
|
41
|
-
|
42
|
-
desc "file filename locale...", t("cli.translate.file")
|
52
|
+
|
53
|
+
desc "file filename locale...", t("cli.translate.file")
|
43
54
|
thor_options(self, Translatomatic::CLI::CommonOptions)
|
44
55
|
thor_options(self, Translatomatic::CLI::Translate)
|
45
|
-
thor_options(self, Translatomatic::
|
56
|
+
thor_options(self, Translatomatic::FileTranslator)
|
46
57
|
thor_options(self, Translatomatic::Database)
|
47
58
|
thor_options(self, Translatomatic::Translator.modules)
|
48
59
|
# Translate files to target locales
|
49
|
-
# @param file [String] Resource file to translate
|
50
|
-
#
|
60
|
+
# @param file [String] Resource file to translate, can also be set
|
61
|
+
# with the --source-files option.
|
62
|
+
# @param locales [Array<String>] List of target locales, can also be set
|
63
|
+
# with the --target-locales option
|
51
64
|
# @return [void]
|
52
|
-
def file(file, *locales)
|
53
|
-
run do
|
54
|
-
setup_translation
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# set up
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
@
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
65
|
+
def file(file = nil, *locales)
|
66
|
+
run do
|
67
|
+
setup_translation
|
68
|
+
determine_target_locales(locales)
|
69
|
+
|
70
|
+
# check source file(s) exist and they can be loaded
|
71
|
+
source_files = parse_list(cli_option(:source_files), file)
|
72
|
+
source_files.each do |source_file|
|
73
|
+
path = source_path(source_file)
|
74
|
+
raise t("file.not_found", file: path) unless File.exist?(path)
|
75
|
+
source = Translatomatic::ResourceFile.load(path, @source_locale)
|
76
|
+
raise t("file.unsupported", file: path) unless source
|
77
|
+
end
|
78
|
+
|
79
|
+
# set up database
|
80
|
+
Translatomatic::Database.new(options)
|
81
|
+
|
82
|
+
# set up file translatiln
|
83
|
+
translation_count = calculate_translation_count(source_files, @target_locales)
|
84
|
+
ft_options = options.merge(
|
85
|
+
translator: @translators,
|
86
|
+
listener: progress_updater(translation_count)
|
87
|
+
)
|
88
|
+
ft = Translatomatic::FileTranslator.new(ft_options)
|
89
|
+
|
90
|
+
source_files.each do |path|
|
91
|
+
# read source file
|
92
|
+
source = Translatomatic::ResourceFile.load(path, @source_locale)
|
93
|
+
|
94
|
+
# convert source to locale(s) and write files
|
95
|
+
@target_locales.each do |i|
|
96
|
+
to_locale = locale(i)
|
97
|
+
next if to_locale.language == source.locale.language
|
98
|
+
ft.translate_to_file(source, to_locale)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
log.info ft.stats
|
103
|
+
finish_log
|
104
|
+
|
105
|
+
share_translations(ft) if cli_option(:share)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def setup_translation
|
112
|
+
@source_locale = determine_source_locale
|
113
|
+
# resolve translators
|
114
|
+
@translators = Translatomatic::Translator.resolve(
|
115
|
+
cli_option(:translator), options
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def determine_target_locales(locales)
|
120
|
+
@target_locales = parse_list(locales, cli_option(:target_locales))
|
121
|
+
raise t("cli.locales_required") if @target_locales.empty?
|
122
|
+
end
|
123
|
+
|
124
|
+
def determine_source_locale
|
125
|
+
cli_option(:source_locale) || conf.default_locale
|
126
|
+
end
|
127
|
+
|
128
|
+
def calculate_translation_count(source_files, locales)
|
129
|
+
count = 0
|
130
|
+
source_files.each do |file|
|
131
|
+
source = Translatomatic::ResourceFile.load(file, @source_locale)
|
132
|
+
count += source.sentences.length * locales.length
|
133
|
+
end
|
134
|
+
count
|
135
|
+
end
|
136
|
+
|
137
|
+
def share_translations(ft)
|
138
|
+
return if ft.db_translations.empty?
|
139
|
+
|
140
|
+
tmx = Translatomatic::TMX::Document.from_texts(ft.db_translations)
|
141
|
+
available = Translatomatic::Translator.available(options)
|
142
|
+
available.each do |translator|
|
143
|
+
if translator.respond_to?(:upload)
|
119
144
|
log.info(t("cli.uploading_tmx", name: translator.name))
|
120
|
-
translator.upload(tmx)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
ActiveRecord::Base.transaction do
|
125
|
-
|
126
|
-
text.update(shared: true) if text.is_translated?
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
145
|
+
translator.upload(tmx)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
ActiveRecord::Base.transaction do
|
150
|
+
ft.db_translations.each do |text|
|
151
|
+
text.update(shared: true) if text.is_translated?
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# convert the given path to an absolute path if necessary, relative
|
157
|
+
# to project root.
|
158
|
+
def source_path(path)
|
159
|
+
if path.start_with?("~/")
|
160
|
+
# replace ~/ with home directory
|
161
|
+
path = path.sub(/\A~\//, Dir.home + "/")
|
162
|
+
end
|
163
|
+
File.absolute_path(path, conf.project_path)
|
164
|
+
end
|
165
|
+
|
166
|
+
# create a progress bar and progress updater
|
167
|
+
def progress_updater(translation_count)
|
168
|
+
return nil unless cli_option(:wank)
|
169
|
+
# set up progress bar
|
170
|
+
progressbar = ProgressBar.create(
|
171
|
+
title: t("cli.translating"),
|
172
|
+
format: "%t: |%B| %E ",
|
173
|
+
autofinish: false,
|
174
|
+
total: translation_count
|
175
|
+
)
|
176
|
+
conf.logger.progressbar = progressbar
|
177
|
+
Translatomatic::ProgressUpdater.new(progressbar)
|
178
|
+
end
|
179
|
+
|
180
|
+
end # class
|
181
|
+
end # module
|