translatomatic 0.1.3 → 0.2.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.
Files changed (139) hide show
  1. checksums.yaml +5 -5
  2. data/.gitattributes +20 -20
  3. data/.gitignore +19 -15
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +28 -0
  6. data/.translatomatic/config.yml +4 -0
  7. data/.travis.yml +4 -6
  8. data/.yardopts +9 -9
  9. data/Gemfile +8 -4
  10. data/Guardfile +4 -5
  11. data/README.de.md +55 -50
  12. data/README.en.md +177 -0
  13. data/README.es.md +53 -48
  14. data/README.fr.md +53 -48
  15. data/README.it.md +54 -49
  16. data/README.ja.md +63 -58
  17. data/README.ko.md +59 -54
  18. data/README.md +17 -13
  19. data/README.ms.md +50 -45
  20. data/README.pt.md +54 -49
  21. data/README.ru.md +57 -52
  22. data/README.sv.md +51 -46
  23. data/README.zh.md +60 -55
  24. data/Rakefile +3 -3
  25. data/TODO.txt +6 -0
  26. data/bin/console +3 -3
  27. data/bin/translatomatic +4 -2
  28. data/config/i18n-tasks.yml +130 -0
  29. data/config/locales/translatomatic/de.yml +141 -99
  30. data/config/locales/translatomatic/en.yml +129 -89
  31. data/config/locales/translatomatic/es.yml +136 -99
  32. data/config/locales/translatomatic/fr.yml +139 -100
  33. data/config/locales/translatomatic/it.yml +135 -97
  34. data/config/locales/translatomatic/ja.yml +137 -98
  35. data/config/locales/translatomatic/ko.yml +138 -98
  36. data/config/locales/translatomatic/ms.yml +138 -100
  37. data/config/locales/translatomatic/pt.yml +137 -101
  38. data/config/locales/translatomatic/ru.yml +136 -98
  39. data/config/locales/translatomatic/sv.yml +134 -96
  40. data/config/locales/translatomatic/zh.yml +136 -97
  41. data/db/migrate/201712170000_initial.rb +2 -3
  42. data/lib/translatomatic.rb +40 -25
  43. data/lib/translatomatic/cli.rb +5 -1
  44. data/lib/translatomatic/cli/base.rb +61 -58
  45. data/lib/translatomatic/cli/common_options.rb +14 -11
  46. data/lib/translatomatic/cli/config.rb +96 -91
  47. data/lib/translatomatic/cli/database.rb +85 -23
  48. data/lib/translatomatic/cli/main.rb +158 -104
  49. data/lib/translatomatic/cli/thor.rb +29 -0
  50. data/lib/translatomatic/cli/translate.rb +134 -157
  51. data/lib/translatomatic/config.rb +10 -301
  52. data/lib/translatomatic/config/display.rb +78 -0
  53. data/lib/translatomatic/config/files.rb +60 -0
  54. data/lib/translatomatic/config/location_settings.rb +133 -0
  55. data/lib/translatomatic/config/options.rb +68 -0
  56. data/lib/translatomatic/config/selector.rb +127 -0
  57. data/lib/translatomatic/config/settings.rb +148 -0
  58. data/lib/translatomatic/converter.rb +40 -28
  59. data/lib/translatomatic/database.rb +127 -110
  60. data/lib/translatomatic/define_options.rb +4 -5
  61. data/lib/translatomatic/escaped_unicode.rb +86 -76
  62. data/lib/translatomatic/extractor.rb +5 -2
  63. data/lib/translatomatic/extractor/base.rb +12 -12
  64. data/lib/translatomatic/extractor/ruby.rb +7 -6
  65. data/lib/translatomatic/file_translator.rb +101 -244
  66. data/lib/translatomatic/flattenation.rb +39 -0
  67. data/lib/translatomatic/http.rb +13 -0
  68. data/lib/translatomatic/http/client.rb +144 -0
  69. data/lib/translatomatic/http/exception.rb +43 -0
  70. data/lib/translatomatic/http/file_param.rb +27 -0
  71. data/lib/translatomatic/http/param.rb +37 -0
  72. data/lib/translatomatic/http/request.rb +91 -0
  73. data/lib/translatomatic/i18n.rb +43 -0
  74. data/lib/translatomatic/locale.rb +71 -59
  75. data/lib/translatomatic/logger.rb +43 -28
  76. data/lib/translatomatic/metadata.rb +58 -0
  77. data/lib/translatomatic/model.rb +4 -2
  78. data/lib/translatomatic/model/locale.rb +5 -5
  79. data/lib/translatomatic/model/text.rb +5 -5
  80. data/lib/translatomatic/option.rb +57 -34
  81. data/lib/translatomatic/path_utils.rb +126 -0
  82. data/lib/translatomatic/progress_updater.rb +13 -16
  83. data/lib/translatomatic/provider.rb +101 -0
  84. data/lib/translatomatic/provider/base.rb +136 -0
  85. data/lib/translatomatic/provider/frengly.rb +55 -0
  86. data/lib/translatomatic/provider/google.rb +78 -0
  87. data/lib/translatomatic/provider/google_web.rb +50 -0
  88. data/lib/translatomatic/provider/microsoft.rb +144 -0
  89. data/lib/translatomatic/provider/my_memory.rb +75 -0
  90. data/lib/translatomatic/provider/yandex.rb +61 -0
  91. data/lib/translatomatic/resource_file.rb +59 -53
  92. data/lib/translatomatic/resource_file/base.rb +171 -237
  93. data/lib/translatomatic/resource_file/csv.rb +176 -24
  94. data/lib/translatomatic/resource_file/html.rb +21 -42
  95. data/lib/translatomatic/resource_file/key_value_support.rb +117 -0
  96. data/lib/translatomatic/resource_file/markdown.rb +36 -38
  97. data/lib/translatomatic/resource_file/plist.rb +121 -126
  98. data/lib/translatomatic/resource_file/po.rb +104 -82
  99. data/lib/translatomatic/resource_file/properties.rb +48 -77
  100. data/lib/translatomatic/resource_file/properties.treetop +87 -0
  101. data/lib/translatomatic/resource_file/resw.rb +56 -41
  102. data/lib/translatomatic/resource_file/subtitle.rb +86 -54
  103. data/lib/translatomatic/resource_file/text.rb +18 -18
  104. data/lib/translatomatic/resource_file/xcode_strings.rb +32 -63
  105. data/lib/translatomatic/resource_file/xcode_strings.treetop +85 -0
  106. data/lib/translatomatic/resource_file/xml.rb +94 -81
  107. data/lib/translatomatic/resource_file/yaml.rb +54 -68
  108. data/lib/translatomatic/retry_executor.rb +37 -0
  109. data/lib/translatomatic/slurp.rb +32 -0
  110. data/lib/translatomatic/string_batcher.rb +50 -0
  111. data/lib/translatomatic/string_escaping.rb +61 -0
  112. data/lib/translatomatic/text.rb +263 -0
  113. data/lib/translatomatic/text_collection.rb +66 -0
  114. data/lib/translatomatic/tmx.rb +5 -3
  115. data/lib/translatomatic/tmx/document.rb +107 -82
  116. data/lib/translatomatic/tmx/translation_unit.rb +19 -18
  117. data/lib/translatomatic/translation.rb +8 -28
  118. data/lib/translatomatic/translation/collection.rb +199 -0
  119. data/lib/translatomatic/translation/fetcher.rb +123 -0
  120. data/lib/translatomatic/translation/munging.rb +112 -0
  121. data/lib/translatomatic/translation/result.rb +50 -0
  122. data/lib/translatomatic/translation/sharer.rb +32 -0
  123. data/lib/translatomatic/translation/stats.rb +44 -0
  124. data/lib/translatomatic/translator.rb +91 -88
  125. data/lib/translatomatic/type_cast.rb +63 -0
  126. data/lib/translatomatic/util.rb +37 -33
  127. data/lib/translatomatic/version.rb +2 -2
  128. data/translatomatic.gemspec +57 -46
  129. metadata +136 -59
  130. data/lib/translatomatic/http_request.rb +0 -162
  131. data/lib/translatomatic/string.rb +0 -188
  132. data/lib/translatomatic/translation_result.rb +0 -86
  133. data/lib/translatomatic/translation_stats.rb +0 -31
  134. data/lib/translatomatic/translator/base.rb +0 -128
  135. data/lib/translatomatic/translator/frengly.rb +0 -62
  136. data/lib/translatomatic/translator/google.rb +0 -37
  137. data/lib/translatomatic/translator/microsoft.rb +0 -41
  138. data/lib/translatomatic/translator/my_memory.rb +0 -68
  139. data/lib/translatomatic/translator/yandex.rb +0 -56
@@ -8,7 +8,7 @@ class Initial < ActiveRecord::Migration[4.2] # :nodoc:
8
8
  t.timestamps
9
9
  end
10
10
 
11
- add_index :locales, [:language, :script, :region], unique: true
11
+ add_index :locales, %i[language script region], unique: true
12
12
 
13
13
  create_table :texts do |t|
14
14
  t.belongs_to :locale, index: true, null: false
@@ -17,9 +17,8 @@ class Initial < ActiveRecord::Migration[4.2] # :nodoc:
17
17
  }
18
18
  t.text :value, null: false
19
19
  t.boolean :shared, null: false, default: false, index: true
20
- t.string :translator
20
+ t.string :provider
21
21
  t.timestamps
22
22
  end
23
-
24
23
  end
25
24
  end
@@ -1,52 +1,67 @@
1
- require 'i18n'
2
- require 'rails-i18n'
3
- require 'i18n_data'
1
+ # gem :rchardet19, provided_by: :rchardet
2
+ # titlekit has rchardet19 dependency, but we don't want that.
3
+ dependency = Gem::Dependency.new('rchardet19')
4
+ specs = dependency.matching_specs
5
+ if specs
6
+ path = File.join(specs[0].full_gem_path, 'lib')
7
+ $LOAD_PATH.delete(path)
8
+ end
4
9
 
5
10
  require 'pathname'
6
11
  require 'active_support/core_ext/hash'
7
- require 'active_support/dependencies/autoload'
12
+ require 'rchardet'
8
13
 
9
14
  # Module containing all of the translation goodness
10
15
  module Translatomatic
16
+ class << self
17
+ attr_writer :logger
18
+ attr_writer :config
11
19
 
12
- # @return [Translatomatic::Config] configuration
13
- def self.config
14
- @config ||= Translatomatic::Config.new
15
- end
16
-
17
- private
20
+ # @return [Logger] Translatomatic logger instance
21
+ def logger
22
+ @logger ||= Translatomatic::Logger.new
23
+ end
18
24
 
19
- def self.init_i18n(lib_path)
20
- locale_path = File.join(File.dirname(lib_path), "..", "config", "locales")
21
- I18n.load_path += Dir[File.join(locale_path, "**", "*.yml")]
25
+ # @return [Translatomatic::Config] Configuration settings
26
+ def config
27
+ @config ||= Translatomatic::Config::Settings.new
28
+ end
22
29
  end
23
30
  end
24
31
 
25
- begin
26
- Translatomatic.init_i18n(__FILE__)
27
- end
28
-
29
32
  require 'translatomatic/version'
30
- require 'translatomatic/option'
31
- require 'translatomatic/define_options'
32
33
  require 'translatomatic/locale'
33
- require 'translatomatic/string'
34
- require 'translatomatic/translation'
34
+ require 'translatomatic/slurp'
35
+ require 'translatomatic/i18n'
35
36
  require 'translatomatic/util'
37
+ require 'translatomatic/option'
38
+ require 'translatomatic/define_options'
39
+ require 'translatomatic/flattenation'
40
+ require 'translatomatic/string_batcher'
41
+ require 'translatomatic/path_utils'
42
+ require 'translatomatic/string_escaping'
43
+ require 'translatomatic/text'
44
+ require 'translatomatic/text_collection'
45
+ require 'translatomatic/retry_executor'
36
46
  require 'translatomatic/version'
37
47
  require 'translatomatic/logger'
48
+ require 'translatomatic/type_cast'
38
49
  require 'translatomatic/config'
39
50
  require 'translatomatic/database'
51
+ require 'translatomatic/translation'
40
52
  require 'translatomatic/escaped_unicode'
41
53
  require 'translatomatic/model'
54
+ require 'translatomatic/metadata'
42
55
  require 'translatomatic/resource_file'
43
- require 'translatomatic/http_request'
56
+ require 'translatomatic/http'
44
57
  require 'translatomatic/converter'
45
- require 'translatomatic/translator'
46
- require 'translatomatic/translation_result'
47
- require 'translatomatic/translation_stats'
58
+ require 'translatomatic/provider'
48
59
  require 'translatomatic/file_translator'
49
60
  require 'translatomatic/extractor'
50
61
  require 'translatomatic/progress_updater'
51
62
  require 'translatomatic/tmx'
63
+ require 'translatomatic/translator'
52
64
  require 'translatomatic/cli'
65
+
66
+ # monkey patches
67
+ Thor::Option.prepend Translatomatic::CLI::ThorPatch::NoNo
@@ -1,5 +1,9 @@
1
- module Translatomatic::CLI; end
1
+ module Translatomatic
2
+ # Command line functions
3
+ module CLI; end
4
+ end
2
5
 
6
+ require 'translatomatic/cli/thor'
3
7
  require 'translatomatic/cli/common_options'
4
8
  require 'translatomatic/cli/base'
5
9
  require 'translatomatic/cli/translate'
@@ -1,81 +1,84 @@
1
1
  require 'thor'
2
+ require 'rainbow'
2
3
 
3
- module Translatomatic::CLI
4
- # Base class for command line interface classes
5
- class Base < Thor
4
+ module Translatomatic
5
+ module CLI
6
+ # Base class for command line interface classes
7
+ class Base < Thor
8
+ private
6
9
 
7
- private
10
+ include Translatomatic::Util
11
+ include Translatomatic::DefineOptions
8
12
 
9
- include Translatomatic::Util
10
- include Translatomatic::DefineOptions
13
+ # creates thor options
14
+ class << self
15
+ private
11
16
 
12
- # creates thor options
13
- def self.thor_options(klass, object)
14
- Translatomatic::Option.options_from_object(object).each do |option|
15
- next if option.hidden
16
- klass.method_option option.name, option.to_thor
17
+ def thor_options(klass, object)
18
+ Translatomatic::Option.options_from_object(object).each do |option|
19
+ next if option.hidden
20
+ name = option.name.to_s.dasherize
21
+ klass.method_option name, option.to_thor
22
+ end
23
+ end
17
24
  end
18
- end
19
-
20
- def parse_list(list, default = [])
21
- # use the default list if the list is empty
22
- list = default if list.nil? || list.empty?
23
- list = [list] unless list.kind_of?(Array)
24
- # split list entries on ','
25
- list.compact.collect { |i| i.split(/[, ]/) }.flatten.compact
26
- end
27
25
 
28
- # run the give code block, display exceptions.
29
- # return true if the code ran without exceptions
30
- def run
31
- begin
32
- merge_options_and_config
33
- @dry_run = cli_option(:dry_run)
34
- conf.logger.level = Logger::DEBUG if cli_option(:debug)
35
- log.info(t("cli.dry_run")) if @dry_run
26
+ def parse_list(list, default = [])
27
+ # use the default list if the list is empty
28
+ list = default if list.nil? || list.empty?
29
+ list = [list] unless list.is_a?(Array)
30
+ # split list entries on ','
31
+ list.compact.collect { |i| i.split(/[, ]/) }.flatten.compact
32
+ end
36
33
 
34
+ # run the give code block, display exceptions.
35
+ def run
36
+ Translatomatic.config = create_config
37
+ @dry_run = conf.get(:dry_run)
38
+ log.level = ::Logger::DEBUG if conf.get(:debug)
39
+ log.info(t('cli.dry_run')) if @dry_run
37
40
  yield
38
- true
39
41
  rescue Interrupt
40
- puts "\n" + t("cli.aborted")
41
- false
42
- rescue Exception => e
42
+ puts "\n" + t('cli.aborted')
43
+ rescue StandardError => e
44
+ handle_run_error(e)
45
+ end
46
+
47
+ def create_config
48
+ Translatomatic::Config::Settings.new(runtime: options)
49
+ end
50
+
51
+ def handle_run_error(e)
43
52
  finish_log
44
53
  log.error(e.message)
45
54
  log.debug(e.backtrace.join("\n"))
46
- raise e if ENV["TEST"] # reraise exceptions in test
47
- false
55
+ raise e if ENV['TEST'] # reraise exceptions in test
48
56
  end
49
- end
50
57
 
51
- def finish_log
52
- conf.logger.finish if conf.logger.respond_to?(:finish)
53
- end
54
-
55
- def conf
56
- Translatomatic.config
57
- end
58
+ def finish_log
59
+ log.finish if log.respond_to?(:finish)
60
+ end
58
61
 
59
- # get an option value
60
- def cli_option(key)
61
- @options[key]
62
- end
62
+ def conf
63
+ Translatomatic.config
64
+ end
63
65
 
64
- # create @options from options and config
65
- def merge_options_and_config
66
- # start with command line options
67
- @options = options.transform_keys { |i| i.to_sym }
68
- # fill missing entries with config values
69
- Translatomatic::Config.options.each do |option|
70
- unless @options.include?(option.name)
71
- @options[option.name] = conf.get(option.name)
66
+ def rainbow
67
+ @rainbow ||= begin
68
+ rainbow = Rainbow.new
69
+ rainbow.enabled = !conf.get(:no_wank)
70
+ rainbow
72
71
  end
73
72
  end
74
- end
75
73
 
76
- def empty_array?(value)
77
- value.kind_of?(Array) && value.empty?
78
- end
74
+ def empty_array?(value)
75
+ value.is_a?(Array) && value.empty?
76
+ end
79
77
 
78
+ def add_table_heading(rows, headings)
79
+ underscores = headings.collect { |i| i.gsub(/\w/, '=') }
80
+ [headings, underscores] + rows
81
+ end
82
+ end
80
83
  end
81
84
  end
@@ -1,14 +1,17 @@
1
- module Translatomatic::CLI
2
- # Defines options common to all command line methods
3
- class CommonOptions
4
- private
5
- include Translatomatic::DefineOptions
6
- include Translatomatic::Util
7
-
8
- define_options(
9
- { name: :debug, type: :boolean, default: false, desc: t("cli.debug") },
10
- { name: :wank, type: :boolean, default: true, desc: t("cli.wank") },
11
- )
1
+ module Translatomatic
2
+ module CLI
3
+ # Defines options common to all command line methods
4
+ class CommonOptions
5
+ include Translatomatic::DefineOptions
6
+ include Translatomatic::Util
12
7
 
8
+ define_option :debug, type: :boolean, default: false,
9
+ desc: t('cli.debug'), command_line_only: true
10
+ define_option :no_wank, type: :boolean, default: false,
11
+ desc: t('cli.no_wank')
12
+ define_option :dry_run, type: :boolean, aliases: '-n',
13
+ desc: t('cli.dry_run'),
14
+ command_line_only: true
15
+ end
13
16
  end
14
17
  end
@@ -1,110 +1,115 @@
1
- module Translatomatic::CLI
2
- # Configuration functions for the command line interface
3
- class Config < Base
1
+ module Translatomatic
2
+ module CLI
3
+ # Configuration functions for the command line interface
4
+ class Config < Base
5
+ define_option :user, type: :boolean,
6
+ desc: t('cli.config.user'),
7
+ command_line_only: true
8
+ define_option :project, type: :boolean,
9
+ desc: t('cli.config.project'),
10
+ command_line_only: true
11
+ define_option :for_file, type: :path,
12
+ desc: t('cli.config.for_file'),
13
+ command_line_only: true
4
14
 
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
- )
15
+ desc 'set key value', t('cli.config.set')
16
+ thor_options(self, Translatomatic::CLI::CommonOptions)
17
+ thor_options(self, Translatomatic::CLI::Config)
18
+ # Change a configuration setting
19
+ # @param key [String] configuration key
20
+ # @param value [String] new value for the configuration
21
+ # @return [String] the new value
22
+ def set(key, *value)
23
+ run { conf.set(key, value, config_params) }
24
+ end
12
25
 
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
26
+ desc 'unset key', t('cli.config.unset')
27
+ thor_options(self, Translatomatic::CLI::CommonOptions)
28
+ thor_options(self, Translatomatic::CLI::Config)
29
+ # Remove a configuration setting
30
+ # @param key [String] configuration key to remove
31
+ # @return [void]
32
+ def unset(key)
33
+ run { conf.unset(key, config_params) }
34
+ end
23
35
 
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
36
+ desc 'add key value', t('cli.config.add')
37
+ thor_options(self, Translatomatic::CLI::CommonOptions)
38
+ thor_options(self, Translatomatic::CLI::Config)
39
+ # Add a configuration setting to a list
40
+ # @param key [String] configuration key
41
+ # @param value [String] value to add
42
+ # @return [String] the new value
43
+ def add(key, *value)
44
+ run { conf.add(key, value, config_params) }
45
+ end
33
46
 
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
- )
47
+ desc 'subtract key value', t('cli.config.subtract')
48
+ thor_options(self, Translatomatic::CLI::CommonOptions)
49
+ thor_options(self, Translatomatic::CLI::Config)
50
+ # Remove a configuration setting from a list
51
+ # @param key [String] configuration key
52
+ # @param value [String] value to remove
53
+ # @return [void]
54
+ def subtract(key, value)
55
+ run { conf.subtract(key, value, config_params) }
44
56
  end
45
- end
46
57
 
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])
58
+ desc 'list', t('cli.config.list')
59
+ thor_options(self, Translatomatic::CLI::CommonOptions)
60
+ thor_options(self, Translatomatic::CLI::Config)
61
+ option :skip_blanks, type: :boolean, desc: 'Skip blank values'
62
+ # List current configuration settings
63
+ def list
64
+ run do
65
+ print_config_table(columns: %i[key value], skip_blanks: true)
66
+ end
54
67
  end
55
- end
56
68
 
57
- private
69
+ desc 'describe', t('cli.config.describe')
70
+ thor_options(self, Translatomatic::CLI::CommonOptions)
71
+ thor_options(self, Translatomatic::CLI::Config)
72
+ # Describe available configuration settings
73
+ def describe
74
+ run do
75
+ print_config_table(columns: %i[key type desc])
76
+ end
77
+ end
58
78
 
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
- }
79
+ private
65
80
 
66
- def print_config_table(options)
67
- columns = options[:columns]
68
- context = options[:context]
69
- rows = []
81
+ def config_params
82
+ { location: config_location, for_file: options['for-file'] }
83
+ end
70
84
 
71
- if context
72
- puts t("cli.config.context_configuration", context: context)
73
- else
74
- puts t("cli.config.configuration")
85
+ def config_location
86
+ if options[:user]
87
+ :user
88
+ elsif options[:project]
89
+ :project
90
+ end
75
91
  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
92
+
93
+ def print_config_table(params)
94
+ display_options = options.merge(params).merge(config_params)
95
+ display = Translatomatic::Config::Display.new(display_options)
96
+ puts config_table_intro + "\n"
97
+ rows = display.config_table_body
98
+ if rows.empty?
99
+ puts t('cli.config.no_config')
100
+ else
101
+ print_table(rows)
94
102
  end
95
- rows << data
103
+ puts
96
104
  end
97
105
 
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
+ def config_table_intro
107
+ if (location = config_location)
108
+ t('cli.config.location_configuration', location: location)
109
+ else
110
+ t('cli.config.configuration')
111
+ end
106
112
  end
107
- puts
108
113
  end
109
114
  end
110
115
  end