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,52 +1,52 @@
1
- require 'set'
2
-
1
+ require 'set'
2
+
3
3
  module Translatomatic
4
- # Stores results of a translation
5
- class TranslationResult
4
+ # Stores results of a translation
5
+ class TranslationResult
6
6
 
7
7
  # @return [Translatomatic::ResourceFile::Base] The resource file
8
8
  attr_reader :file
9
-
10
- # @return [Hash<String,String>] Translation results
9
+
10
+ # @return [Hash<String,String>] Translation results
11
11
  attr_reader :properties
12
-
13
- # @return [Locale] The locale of the original strings
14
- attr_reader :from_locale
15
-
16
- # @return [Locale] The target locale
17
- attr_reader :to_locale
18
-
19
- # @return [Set<String>] Untranslated strings
20
- attr_reader :untranslated
21
-
22
- # Create a translation result
23
- # @param file [Translatomatic::ResourceFile::Base] A resource file
24
- # @param to_locale [Locale] The target locale
12
+
13
+ # @return [Locale] The locale of the original strings
14
+ attr_reader :from_locale
15
+
16
+ # @return [Locale] The target locale
17
+ attr_reader :to_locale
18
+
19
+ # @return [Set<String>] Untranslated strings
20
+ attr_reader :untranslated
21
+
22
+ # Create a translation result
23
+ # @param file [Translatomatic::ResourceFile::Base] A resource file
24
+ # @param to_locale [Locale] The target locale
25
25
  def initialize(file, to_locale)
26
- @file = file
27
- @value_to_keys = {}
28
- @untranslated = Set.new
29
- @from_locale = file.locale
30
- @to_locale = to_locale
31
-
32
- # duplicate strings
33
- @properties = file.properties.transform_values { |i| i.dup }
34
-
35
- @properties.each do |key, value|
36
- # split property value into sentences
37
- string = string(value, from_locale)
38
- string.sentences.each do |sentence|
39
- @untranslated << sentence
40
- keylist = (@value_to_keys[sentence.to_s] ||= [])
41
- keylist << key
42
- end
43
- end
44
- end
45
-
26
+ @file = file
27
+ @value_to_keys = {}
28
+ @untranslated = Set.new
29
+ @from_locale = file.locale
30
+ @to_locale = to_locale
31
+
32
+ # duplicate strings
33
+ @properties = file.properties.transform_values { |i| i.dup }
34
+
35
+ @properties.each do |key, value|
36
+ # split property value into sentences
37
+ string = string(value, from_locale)
38
+ string.sentences.each do |sentence|
39
+ @untranslated << sentence
40
+ keylist = (@value_to_keys[sentence.to_s] ||= [])
41
+ keylist << key
42
+ end
43
+ end
44
+ end
45
+
46
46
  # Update result with a list of translated strings.
47
47
  # @param translations [Array<Translatomatic::Translation>] Translations
48
- # @return [void]
49
- def update_strings(translations)
48
+ # @return [void]
49
+ def update_strings(translations)
50
50
  # sort translation list by largest offset first so that we replace
51
51
  # from the end of the string to the front, so substring offsets
52
52
  # are correct in the target string.
@@ -57,30 +57,30 @@ module Translatomatic
57
57
  #end
58
58
  translations.sort_by! { |t| -t.original.offset }
59
59
 
60
- translations.each do |translation|
60
+ translations.each do |translation|
61
61
  update(translation.original, translation.result)
62
- end
62
+ end
63
63
  end
64
-
65
- private
66
-
67
- include Translatomatic::Util
68
-
69
- def update(original, translated)
70
- keys = @value_to_keys[original.to_s]
71
- raise "no key mapping for text '#{original}'" unless keys
72
- keys.each do |key|
64
+
65
+ private
66
+
67
+ include Translatomatic::Util
68
+
69
+ def update(original, translated)
70
+ keys = @value_to_keys[original.to_s]
71
+ raise "no key mapping for text '#{original}'" unless keys
72
+ keys.each do |key|
73
73
  #value = @properties[key]
74
74
  if original.kind_of?(Translatomatic::String) && original.substring?
75
- #log.debug("#{value[original.offset, original.length]} -> #{translated}")
76
- @properties[key][original.offset, original.length] = translated
77
- else
75
+ #log.debug("#{value[original.offset, original.length]} -> #{translated}")
76
+ @properties[key][original.offset, original.length] = translated
77
+ else
78
78
  #log.debug("#{key} -> #{translated}")
79
- @properties[key] = translated
80
- end
81
- end
82
-
83
- @untranslated.delete(original) unless translated.nil?
84
- end
85
- end
86
- end
79
+ @properties[key] = translated
80
+ end
81
+ end
82
+
83
+ @untranslated.delete(original) unless translated.nil?
84
+ end
85
+ end
86
+ end
@@ -1,31 +1,31 @@
1
- # Translation statistics
2
- class Translatomatic::ConverterStats
1
+ # Translation statistics
2
+ class Translatomatic::TranslationStats
3
3
  include Translatomatic::Util
4
-
4
+
5
5
  # @return [Array<Translatomatic::Translation>] A list of all translations
6
- attr_reader :translations
7
-
8
- # @return [Number] The number of translations that came from the database.
9
- attr_reader :from_db
10
-
11
- # @return [Number] The number of translations that came from the translator.
12
- attr_reader :from_translator
6
+ attr_reader :translations
7
+
8
+ # @return [Number] The number of translations that came from the database.
9
+ attr_reader :from_db
10
+
11
+ # @return [Number] The number of translations that came from the translator.
12
+ attr_reader :from_translator
13
13
 
14
14
  # @return [Number] The number of untranslated strings
15
15
  attr_reader :untranslated
16
16
 
17
- private
17
+ private
18
18
 
19
19
  def initialize(translations)
20
20
  @translations = translations.values
21
- @from_db = @translations.count { |i| i.from_database && i.result }
21
+ @from_db = @translations.count { |i| i.from_database && i.result }
22
22
  @from_translator = @translations.count { |i| !i.from_database && i.result }
23
23
  @untranslated = @translations.count { |i| i.result == nil }
24
24
  end
25
-
25
+
26
26
  def to_s
27
- t("converter.total_translations", total: @translations.length,
27
+ t("file_translator.total_translations", total: @translations.length,
28
28
  from_db: @from_db, from_translator: @from_translator,
29
- untranslated: @untranslated)
30
- end
31
- end
29
+ untranslated: @untranslated)
30
+ end
31
+ end
@@ -56,9 +56,9 @@ module Translatomatic
56
56
  translated = []
57
57
  untranslated = strings.dup
58
58
  request = Translatomatic::HTTPRequest.new(url)
59
+ fail_count = 0 # number of consecutive translation failures
59
60
 
60
61
  while !untranslated.empty? # request start block
61
- fail_count = 0 # number of consecutive translation failures
62
62
 
63
63
  request.start do |http|
64
64
  while !untranslated.empty?
@@ -1,3 +1,5 @@
1
+ require 'easy_translate'
2
+
1
3
  module Translatomatic
2
4
  module Translator
3
5
 
@@ -76,19 +76,21 @@ module Translatomatic::Translator
76
76
  # @return [String] A description of all translators and options
77
77
  def self.list
78
78
  out = t("translator.translators") + "\n"
79
+ configured_options = {}
79
80
  modules.each do |mod|
80
81
  out += "\n" + mod.name.demodulize + ":\n"
81
82
  opts = mod.options
82
83
  opts.each do |opt|
84
+ configured_options[opt.name] = config.get(opt.name)
83
85
  optname = opt.name.to_s.gsub("_", "-")
84
86
  out += " --%-18s %18s %10s %15s\n" % [optname, opt.description,
85
87
  opt.required ? t("translator.required_option") : "",
86
- opt.use_env ? "ENV[#{opt.name.upcase}]" : ""]
88
+ opt.env_name ? "ENV[#{opt.env_name}]" : ""]
87
89
  end
88
90
  end
89
91
  out += "\n"
90
92
  out += t("translator.configured") + "\n"
91
- configured = available
93
+ configured = available(configured_options)
92
94
  configured.each do |translator|
93
95
  out += " " + translator.name + "\n"
94
96
  end
@@ -96,4 +98,10 @@ module Translatomatic::Translator
96
98
  out + "\n"
97
99
  end
98
100
 
101
+ private
102
+
103
+ def self.config
104
+ Translatomatic.config
105
+ end
106
+
99
107
  end
@@ -1,45 +1,45 @@
1
- # Utility functions, used internally
2
- module Translatomatic::Util
3
-
4
- private
5
-
6
- # @!visibility private
7
- module CommonMethods
8
- private
9
- def t(key, options = {})
10
- tkey = "translatomatic.#{key}"
11
- raise "missing translation: #{tkey}" unless I18n.exists?(tkey)
12
- I18n.t(tkey, options)
13
- end
14
- end
15
-
16
- include CommonMethods
17
-
18
- # @!visibility private
19
- module ClassMethods
20
- private
21
- include CommonMethods
22
- end
23
-
24
- def self.included(klass)
25
- klass.extend(ClassMethods)
26
- end
27
-
28
- def log
29
- Translatomatic::Config.instance.logger
30
- end
31
-
32
- def locale(tag)
33
- Translatomatic::Locale.parse(tag)
34
- end
35
-
36
- def string(value, locale)
37
- Translatomatic::String.new(value, locale)
38
- end
39
-
40
- def hashify(list)
41
- hash = {}
42
- list.each { |i| hash[i.to_s] = i }
43
- hash
44
- end
45
- end
1
+ # Utility functions, used internally
2
+ module Translatomatic::Util
3
+
4
+ private
5
+
6
+ # @!visibility private
7
+ module CommonMethods
8
+ private
9
+ def t(key, options = {})
10
+ tkey = "translatomatic.#{key}"
11
+ raise "missing translation: #{tkey}" unless I18n.exists?(tkey)
12
+ I18n.t(tkey, options)
13
+ end
14
+ end
15
+
16
+ include CommonMethods
17
+
18
+ # @!visibility private
19
+ module ClassMethods
20
+ private
21
+ include CommonMethods
22
+ end
23
+
24
+ def self.included(klass)
25
+ klass.extend(ClassMethods)
26
+ end
27
+
28
+ def log
29
+ Translatomatic.config.logger
30
+ end
31
+
32
+ def locale(tag)
33
+ Translatomatic::Locale.parse(tag)
34
+ end
35
+
36
+ def string(value, locale)
37
+ Translatomatic::String.new(value, locale)
38
+ end
39
+
40
+ def hashify(list)
41
+ hash = {}
42
+ list.each { |i| hash[i.to_s] = i }
43
+ hash
44
+ end
45
+ end
@@ -1,7 +1,7 @@
1
- module Translatomatic
2
- # @return [String] Gem version
3
- VERSION = "0.1.2"
4
-
5
- # @return [String] Homepage
6
- URL = "https://github.com/smugglys/translatomatic"
7
- end
1
+ module Translatomatic
2
+ # @return [String] Gem version
3
+ VERSION = "0.1.3"
4
+
5
+ # @return [String] Homepage
6
+ URL = "https://github.com/smugglys/translatomatic"
7
+ end
@@ -1,49 +1,52 @@
1
- require 'i18n'
2
- require 'rails-i18n'
3
-
4
- # Module containing all of the translation goodness
5
- module Translatomatic
6
- # @return [Translatomatic::Config] configuration
7
- def self.config
8
- @config ||= Translatomatic::Config.new
9
- end
10
-
11
- private
12
-
13
- def self.init_i18n(lib_path)
14
- locale_path = File.join(File.dirname(lib_path), "..", "config", "locales")
15
- I18n.load_path += Dir[File.join(locale_path, "**", "*.yml")]
16
- end
17
- end
18
-
19
- begin
20
- Translatomatic.init_i18n(__FILE__)
21
- end
22
-
23
- require 'pathname'
24
- require 'active_support/core_ext/hash'
25
- require 'easy_translate'
26
- require 'i18n_data'
27
- require 'ruby-progressbar'
28
-
29
- require 'translatomatic/option'
30
- require 'translatomatic/locale'
31
- require 'translatomatic/string'
32
- require 'translatomatic/translation'
33
- require 'translatomatic/util'
34
- require 'translatomatic/version'
35
- require 'translatomatic/logger'
36
- require 'translatomatic/config'
37
- require 'translatomatic/database'
38
- require 'translatomatic/escaped_unicode'
39
- require 'translatomatic/model'
40
- require 'translatomatic/resource_file'
41
- require 'translatomatic/http_request'
42
- require 'translatomatic/translator'
43
- require 'translatomatic/translation_result'
44
- require 'translatomatic/converter_stats'
45
- require 'translatomatic/converter'
46
- require 'translatomatic/extractor'
47
- require 'translatomatic/progress_updater'
48
- require 'translatomatic/tmx'
49
- require 'translatomatic/cli'
1
+ require 'i18n'
2
+ require 'rails-i18n'
3
+ require 'i18n_data'
4
+
5
+ require 'pathname'
6
+ require 'active_support/core_ext/hash'
7
+ require 'active_support/dependencies/autoload'
8
+
9
+ # Module containing all of the translation goodness
10
+ module Translatomatic
11
+
12
+ # @return [Translatomatic::Config] configuration
13
+ def self.config
14
+ @config ||= Translatomatic::Config.new
15
+ end
16
+
17
+ private
18
+
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")]
22
+ end
23
+ end
24
+
25
+ begin
26
+ Translatomatic.init_i18n(__FILE__)
27
+ end
28
+
29
+ require 'translatomatic/version'
30
+ require 'translatomatic/option'
31
+ require 'translatomatic/define_options'
32
+ require 'translatomatic/locale'
33
+ require 'translatomatic/string'
34
+ require 'translatomatic/translation'
35
+ require 'translatomatic/util'
36
+ require 'translatomatic/version'
37
+ require 'translatomatic/logger'
38
+ require 'translatomatic/config'
39
+ require 'translatomatic/database'
40
+ require 'translatomatic/escaped_unicode'
41
+ require 'translatomatic/model'
42
+ require 'translatomatic/resource_file'
43
+ require 'translatomatic/http_request'
44
+ require 'translatomatic/converter'
45
+ require 'translatomatic/translator'
46
+ require 'translatomatic/translation_result'
47
+ require 'translatomatic/translation_stats'
48
+ require 'translatomatic/file_translator'
49
+ require 'translatomatic/extractor'
50
+ require 'translatomatic/progress_updater'
51
+ require 'translatomatic/tmx'
52
+ require 'translatomatic/cli'
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Andrew Williams"]
10
10
  spec.email = ["contact@smugglys.com"]
11
11
 
12
- spec.summary = %q{Strings translation utility}
12
+ spec.summary = %q{File translation and conversion utility}
13
13
  spec.homepage = Translatomatic::URL
14
14
  spec.license = "MIT"
15
15
 
@@ -41,5 +41,6 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency "ruby-progressbar"
42
42
  spec.add_dependency "kramdown" # markdown -> html
43
43
  spec.add_dependency "reverse_markdown" # html -> markdown
44
- spec.add_dependency "concurrent-ruby"
44
+ spec.add_dependency "PoParser"
45
+ spec.add_dependency "titlekit"
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translatomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-01 00:00:00.000000000 Z
11
+ date: 2018-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -263,7 +263,21 @@ dependencies:
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  - !ruby/object:Gem::Dependency
266
- name: concurrent-ruby
266
+ name: PoParser
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: titlekit
267
281
  requirement: !ruby/object:Gem::Requirement
268
282
  requirements:
269
283
  - - ">="
@@ -287,6 +301,7 @@ files:
287
301
  - ".gitattributes"
288
302
  - ".gitignore"
289
303
  - ".rspec"
304
+ - ".translatomatic/config.yml"
290
305
  - ".travis.yml"
291
306
  - ".yardopts"
292
307
  - CODE_OF_CONDUCT.md
@@ -334,12 +349,13 @@ files:
334
349
  - lib/translatomatic/cli/translate.rb
335
350
  - lib/translatomatic/config.rb
336
351
  - lib/translatomatic/converter.rb
337
- - lib/translatomatic/converter_stats.rb
338
352
  - lib/translatomatic/database.rb
353
+ - lib/translatomatic/define_options.rb
339
354
  - lib/translatomatic/escaped_unicode.rb
340
355
  - lib/translatomatic/extractor.rb
341
356
  - lib/translatomatic/extractor/base.rb
342
357
  - lib/translatomatic/extractor/ruby.rb
358
+ - lib/translatomatic/file_translator.rb
343
359
  - lib/translatomatic/http_request.rb
344
360
  - lib/translatomatic/locale.rb
345
361
  - lib/translatomatic/logger.rb
@@ -350,11 +366,14 @@ files:
350
366
  - lib/translatomatic/progress_updater.rb
351
367
  - lib/translatomatic/resource_file.rb
352
368
  - lib/translatomatic/resource_file/base.rb
369
+ - lib/translatomatic/resource_file/csv.rb
353
370
  - lib/translatomatic/resource_file/html.rb
354
371
  - lib/translatomatic/resource_file/markdown.rb
355
372
  - lib/translatomatic/resource_file/plist.rb
373
+ - lib/translatomatic/resource_file/po.rb
356
374
  - lib/translatomatic/resource_file/properties.rb
357
375
  - lib/translatomatic/resource_file/resw.rb
376
+ - lib/translatomatic/resource_file/subtitle.rb
358
377
  - lib/translatomatic/resource_file/text.rb
359
378
  - lib/translatomatic/resource_file/xcode_strings.rb
360
379
  - lib/translatomatic/resource_file/xml.rb
@@ -365,6 +384,7 @@ files:
365
384
  - lib/translatomatic/tmx/translation_unit.rb
366
385
  - lib/translatomatic/translation.rb
367
386
  - lib/translatomatic/translation_result.rb
387
+ - lib/translatomatic/translation_stats.rb
368
388
  - lib/translatomatic/translator.rb
369
389
  - lib/translatomatic/translator/base.rb
370
390
  - lib/translatomatic/translator/frengly.rb
@@ -399,5 +419,5 @@ rubyforge_project:
399
419
  rubygems_version: 2.6.11
400
420
  signing_key:
401
421
  specification_version: 4
402
- summary: Strings translation utility
422
+ summary: File translation and conversion utility
403
423
  test_files: []