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
@@ -1,36 +1,51 @@
1
- # Logging
2
- class Translatomatic::Logger
3
-
4
- # @return [ProgressBar] A progress bar
5
- attr_accessor :progressbar
6
-
7
- # @return [Translatomatic::Logger] create a new logger instance
8
- def initialize
9
- @logger = Logger.new(STDOUT)
10
- @logger.level = ENV['DEBUG'] ? Logger::DEBUG : Logger::INFO
11
- @logger.formatter = proc do |severity, datetime, progname, msg|
12
- "#{msg}\n"
1
+ require 'logger'
2
+
3
+ module Translatomatic
4
+ # Logging
5
+ class Logger
6
+ # @return [ProgressBar] A progress bar
7
+ attr_accessor :progressbar
8
+
9
+ # @return [Translatomatic::Logger] create a new logger instance
10
+ def initialize
11
+ @logger = ::Logger.new(STDOUT)
12
+ @logger.level = ENV['DEBUG'] ? ::Logger::DEBUG : ::Logger::INFO
13
+ @logger.formatter = proc do |_severity, _datetime, _progname, msg|
14
+ "#{msg}\n"
15
+ end
13
16
  end
14
- end
15
17
 
16
- # Called at the end of translatomatic to clear the progress bar.
17
- def finish
18
- @finished ||= begin
19
- @progressbar.finish if @progressbar
20
- true
18
+ # Called at the end of translatomatic to clear the progress bar.
19
+ def finish
20
+ @finished ||= begin
21
+ @progressbar.finish if @progressbar
22
+ true
23
+ end
21
24
  end
22
- end
23
25
 
24
- private
26
+ private
25
27
 
26
- def method_missing(name, *args)
27
- handle_logger_method(name, args) if @logger.respond_to?(name)
28
- end
28
+ def respond_to_missing?(name, include_private = false)
29
+ @logger.respond_to?(name, include_private) || super
30
+ end
29
31
 
30
- def handle_logger_method(name, args)
31
- @progressbar.clear if @progressbar
32
- @logger.send(name, *args)
33
- @progressbar.refresh(force: true) if @progressbar && !@progressbar.stopped?
34
- end
32
+ def method_missing(name, *args)
33
+ if @logger.respond_to?(name)
34
+ handle_logger_method(name, args)
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def handle_logger_method(name, args)
41
+ @progressbar.clear if @progressbar
42
+ @logger.send(name, *args)
43
+ refresh_progress_bar
44
+ end
35
45
 
46
+ def refresh_progress_bar
47
+ return unless @progressbar && !@progressbar.stopped?
48
+ @progressbar.refresh(force: true)
49
+ end
50
+ end
36
51
  end
@@ -0,0 +1,58 @@
1
+ module Translatomatic
2
+ # Parses tm.context comments in resource files
3
+ class Metadata
4
+ attr_reader :context
5
+
6
+ def initialize
7
+ reset
8
+ end
9
+
10
+ # Find associated context(s) for a property.
11
+ # Contexts are defined using tm.context comments in resource files.
12
+ # @return [Array<String>] Context for the given key
13
+ def get_context(key)
14
+ @context[key]
15
+ end
16
+
17
+ # Clear all metadata
18
+ def reset
19
+ @context = {}
20
+ @current_context = nil
21
+ end
22
+
23
+ # Assign current metadata to the given key
24
+ # @param key [String] name of the key
25
+ def assign_key(key, options = {})
26
+ if @current_context.present?
27
+ @context[key] = @current_context
28
+ @current_context = nil unless options[:keep_context]
29
+ end
30
+ end
31
+
32
+ # Clear the current context
33
+ def clear_context
34
+ @current_context = nil
35
+ end
36
+
37
+ # Add to the current context
38
+ # @param context [String] A context string
39
+ def add_context(context)
40
+ return unless context.present?
41
+ @current_context ||= []
42
+ @current_context << context.strip
43
+ end
44
+
45
+ # Parse comment text and extract metadata
46
+ # @return [Array] parsed context data
47
+ def parse_comment(comment)
48
+ return nil if comment.blank?
49
+ contexts = comment.scan(/tm\.context:\s*(.*)/)
50
+ result = []
51
+ contexts.each do |i|
52
+ add_context(i[0])
53
+ result << i[0]
54
+ end
55
+ result
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,7 @@
1
- # Contains classes that interface to records in the translatomatic database
2
- module Translatomatic::Model; end
1
+ module Translatomatic
2
+ # Active record model classes
3
+ module Model; end
4
+ end
3
5
 
4
6
  require 'translatomatic/model/locale'
5
7
  require 'translatomatic/model/text'
@@ -3,22 +3,22 @@ module Translatomatic
3
3
  # Locale database record.
4
4
  # Used to store translations in the database.
5
5
  class Locale < ActiveRecord::Base
6
- has_many :texts, class_name: "Translatomatic::Model::Text"
6
+ has_many :texts, class_name: 'Translatomatic::Model::Text'
7
7
  validates_presence_of :language
8
- validates_uniqueness_of :language, scope: [:script, :region]
8
+ validates_uniqueness_of :language, scope: %i[script region]
9
9
 
10
10
  # Create a locale record from an I18n::Locale::Tag object or string
11
11
  # @return [Translatomatic::Model::Locale] Locale record
12
12
  def self.from_tag(tag)
13
13
  tag = Translatomatic::Locale.parse(tag)
14
- find_or_create_by!({
14
+ find_or_create_by!(
15
15
  language: tag.language, script: tag.script, region: tag.region
16
- })
16
+ )
17
17
  end
18
18
 
19
19
  # @return [String] Locale as string
20
20
  def to_s
21
- [language, script, region].compact.join("-")
21
+ [language, script, region].compact.join('-')
22
22
  end
23
23
  end
24
24
  end
@@ -3,15 +3,15 @@ module Translatomatic
3
3
  # Text database record.
4
4
  # Used to store translations in the database.
5
5
  class Text < ActiveRecord::Base
6
- belongs_to :locale, class_name: "Translatomatic::Model::Locale"
7
- belongs_to :from_text, class_name: "Translatomatic::Model::Text"
8
- has_many :translations, class_name: "Translatomatic::Model::Text",
9
- foreign_key: :from_text_id, dependent: :delete_all
6
+ belongs_to :locale, class_name: 'Translatomatic::Model::Locale'
7
+ belongs_to :from_text, class_name: 'Translatomatic::Model::Text'
8
+ has_many :translations, class_name: 'Translatomatic::Model::Text',
9
+ foreign_key: :from_text_id, dependent: :delete_all
10
10
 
11
11
  validates_presence_of :value
12
12
  validates_presence_of :locale
13
13
 
14
- def is_translated?
14
+ def translated?
15
15
  !from_text_id.nil?
16
16
  end
17
17
  end
@@ -28,58 +28,81 @@ module Translatomatic
28
28
  # @return [boolean] True if this option can only be set on the command line
29
29
  attr_reader :command_line_only
30
30
 
31
- # @return [boolean] True if this option can only be set in user context
32
- attr_reader :user_context_only
31
+ # @return [boolean] True if this option can only be set in the
32
+ # user configuration file
33
+ attr_reader :user_location_only
33
34
 
34
35
  # Create a new option
35
- # @param data [Hash<Symbol,Object>] Attributes as above
36
+ # @param attributes [Hash<Symbol,Object>] Attributes as above
36
37
  # @return [Translatomatic::Option] A new option instance
37
- def initialize(data = {})
38
- @name = data[:name]
39
- @required = data[:required]
40
- @description = data[:desc]
41
- @use_env = data[:use_env]
42
- @hidden = data[:hidden]
43
- @type = data[:type] || :string
44
- @default = data[:default]
45
- @aliases = data[:aliases]
46
- @enum = data[:enum]
47
- @user_context_only = data[:user_context_only]
48
- @command_line_only = data[:command_line_only]
49
- @env_name = data[:env_name] || (@use_env ? @name.to_s.upcase : nil)
38
+ def initialize(attributes = {})
39
+ attributes.each do |k, v|
40
+ raise "unrecognised attribute #{k}" unless constructor_option?(k)
41
+ instance_variable_set("@#{k}", v)
42
+ end
43
+ @description = @desc
44
+ @type ||= :string
45
+ raise "invalid type: #{@type}" unless VALID_TYPES.include?(@type)
46
+ @env_name ||= @use_env && @name ? @name.to_s.upcase : nil
47
+ @user_location_only = true if @name.to_s =~ /api_key/
50
48
  end
51
49
 
50
+ # Return sconfiguration for a thor command line option
51
+ # @return [Hash] Thor configuration
52
52
  def to_thor
53
- # use internal ',' splitting for array types on command line
54
- type = @type == :array ? :string : @type
55
-
56
- { name: @name,
53
+ {
57
54
  required: @required,
58
- type: type,
55
+ type: thor_type,
59
56
  desc: @description,
60
57
  default: @default,
61
58
  aliases: @aliases,
62
- enum: @enum ? @enum.collect { |i| i.to_s } : nil
59
+ banner: @type == :boolean ? nil : type_name,
60
+ enum: @enum ? @enum.collect(&:to_s) : nil
63
61
  }
64
62
  end
65
63
 
64
+ # Translate the type of this option
65
+ # @return [String] The translated type
66
+ def type_name
67
+ t("config.types.#{type}")
68
+ end
69
+
66
70
  # Retrieve all options from an object or list of objects.
67
71
  # @param object [#options,Array<#options>] Options source
68
72
  # @return [Array<Translatomatic::Option>] options
69
73
  def self.options_from_object(object)
70
- options = []
71
- if object.respond_to?(:options)
72
- options += options_from_object(object.options)
73
- elsif object.kind_of?(Array)
74
- object.each do |item|
75
- if item.kind_of?(Translatomatic::Option)
76
- options << item
77
- elsif item.respond_to?(:options)
78
- options += options_from_object(item.options)
79
- end
80
- end
74
+ if object.is_a?(Translatomatic::Option)
75
+ [object]
76
+ elsif object.respond_to?(:options)
77
+ options_from_object(object.options)
78
+ elsif object.is_a?(Array)
79
+ object.collect { |i| options_from_object(i) }.flatten
80
+ else
81
+ []
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ include Util
88
+
89
+ CONSTRUCTOR_OPTIONS = %i[name required desc use_env hidden type default
90
+ aliases enum user_location_only
91
+ command_line_only env_name].freeze
92
+ VALID_TYPES = %i[array path_array string path boolean numeric].freeze
93
+
94
+ def constructor_option?(key)
95
+ CONSTRUCTOR_OPTIONS.include?(key)
96
+ end
97
+
98
+ def thor_type
99
+ case @type
100
+ when :array, :path_array, :string, :path
101
+ # use internal ',' splitting for array types on command line
102
+ :string
103
+ else
104
+ @type
81
105
  end
82
- options
83
106
  end
84
107
  end
85
108
  end
@@ -0,0 +1,126 @@
1
+ module Translatomatic
2
+ # Utilities for locales and paths
3
+ module PathUtils
4
+ # Find a new path representing the given path with a new locale
5
+ # @param path [Pathname] The current path
6
+ # @param target_locale [String] The target locale
7
+ # @return [Pathname] The new path for the given locale
8
+ def modify_path_locale(path, target_locale, preferred_separator = '.')
9
+ basename = basename_stripped(path)
10
+
11
+ extlist = extension_list(path)
12
+ if extlist.length >= 2 && (loc_idx = find_extension_locale(extlist))
13
+ # extension(s) contains locale, replace it
14
+ extlist[loc_idx] = target_locale.to_s
15
+ filename = basename + '.' + extlist.join('.')
16
+ path.dirname + filename
17
+ elsif valid_locale?(basename)
18
+ # basename is a locale name, replace it
19
+ path.dirname + (target_locale.to_s + path.extname)
20
+ elsif basename.match(/_([-\w]+)\Z/) &&
21
+ valid_locale?(Regexp.last_match(1))
22
+ # basename contains locale, e.g. basename_$locale.ext
23
+ add_basename_locale(path, target_locale, '_') # retain _
24
+ elsif valid_locale?(path.parent.basename(path.parent.extname)) ||
25
+ path.parent.basename.to_s == 'Base.lproj'
26
+ # parent directory contains locale, e.g. strings/en-US/text.resw
27
+ # or project/en.lproj/Strings.strings
28
+ path.parent.parent + (target_locale.to_s +
29
+ path.parent.extname) + path.basename
30
+ elsif path.to_s =~ %r{\bres/values([-\w]+)?/.+$}
31
+ # android strings
32
+ filename = path.basename
33
+ path.parent.parent + ('values-' + target_locale.to_s) + filename
34
+ else
35
+ # default behaviour, add locale after separator in basename
36
+ add_basename_locale(path, target_locale, preferred_separator)
37
+ end
38
+ end
39
+
40
+ # detect locale from path
41
+ def detect_path_locale(path)
42
+ return nil unless path
43
+ tag = nil
44
+ basename = path.sub_ext('').basename.to_s
45
+ directory = path.dirname.basename.to_s
46
+ extlist = extension_list(path)
47
+
48
+ if basename.match(/_([-\w]{2,})$/) &&
49
+ valid_locale?(Regexp.last_match(1))
50
+ # locale after underscore in filename
51
+ tag = Regexp.last_match(1)
52
+ elsif directory =~ /^([-\w]+)\.lproj$/
53
+ # xcode localized strings
54
+ tag = Regexp.last_match(1)
55
+ elsif extlist.length >= 2 && (loc_idx = find_extension_locale(extlist))
56
+ # multiple parts to extension, e.g. index.html.en
57
+ tag = extlist[loc_idx]
58
+ elsif valid_locale?(basename)
59
+ # try to match on entire basename
60
+ # (support for rails en.yml)
61
+ tag = basename
62
+ elsif valid_locale?(path.parent.basename)
63
+ # try to match on parent directory, e.g. strings/en-US/text.resw
64
+ tag = path.parent.basename
65
+ elsif path.parent.basename.to_s.match(/-([-\w]+)/) &&
66
+ valid_locale?(Regexp.last_match(1))
67
+ # try to match on trailing part of parent directory,
68
+ # e.g. res/values-en/strings.xml
69
+ tag = Regexp.last_match(1)
70
+ end
71
+
72
+ tag ? Translatomatic::Locale.parse(tag, true) : nil
73
+ end
74
+
75
+ private
76
+
77
+ def read_contents(path)
78
+ Translatomatic::Slurp.read(path.to_s)
79
+ end
80
+
81
+ # ext_sub() only removes the last extension
82
+ def basename_stripped(path)
83
+ filename = path.basename.to_s
84
+ filename.sub!(/\..*$/, '')
85
+ filename
86
+ end
87
+
88
+ def relative_path(path)
89
+ if path.relative?
90
+ path
91
+ else
92
+ path.relative_path_from(Pathname.pwd)
93
+ end
94
+ end
95
+
96
+ # for index.html.de, returns ['html', 'de']
97
+ def extension_list(path)
98
+ filename = path.basename.to_s
99
+ idx = filename.index('.')
100
+ if idx && idx < filename.length - 1
101
+ filename[idx + 1..-1].split('.')
102
+ else
103
+ []
104
+ end
105
+ end
106
+
107
+ def add_basename_locale(path, target_locale, preferred_separator = '.')
108
+ # remove any underscore and trailing text from basename
109
+ deunderscored = basename_stripped(path).sub(/_.*?\Z/, '')
110
+ # add #{preferred_separator}locale.ext
111
+ filename = deunderscored + preferred_separator +
112
+ target_locale.to_s + path.extname
113
+ path.dirname + filename
114
+ end
115
+
116
+ # test if the list of strings contains a valid locale
117
+ # return the index to the locale, or nil if no locales found
118
+ def find_extension_locale(extlist)
119
+ extlist.find_index { |i| valid_locale?(i) }
120
+ end
121
+
122
+ def valid_locale?(tag)
123
+ Translatomatic::Locale.new(tag).valid?
124
+ end
125
+ end
126
+ end
@@ -1,19 +1,16 @@
1
- # implements Converter listener
2
- class Translatomatic::ProgressUpdater
3
- # Create a new progress updater
4
- # @param progressbar [Progressbar] A ruby-progressbar object
5
- def initialize(progressbar)
6
- @progressbar = progressbar
7
- end
8
-
9
- # @return [Number] the number of translated strings
10
- def translated_texts(texts)
11
- @progressbar.progress += texts.length
12
- end
1
+ module Translatomatic
2
+ # Class to update the progress bar for the CLI
3
+ class ProgressUpdater
4
+ # Create a new progress updater
5
+ # @param progressbar [Progressbar] A ruby-progressbar object
6
+ def initialize(progressbar)
7
+ @progressbar = progressbar
8
+ end
13
9
 
14
- # @return [Number] the number of untranslated strings
15
- def untranslated_texts(texts)
16
- @progressbar.total -= texts.length
10
+ # @param count [Number] Update progress
11
+ # @return [Number] The total number of processed items.
12
+ def update_progress(count)
13
+ @progressbar.progress += count
14
+ end
17
15
  end
18
-
19
16
  end