translatomatic 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
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,76 +1,76 @@
1
- # Represents a locale
2
- # @see https://en.wikipedia.org/wiki/Locale_(computer_software)
3
- class Translatomatic::Locale
4
-
5
- # @return [String] ISO 639-1 language
6
- attr_reader :language
7
-
8
- # @return [String] ISO 15924 script
9
- attr_reader :script
10
-
11
- # @return [String] ISO 3166-1 alpha-2 country code
12
- attr_reader :region
13
-
14
- # Parse the given tag
15
- # @param tag [String] A string representing a locale
16
- # @param validate [boolean] If true, return nil if the locale is invalid
17
- # @return [Locale] A locale object
18
- def self.parse(tag, validate = true)
19
- return nil if tag.nil?
20
-
21
- locale = tag
22
- unless tag.kind_of?(Translatomatic::Locale)
23
- tag = tag.to_s.gsub(/_/, '-')
24
- locale = new(tag)
25
- end
26
- validate && !locale.valid? ? nil : locale
27
- end
28
-
29
- # @return [Locale] the default locale
30
- def self.default
31
- parse(Translatomatic::Config.instance.default_locale)
32
- end
33
-
34
- # @return [Locale] create a new locale object
35
- def initialize(tag)
36
- data = I18n::Locale::Tag::Rfc4646.tag(tag)
37
- if data
38
- @language = data.language
39
- @script = data.script
40
- @region = data.region
41
- end
42
- end
43
-
44
- # @return true if language is a valid ISO 639-1 language
45
- def valid?
46
- VALID_LANGUAGES.include?(language)
47
- end
48
-
49
- # @return [String] Locale as a string
50
- def to_s
51
- [language, script, region].compact.join("-")
52
- end
53
-
54
- # @param other [Object] Another object
55
- # @return [boolean] true if the other object is a {Translatomatic::Locale}
56
- # object and has equal language, script and region.
57
- def eql?(other)
58
- other.kind_of?(Translatomatic::Locale) && other.hash == hash
59
- end
60
-
61
- # (see #eql?)
62
- def ==(other)
63
- eql?(other)
64
- end
65
-
66
- # @!visibility private
67
- def hash
68
- [language, script, region].hash
69
- end
70
-
71
- private
72
-
73
- # list of 2 letter country codes
74
- VALID_LANGUAGES = ::I18nData.languages.keys.collect { |i| i.downcase }.sort
75
-
76
- end
1
+ # Represents a locale
2
+ # @see https://en.wikipedia.org/wiki/Locale_(computer_software)
3
+ class Translatomatic::Locale
4
+
5
+ # @return [String] ISO 639-1 language
6
+ attr_reader :language
7
+
8
+ # @return [String] ISO 15924 script
9
+ attr_reader :script
10
+
11
+ # @return [String] ISO 3166-1 alpha-2 country code
12
+ attr_reader :region
13
+
14
+ # Parse the given tag
15
+ # @param tag [String] A string representing a locale
16
+ # @param validate [boolean] If true, return nil if the locale is invalid
17
+ # @return [Locale] A locale object
18
+ def self.parse(tag, validate = true)
19
+ return nil if tag.nil?
20
+
21
+ locale = tag
22
+ unless tag.kind_of?(Translatomatic::Locale)
23
+ tag = tag.to_s.gsub(/_/, '-')
24
+ locale = new(tag)
25
+ end
26
+ validate && !locale.valid? ? nil : locale
27
+ end
28
+
29
+ # @return [Locale] the default locale
30
+ def self.default
31
+ parse(Translatomatic.config.default_locale)
32
+ end
33
+
34
+ # @return [Locale] create a new locale object
35
+ def initialize(tag)
36
+ data = I18n::Locale::Tag::Rfc4646.tag(tag)
37
+ if data
38
+ @language = data.language
39
+ @script = data.script
40
+ @region = data.region
41
+ end
42
+ end
43
+
44
+ # @return true if language is a valid ISO 639-1 language
45
+ def valid?
46
+ VALID_LANGUAGES.include?(language)
47
+ end
48
+
49
+ # @return [String] Locale as a string
50
+ def to_s
51
+ [language, script, region].compact.join("-")
52
+ end
53
+
54
+ # @param other [Object] Another object
55
+ # @return [boolean] true if the other object is a {Translatomatic::Locale}
56
+ # object and has equal language, script and region.
57
+ def eql?(other)
58
+ other.kind_of?(Translatomatic::Locale) && other.hash == hash
59
+ end
60
+
61
+ # (see #eql?)
62
+ def ==(other)
63
+ eql?(other)
64
+ end
65
+
66
+ # @!visibility private
67
+ def hash
68
+ [language, script, region].hash
69
+ end
70
+
71
+ private
72
+
73
+ # list of 2 letter country codes
74
+ VALID_LANGUAGES = ::I18nData.languages.keys.collect { |i| i.downcase }.sort
75
+
76
+ end
@@ -1,36 +1,36 @@
1
1
  # Logging
2
2
  class Translatomatic::Logger
3
3
 
4
- # @return [ProgressBar] A progress bar
5
- attr_accessor :progressbar
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"
13
+ end
14
+ end
6
15
 
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"
13
- end
14
- end
15
-
16
16
  # Called at the end of translatomatic to clear the progress bar.
17
17
  def finish
18
- @finished ||= begin
18
+ @finished ||= begin
19
19
  @progressbar.finish if @progressbar
20
20
  true
21
- end
22
- end
21
+ end
22
+ end
23
23
 
24
- private
24
+ private
25
25
 
26
26
  def method_missing(name, *args)
27
27
  handle_logger_method(name, args) if @logger.respond_to?(name)
28
28
  end
29
-
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
35
-
36
- end
29
+
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
35
+
36
+ end
@@ -1,25 +1,25 @@
1
- module Translatomatic
2
- module Model
3
- # Locale database record.
4
- # Used to store translations in the database.
5
- class Locale < ActiveRecord::Base
6
- has_many :texts, class_name: "Translatomatic::Model::Text"
7
- validates_presence_of :language
8
- validates_uniqueness_of :language, scope: [:script, :region]
9
-
10
- # Create a locale record from an I18n::Locale::Tag object or string
11
- # @return [Translatomatic::Model::Locale] Locale record
12
- def self.from_tag(tag)
13
- tag = Translatomatic::Locale.parse(tag)
14
- find_or_create_by!({
15
- language: tag.language, script: tag.script, region: tag.region
16
- })
17
- end
18
-
19
- # @return [String] Locale as string
20
- def to_s
21
- [language, script, region].compact.join("-")
22
- end
23
- end
24
- end
25
- end
1
+ module Translatomatic
2
+ module Model
3
+ # Locale database record.
4
+ # Used to store translations in the database.
5
+ class Locale < ActiveRecord::Base
6
+ has_many :texts, class_name: "Translatomatic::Model::Text"
7
+ validates_presence_of :language
8
+ validates_uniqueness_of :language, scope: [:script, :region]
9
+
10
+ # Create a locale record from an I18n::Locale::Tag object or string
11
+ # @return [Translatomatic::Model::Locale] Locale record
12
+ def self.from_tag(tag)
13
+ tag = Translatomatic::Locale.parse(tag)
14
+ find_or_create_by!({
15
+ language: tag.language, script: tag.script, region: tag.region
16
+ })
17
+ end
18
+
19
+ # @return [String] Locale as string
20
+ def to_s
21
+ [language, script, region].compact.join("-")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,19 +1,19 @@
1
- module Translatomatic
2
- module Model
3
- # Text database record.
4
- # Used to store translations in the database.
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
10
-
11
- validates_presence_of :value
12
- validates_presence_of :locale
13
-
14
- def is_translated?
15
- !from_text_id.nil?
16
- end
17
- end
18
- end
19
- end
1
+ module Translatomatic
2
+ module Model
3
+ # Text database record.
4
+ # Used to store translations in the database.
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
10
+
11
+ validates_presence_of :value
12
+ validates_presence_of :locale
13
+
14
+ def is_translated?
15
+ !from_text_id.nil?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
- # Contains classes that interface to records in the translatomatic database
1
+ # Contains classes that interface to records in the translatomatic database
2
2
  module Translatomatic::Model; end
3
3
 
4
4
  require 'translatomatic/model/locale'
@@ -1,4 +1,4 @@
1
- module Translatomatic
1
+ module Translatomatic
2
2
  # Stores details about command line and object constructor options
3
3
  class Option
4
4
  # @return [String] Name of the option
@@ -7,12 +7,12 @@ module Translatomatic
7
7
  # @return [boolean] True if this option is required
8
8
  attr_reader :required
9
9
 
10
- # @return [boolean] If true, the option can be set via an environment
11
- # variable corresponding to the uppercased version of {name}.
12
- attr_reader :use_env
10
+ # @return [String] If set, the name of the environment variable
11
+ # that can be used to set this option in the environment.
12
+ attr_reader :env_name
13
13
 
14
14
  # @return [String] Description of the option
15
- attr_reader :description
15
+ attr_reader :description
16
16
 
17
17
  # @return [boolean] If true, the option does not appear on the command line
18
18
  # but it can be used in configuration settings
@@ -25,23 +25,42 @@ module Translatomatic
25
25
  # @return [Object] The default value for this option
26
26
  attr_reader :default
27
27
 
28
+ # @return [boolean] True if this option can only be set on the command line
29
+ attr_reader :command_line_only
30
+
31
+ # @return [boolean] True if this option can only be set in user context
32
+ attr_reader :user_context_only
33
+
28
34
  # Create a new option
29
35
  # @param data [Hash<Symbol,Object>] Attributes as above
30
- # @return [Translatomatic::Option] A new option instance
31
- def initialize(data = {})
32
- @name = data[:name]
33
- @required = data[:required]
34
- @use_env = data[:use_env]
36
+ # @return [Translatomatic::Option] A new option instance
37
+ def initialize(data = {})
38
+ @name = data[:name]
39
+ @required = data[:required]
35
40
  @description = data[:desc]
41
+ @use_env = data[:use_env]
36
42
  @hidden = data[:hidden]
43
+ @type = data[:type] || :string
37
44
  @default = data[:default]
38
- @type = data[:type] || :string
39
- @data = data
40
- end
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)
50
+ end
41
51
 
42
- # @return [Hash] Option data as a hash
43
- def to_hash
44
- @data
52
+ def to_thor
53
+ # use internal ',' splitting for array types on command line
54
+ type = @type == :array ? :string : @type
55
+
56
+ { name: @name,
57
+ required: @required,
58
+ type: type,
59
+ desc: @description,
60
+ default: @default,
61
+ aliases: @aliases,
62
+ enum: @enum ? @enum.collect { |i| i.to_s } : nil
63
+ }
45
64
  end
46
65
 
47
66
  # Retrieve all options from an object or list of objects.
@@ -61,29 +80,6 @@ module Translatomatic
61
80
  end
62
81
  end
63
82
  options
64
- end
65
- end
66
-
67
- private
68
-
69
- # @!visibility private
70
- module DefineOptions
71
-
72
- # @!visibility private
73
- module ClassMethods
74
- attr_reader :options
75
-
76
- private
77
-
78
- def define_options(*options)
79
- @options = options.collect { |i| Translatomatic::Option.new(i) }
80
- end
81
83
  end
82
-
83
- private
84
-
85
- def self.included(klass)
86
- klass.extend(ClassMethods)
87
- end
88
- end
89
- end
84
+ end
85
+ end
@@ -1,19 +1,19 @@
1
- # implements Converter listener
2
- class Translatomatic::ProgressUpdater
1
+ # implements Converter listener
2
+ class Translatomatic::ProgressUpdater
3
3
  # Create a new progress updater
4
4
  # @param progressbar [Progressbar] A ruby-progressbar object
5
- def initialize(progressbar)
6
- @progressbar = progressbar
7
- end
8
-
5
+ def initialize(progressbar)
6
+ @progressbar = progressbar
7
+ end
8
+
9
9
  # @return [Number] the number of translated strings
10
- def translated_texts(texts)
10
+ def translated_texts(texts)
11
11
  @progressbar.progress += texts.length
12
- end
12
+ end
13
13
 
14
- # @return [Number] the number of untranslated strings
15
- def untranslated_texts(texts)
14
+ # @return [Number] the number of untranslated strings
15
+ def untranslated_texts(texts)
16
16
  @progressbar.total -= texts.length
17
- end
18
-
19
- end
17
+ end
18
+
19
+ end