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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.translatomatic/config.yml +18 -0
  3. data/.travis.yml +33 -33
  4. data/Gemfile +6 -4
  5. data/README.de.md +53 -18
  6. data/README.es.md +55 -20
  7. data/README.fr.md +54 -19
  8. data/README.it.md +58 -23
  9. data/README.ja.md +54 -19
  10. data/README.ko.md +58 -23
  11. data/README.md +167 -141
  12. data/README.ms.md +51 -16
  13. data/README.pt.md +58 -23
  14. data/README.ru.md +53 -18
  15. data/README.sv.md +53 -18
  16. data/README.zh.md +53 -18
  17. data/bin/translatomatic +6 -6
  18. data/bin/travis +24 -26
  19. data/config/locales/translatomatic/de.yml +22 -11
  20. data/config/locales/translatomatic/en.yml +21 -12
  21. data/config/locales/translatomatic/es.yml +22 -11
  22. data/config/locales/translatomatic/fr.yml +22 -12
  23. data/config/locales/translatomatic/it.yml +22 -11
  24. data/config/locales/translatomatic/ja.yml +22 -11
  25. data/config/locales/translatomatic/ko.yml +22 -11
  26. data/config/locales/translatomatic/ms.yml +22 -11
  27. data/config/locales/translatomatic/pt.yml +22 -11
  28. data/config/locales/translatomatic/ru.yml +22 -11
  29. data/config/locales/translatomatic/sv.yml +22 -11
  30. data/config/locales/translatomatic/zh.yml +22 -11
  31. data/db/migrate/201712170000_initial.rb +25 -25
  32. data/lib/translatomatic/cli/base.rb +81 -73
  33. data/lib/translatomatic/cli/config.rb +110 -81
  34. data/lib/translatomatic/cli/main.rb +85 -72
  35. data/lib/translatomatic/cli/translate.rb +141 -106
  36. data/lib/translatomatic/cli.rb +8 -8
  37. data/lib/translatomatic/config.rb +302 -155
  38. data/lib/translatomatic/converter.rb +28 -260
  39. data/lib/translatomatic/database.rb +134 -134
  40. data/lib/translatomatic/define_options.rb +22 -0
  41. data/lib/translatomatic/escaped_unicode.rb +0 -0
  42. data/lib/translatomatic/extractor/base.rb +16 -16
  43. data/lib/translatomatic/extractor/ruby.rb +6 -6
  44. data/lib/translatomatic/extractor.rb +5 -5
  45. data/lib/translatomatic/file_translator.rb +269 -0
  46. data/lib/translatomatic/http_request.rb +162 -162
  47. data/lib/translatomatic/locale.rb +76 -76
  48. data/lib/translatomatic/logger.rb +23 -23
  49. data/lib/translatomatic/model/locale.rb +25 -25
  50. data/lib/translatomatic/model/text.rb +19 -19
  51. data/lib/translatomatic/model.rb +1 -1
  52. data/lib/translatomatic/option.rb +37 -41
  53. data/lib/translatomatic/progress_updater.rb +13 -13
  54. data/lib/translatomatic/resource_file/base.rb +269 -192
  55. data/lib/translatomatic/resource_file/csv.rb +37 -0
  56. data/lib/translatomatic/resource_file/html.rb +54 -47
  57. data/lib/translatomatic/resource_file/markdown.rb +50 -55
  58. data/lib/translatomatic/resource_file/plist.rb +153 -19
  59. data/lib/translatomatic/resource_file/po.rb +107 -0
  60. data/lib/translatomatic/resource_file/properties.rb +91 -90
  61. data/lib/translatomatic/resource_file/resw.rb +50 -30
  62. data/lib/translatomatic/resource_file/subtitle.rb +75 -0
  63. data/lib/translatomatic/resource_file/text.rb +24 -30
  64. data/lib/translatomatic/resource_file/xcode_strings.rb +75 -80
  65. data/lib/translatomatic/resource_file/xml.rb +98 -91
  66. data/lib/translatomatic/resource_file/yaml.rb +94 -116
  67. data/lib/translatomatic/resource_file.rb +87 -78
  68. data/lib/translatomatic/string.rb +188 -188
  69. data/lib/translatomatic/tmx/document.rb +99 -99
  70. data/lib/translatomatic/translation_result.rb +63 -63
  71. data/lib/translatomatic/{converter_stats.rb → translation_stats.rb} +17 -17
  72. data/lib/translatomatic/translator/base.rb +1 -1
  73. data/lib/translatomatic/translator/google.rb +2 -0
  74. data/lib/translatomatic/translator.rb +10 -2
  75. data/lib/translatomatic/util.rb +45 -45
  76. data/lib/translatomatic/version.rb +7 -7
  77. data/lib/translatomatic.rb +52 -49
  78. data/translatomatic.gemspec +3 -2
  79. metadata +25 -5
@@ -1,268 +1,36 @@
1
- # The converter ties together functionality from translators,
2
- # resource files, and the database to convert files from one
3
- # language to another.
4
- class Translatomatic::Converter
5
-
6
- # @return [Array<Translatomatic::Model::Text>] A list of translations saved to the database
7
- attr_reader :db_translations
8
-
9
- # Create a converter to translate files
10
- #
11
- # @param options [Hash<Symbol,Object>] converter and/or translator options.
12
- def initialize(options = {})
13
- @dry_run = options[:dry_run]
14
- @listener = options[:listener]
15
- @translators = Translatomatic::Translator.resolve(options[:translator], options)
16
- raise t("converter.translator_required") if @translators.empty?
17
- @translators.each { |i| i.listener = @listener } if @listener
18
-
19
- # use database by default if we're connected to a database
20
- use_db = options.include?(:use_database) ? options[:use_database] : true
21
- @use_db = use_db && ActiveRecord::Base.connected?
22
- log.debug(t("converter.database_disabled")) unless @use_db
1
+ # Converts files from one format to another
2
+ class Translatomatic::Converter
23
3
 
24
- @db_translations = []
25
- @translations = {} # map of original text to Translation
4
+ def initialize(options = {})
5
+ @options = options
26
6
  end
27
-
28
- # @return [Translatomatic::ConverterStats] Translation statistics
29
- def stats
30
- @stats ||= Translatomatic::ConverterStats.new(@translations)
31
- end
32
-
33
- # Translate properties of source_file to the target locale.
34
- # Does not write changes to disk.
35
- #
36
- # @param file [String, Translatomatic::ResourceFile] File to translate
37
- # @param to_locale [String] The target locale, e.g. "fr"
38
- # @return [Translatomatic::ResourceFile] The translated resource file
39
- def translate(file, to_locale)
40
- file = resource_file(file)
41
- to_locale = parse_locale(to_locale)
42
7
 
43
- # do nothing if target language is the same as source language
44
- return file if file.locale.language == to_locale.language
45
-
46
- result = Translatomatic::TranslationResult.new(file, to_locale)
47
-
48
- # translate using strings from the database first
49
- each_translator(result) { translate_properties_with_db(result) }
50
- # send remaining unknown strings to translator
51
- each_translator(result) { translate_properties_with_translator(result) }
52
-
53
- log.debug(t("converter.stats", from_db: stats.from_db,
54
- from_translator: stats.from_translator,
55
- untranslated: result.untranslated.length))
56
- @listener.untranslated_texts(result.untranslated) if @listener
57
-
58
- file.properties = result.properties
59
- file.locale = to_locale
60
- file
61
- end
62
-
63
- # Translates a resource file and writes results to a target resource file.
64
- # The path of the target resource file is automatically determined.
65
- #
66
- # @param source [Translatomatic::ResourceFile] The source
67
- # @param to_locale [String] The target locale, e.g. "fr"
68
- # @return [Translatomatic::ResourceFile] The translated resource file
69
- def translate_to_file(source, to_locale)
70
- # Automatically determines the target filename based on target locale.
71
- source = resource_file(source)
72
- target = Translatomatic::ResourceFile.load(source.path)
73
- target.path = source.locale_path(to_locale)
74
-
75
- log.info(t("converter.translating", source: source,
76
- source_locale: source.locale, target: target, target_locale: to_locale))
77
- translate(target, to_locale)
78
- unless @dry_run
79
- target.path.parent.mkpath
80
- target.save
81
- end
82
- target
83
- end
84
-
85
- private
86
-
87
- include Translatomatic::Util
88
- include Translatomatic::DefineOptions
89
-
90
- define_options(
91
- { name: :dry_run, type: :boolean, aliases: "-n",
92
- desc: t("converter.dry_run")
93
- },
94
- { name: :use_database, type: :boolean, default: true,
95
- desc: t("converter.use_database")
96
- }
97
- )
98
-
99
- def each_translator(result)
100
- @translators.each do |translator|
101
- break if result.untranslated.empty?
102
- @current_translator = translator
103
- yield
104
- end
8
+ # Convert a resource file from one format to another.
9
+ # @param source [String] Path to source file. File must exist
10
+ # @param target [String] Path to target file. File will be created
11
+ # or overwritten if it already exists.
12
+ # @return [Translatomatic::ResourceFile] The converted file.
13
+ def convert(source, target)
14
+ source_path = Pathname.new(source.to_s)
15
+ target_path = Pathname.new(target.to_s)
16
+ raise t("file.not_found", file: source.to_s) unless source_path.file?
17
+ raise t("file.directory", file: target.to_s) if target_path.directory?
18
+
19
+ source_file = load_file(source_path)
20
+ target_file = load_file(target_path)
21
+
22
+ # copy properties from source file to target
23
+ target_file.properties = source_file.properties
24
+ target_file.save(target_path, @options)
25
+ target_file
105
26
  end
106
27
 
107
- # Attempt to restore interpolated variable names in the translation.
108
- # If variable names cannot be restored, sets the translation result to nil.
109
- # @param result [Translatomatic::TranslationResult] translation result
110
- # @param translation [Translatomatic::Translation] translation
111
- # @return [void]
112
- def restore_variables(result, translation)
113
- file = result.file
114
- return unless file.supports_variable_interpolation?
115
-
116
- # find variables in the original string
117
- variables = string_variables(translation.original, file.locale, file)
118
- # find variables in the translated string
119
- translated_variables = string_variables(translation.result, result.to_locale, file)
120
-
121
- if variables.length == translated_variables.length
122
- # we can restore variables. sort by largest offset first.
123
- # not using translation() method as that adds to @translations hash.
124
- conversions = variables.zip(translated_variables).collect {
125
- |v1, v2| Translatomatic::Translation.new(v1, v2)
126
- }
127
- conversions.sort_by! { |t| -t.original.offset }
128
- conversions.each do |conversion|
129
- v1 = conversion.original
130
- v2 = conversion.result
131
- translation.result[v2.offset, v2.length] = v1.value
132
- end
133
- else
134
- # unable to restore interpolated variable names
135
- log.debug("#{@current_translator.name}: unable to restore variables: #{translation.result}")
136
- translation.result = nil # mark result as invalid
137
- end
138
- end
139
-
140
- def string_variables(value, locale, file)
141
- string(value, locale).substrings(file.variable_regex)
142
- end
143
-
144
- def resource_file(path)
145
- if path.kind_of?(Translatomatic::ResourceFile::Base)
146
- path
147
- else
148
- file = Translatomatic::ResourceFile.load(path)
149
- raise t("converter.file_unsupported", file: path) unless file
150
- file
151
- end
152
- end
153
-
154
- # update result with translations from the database.
155
- def translate_properties_with_db(result)
156
- db_texts = []
157
- unless database_disabled?
158
- translations = []
159
- untranslated = hashify(result.untranslated)
160
- db_texts = find_database_translations(result, result.untranslated.to_a)
161
- db_texts.each do |db_text|
162
- from_text = db_text.from_text.value
163
- if untranslated[from_text]
164
- translation = translation(untranslated[from_text], db_text.value, true)
165
- restore_variables(result, translation)
166
- translations << translation
167
- end
168
- end
169
-
170
- result.update_strings(translations)
171
- @listener.translated_texts(db_texts) if @listener
172
- end
173
- db_texts
174
- end
175
-
176
- # update result with translations from the translator.
177
- def translate_properties_with_translator(result)
178
- untranslated = result.untranslated.to_a.select { |i| translatable?(i) }
179
- translated = []
180
- if !untranslated.empty? && !@dry_run
181
- untranslated_strings = untranslated.collect { |i| i.to_s }
182
- log.debug("translating: #{untranslated_strings}")
183
- translated = @current_translator.translate(untranslated_strings,
184
- result.from_locale, result.to_locale
185
- )
28
+ private
186
29
 
187
- # create list of translations, filtering out invalid translations
188
- translations = []
189
- untranslated.zip(translated).each do |from, to|
190
- translation = translation(from, to, false)
191
- restore_variables(result, translation)
192
- translations << translation
193
- end
194
-
195
- result.update_strings(translations)
196
- unless database_disabled?
197
- save_database_translations(result, translations)
198
- end
199
- end
200
- translated
30
+ def load_file(path)
31
+ file = Translatomatic::ResourceFile.load(path)
32
+ raise t("file.unsupported", file: path) unless file
33
+ file
201
34
  end
202
35
 
203
- def translation(from, to, from_database = false)
204
- translator = @current_translator.name
205
- t = Translatomatic::Translation.new(from, to, translator, from_database)
206
- @translations[from] = t
207
- t
208
- end
209
-
210
- def database_disabled?
211
- !@use_db
212
- end
213
-
214
- def parse_locale(locale)
215
- Translatomatic::Locale.parse(locale)
216
- end
217
-
218
- def translatable?(string)
219
- # don't translate numbers
220
- !string.empty? && !string.match(/^[\d,]+$/)
221
- end
222
-
223
- def save_database_translations(result, translations)
224
- ActiveRecord::Base.transaction do
225
- from = db_locale(result.from_locale)
226
- to = db_locale(result.to_locale)
227
- translations.each do |translation|
228
- next if translation.result.nil? # skip invalid translations
229
- save_database_translation(from, to, translation)
230
- end
231
- end
232
- end
233
-
234
- def save_database_translation(from_locale, to_locale, translation)
235
- original_text = Translatomatic::Model::Text.find_or_create_by!(
236
- locale: from_locale,
237
- value: translation.original.to_s
238
- )
239
-
240
- text = Translatomatic::Model::Text.find_or_create_by!(
241
- locale: to_locale,
242
- value: translation.result.to_s,
243
- from_text: original_text,
244
- translator: @current_translator.name
245
- )
246
- @db_translations += [original_text, text]
247
- text
248
- end
249
-
250
- def find_database_translations(result, untranslated)
251
- from = db_locale(result.from_locale)
252
- to = db_locale(result.to_locale)
253
-
254
- Translatomatic::Model::Text.where({
255
- locale: to,
256
- translator: @current_translator.name,
257
- from_texts_texts: {
258
- locale_id: from,
259
- # convert untranslated set to strings
260
- value: untranslated.collect { |i| i.to_s }
261
- }
262
- }).joins(:from_text)
263
- end
264
-
265
- def db_locale(locale)
266
- Translatomatic::Model::Locale.from_tag(locale)
267
- end
268
- end
36
+ end
@@ -1,143 +1,143 @@
1
- require 'active_record'
2
-
3
- # Database functions
4
- class Translatomatic::Database
5
-
6
- class << self
7
- # @param options [Hash<Symbol,Object>] Database options
8
- # @return [boolean] True if we can connect to the database
9
- def enabled?(options = {})
10
- new(options).connect
11
- end
12
- end
13
-
14
- def initialize(options = {})
15
- @env = options[:database_env] || DEFAULT_ENV
16
- @db_config = database_config(@env, options)
17
- @env_config = @db_config
1
+ require 'active_record'
2
+
3
+ # Database functions
4
+ class Translatomatic::Database
5
+
6
+ class << self
7
+ # @param options [Hash<Symbol,Object>] Database options
8
+ # @return [boolean] True if we can connect to the database
9
+ def enabled?(options = {})
10
+ new(options).connect
11
+ end
12
+ end
13
+
14
+ def initialize(options = {})
15
+ @env = options[:database_env] || DEFAULT_ENV
16
+ @db_config = database_config(@env, options)
17
+ @env_config = @db_config
18
18
  raise t("database.no_environment",
19
- env: @env, file: db_config_path) unless @env_config[@env]
20
- @env_config = @env_config[@env] || {}
21
-
22
- ActiveRecord::Base.configurations = @db_config
23
- ActiveRecord::Tasks::DatabaseTasks.env = @env
24
- ActiveRecord::Tasks::DatabaseTasks.db_dir = DB_PATH
25
- ActiveRecord::Tasks::DatabaseTasks.root = DB_PATH
26
- ActiveRecord::Tasks::DatabaseTasks.database_configuration = @db_config
27
- create unless exists?
28
- migrate
29
- end
30
-
31
- # Connect to the database
32
- # @return [boolean] True if the connection was established
33
- def connect
34
- begin
35
- ActiveRecord::Base.establish_connection(@env_config)
36
- true
37
- rescue LoadError
38
- false
39
- end
40
- end
41
-
42
- # Disconnect from the database
43
- # @return [void]
44
- def disconnect
45
- ActiveRecord::Base.remove_connection
46
- end
47
-
48
- # Test if the database exists
49
- # @return [Boolean] true if the database exists
50
- def exists?
51
- begin
52
- return true if sqlite_database_exists?
53
- return false unless connect
54
- ActiveRecord::Base.connection.tables
55
- rescue
56
- return false
57
- end
58
- true
59
- end
60
-
61
- # Run outstanding migrations against the database
62
- # @return [void]
63
- def migrate
64
- return false unless connect
65
- ActiveRecord::Migrator.migrate(MIGRATIONS_PATH)
66
- ActiveRecord::Base.clear_cache!
19
+ env: @env, file: db_config_path) unless @env_config[@env]
20
+ @env_config = @env_config[@env] || {}
21
+
22
+ ActiveRecord::Base.configurations = @db_config
23
+ ActiveRecord::Tasks::DatabaseTasks.env = @env
24
+ ActiveRecord::Tasks::DatabaseTasks.db_dir = DB_PATH
25
+ ActiveRecord::Tasks::DatabaseTasks.root = DB_PATH
26
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = @db_config
27
+ create unless exists?
28
+ migrate
29
+ end
30
+
31
+ # Connect to the database
32
+ # @return [boolean] True if the connection was established
33
+ def connect
34
+ begin
35
+ ActiveRecord::Base.establish_connection(@env_config)
36
+ true
37
+ rescue LoadError
38
+ false
39
+ end
40
+ end
41
+
42
+ # Disconnect from the database
43
+ # @return [void]
44
+ def disconnect
45
+ ActiveRecord::Base.remove_connection
46
+ end
47
+
48
+ # Test if the database exists
49
+ # @return [Boolean] true if the database exists
50
+ def exists?
51
+ begin
52
+ return true if sqlite_database_exists?
53
+ return false unless connect
54
+ ActiveRecord::Base.connection.tables
55
+ rescue
56
+ return false
57
+ end
58
+ true
59
+ end
60
+
61
+ # Run outstanding migrations against the database
62
+ # @return [void]
63
+ def migrate
64
+ return false unless connect
65
+ ActiveRecord::Migrator.migrate(MIGRATIONS_PATH)
66
+ ActiveRecord::Base.clear_cache!
67
67
  log.debug t("database.migrated")
68
- end
69
-
70
- # Create the database
71
- # @return [boolean] True if the database was created
72
- def create
73
- begin
74
- ActiveRecord::Tasks::DatabaseTasks.create(@env_config)
75
- log.debug t("database.created")
76
- true
68
+ end
69
+
70
+ # Create the database
71
+ # @return [boolean] True if the database was created
72
+ def create
73
+ begin
74
+ ActiveRecord::Tasks::DatabaseTasks.create(@env_config)
75
+ log.debug t("database.created")
76
+ true
77
77
  rescue LoadError => e
78
78
  log.debug t("database.could_not_create")
79
- log.error e.message
80
- false
81
- end
82
- end
83
-
84
- # Drop the database
85
- # @return [void]
86
- def drop
87
- disconnect
88
- ActiveRecord::Tasks::DatabaseTasks.drop(@env_config)
89
- log.debug t("database.deleted")
90
- end
91
-
79
+ log.error e.message
80
+ false
81
+ end
82
+ end
83
+
84
+ # Drop the database
85
+ # @return [void]
86
+ def drop
87
+ disconnect
88
+ ActiveRecord::Tasks::DatabaseTasks.drop(@env_config)
89
+ log.debug t("database.deleted")
90
+ end
91
+
92
92
  private
93
93
 
94
94
  include Translatomatic::Util
95
95
  include Translatomatic::DefineOptions
96
-
97
- def sqlite_database_exists?
98
- @env_config['adapter'] == 'sqlite3' && File.exist?(@env_config['database'])
99
- end
100
-
101
- def self.join_path(*parts)
102
- File.realpath(File.join(*parts))
103
- end
104
-
105
- DB_PATH = join_path(File.dirname(__FILE__), "..", "..", "db")
106
- INTERNAL_CONFIG = File.join(DB_PATH, "database.yml")
107
- CUSTOM_CONFIG = File.join(Dir.home, ".translatomatic", "database.yml")
108
- DEFAULT_CONFIG = File.exist?(CUSTOM_CONFIG) ? CUSTOM_CONFIG : INTERNAL_CONFIG
109
- MIGRATIONS_PATH = File.join(DB_PATH, "migrate")
110
- GEM_ROOT = join_path(File.dirname(__FILE__), "..", "..")
111
- DEFAULT_ENV = "production"
112
-
113
- define_options(
114
- { name: :database_config, desc: t("database.config_file"),
115
- default: DEFAULT_CONFIG },
96
+
97
+ def sqlite_database_exists?
98
+ @env_config['adapter'] == 'sqlite3' && File.exist?(@env_config['database'])
99
+ end
100
+
101
+ def self.join_path(*parts)
102
+ File.realpath(File.join(*parts))
103
+ end
104
+
105
+ DB_PATH = join_path(File.dirname(__FILE__), "..", "..", "db")
106
+ INTERNAL_CONFIG = File.join(DB_PATH, "database.yml")
107
+ CUSTOM_CONFIG = File.join(Dir.home, ".translatomatic", "database.yml")
108
+ DEFAULT_CONFIG = File.exist?(CUSTOM_CONFIG) ? CUSTOM_CONFIG : INTERNAL_CONFIG
109
+ MIGRATIONS_PATH = File.join(DB_PATH, "migrate")
110
+ GEM_ROOT = join_path(File.dirname(__FILE__), "..", "..")
111
+ DEFAULT_ENV = "production"
112
+
113
+ define_options(
114
+ { name: :database_config, desc: t("database.config_file"),
115
+ default: DEFAULT_CONFIG },
116
116
  { name: :database_env, desc: t("database.env"),
117
- default: DEFAULT_ENV })
118
-
119
- # return path to database config
120
- def database_config_path(options)
121
- if options[:database_env] == "test"
122
- INTERNAL_CONFIG # rspec
123
- elsif options[:database_config]
124
- return options[:database_config]
125
- else
126
- DEFAULT_CONFIG
127
- end
128
- end
129
-
130
- # return database config as a hash
131
- def database_config(env, options)
132
- if options[:database_config].kind_of?(Hash)
133
- return { env => options[:database_config] }
134
- end
135
-
136
- db_config_path = database_config_path(options)
137
- dbconfig = File.read(db_config_path)
138
- dbconfig.gsub!(/\$HOME/, Dir.home)
139
- dbconfig.gsub!(/\$GEM_ROOT/, GEM_ROOT)
140
- YAML::load(dbconfig) || {}
141
- end
142
-
143
- end
117
+ default: DEFAULT_ENV })
118
+
119
+ # return path to database config
120
+ def database_config_path(options)
121
+ if options[:database_env] == "test"
122
+ INTERNAL_CONFIG # rspec
123
+ elsif options[:database_config]
124
+ return options[:database_config]
125
+ else
126
+ DEFAULT_CONFIG
127
+ end
128
+ end
129
+
130
+ # return database config as a hash
131
+ def database_config(env, options)
132
+ if options[:database_config].kind_of?(Hash)
133
+ return { env => options[:database_config] }
134
+ end
135
+
136
+ db_config_path = database_config_path(options)
137
+ dbconfig = File.read(db_config_path)
138
+ dbconfig.gsub!(/\$HOME/, Dir.home)
139
+ dbconfig.gsub!(/\$GEM_ROOT/, GEM_ROOT)
140
+ YAML::load(dbconfig) || {}
141
+ end
142
+
143
+ end
@@ -0,0 +1,22 @@
1
+ module Translatomatic
2
+ # @!visibility private
3
+ module DefineOptions
4
+
5
+ # @!visibility private
6
+ module ClassMethods
7
+ attr_reader :options
8
+
9
+ private
10
+
11
+ def define_options(*options)
12
+ @options = options.collect { |i| Translatomatic::Option.new(i) }
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def self.included(klass)
19
+ klass.extend(ClassMethods)
20
+ end
21
+ end
22
+ end
File without changes
@@ -1,16 +1,16 @@
1
- module Translatomatic::Extractor
2
- # Base class for string extraction functionality
3
- class Base
4
-
5
- def initialize(path)
6
- @path = path.kind_of?(Pathname) ? path : Pathname.new(path)
7
- @contents = @path.read
8
- end
9
-
10
- # @return [Array<String>] All strings found
11
- def extract
12
- @contents.scan(/\"(.*?[^\\])"|'(.*?[^\\])'/).flatten.compact
13
- end
14
-
15
- end
16
- end
1
+ module Translatomatic::Extractor
2
+ # Base class for string extraction functionality
3
+ class Base
4
+
5
+ def initialize(path)
6
+ @path = path.kind_of?(Pathname) ? path : Pathname.new(path)
7
+ @contents = @path.read
8
+ end
9
+
10
+ # @return [Array<String>] All strings found
11
+ def extract
12
+ @contents.scan(/\"(.*?[^\\])"|'(.*?[^\\])'/).flatten.compact
13
+ end
14
+
15
+ end
16
+ end
@@ -1,6 +1,6 @@
1
- module Translatomatic::Extractor
2
- # Class to extract strings from ruby code
3
- class Ruby < Base
4
-
5
- end # class
6
- end # module
1
+ module Translatomatic::Extractor
2
+ # Class to extract strings from ruby code
3
+ class Ruby < Base
4
+
5
+ end # class
6
+ end # module
@@ -1,5 +1,5 @@
1
- # Classes to extract strings from files
2
- module Translatomatic::Extractor; end
3
-
4
- require 'translatomatic/extractor/base'
5
- require 'translatomatic/extractor/ruby'
1
+ # Classes to extract strings from files
2
+ module Translatomatic::Extractor; end
3
+
4
+ require 'translatomatic/extractor/base'
5
+ require 'translatomatic/extractor/ruby'