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.
- checksums.yaml +4 -4
- data/.translatomatic/config.yml +18 -0
- data/.travis.yml +33 -33
- data/Gemfile +6 -4
- data/README.de.md +53 -18
- data/README.es.md +55 -20
- data/README.fr.md +54 -19
- data/README.it.md +58 -23
- data/README.ja.md +54 -19
- data/README.ko.md +58 -23
- data/README.md +167 -141
- data/README.ms.md +51 -16
- data/README.pt.md +58 -23
- data/README.ru.md +53 -18
- data/README.sv.md +53 -18
- data/README.zh.md +53 -18
- data/bin/translatomatic +6 -6
- data/bin/travis +24 -26
- data/config/locales/translatomatic/de.yml +22 -11
- data/config/locales/translatomatic/en.yml +21 -12
- data/config/locales/translatomatic/es.yml +22 -11
- data/config/locales/translatomatic/fr.yml +22 -12
- data/config/locales/translatomatic/it.yml +22 -11
- data/config/locales/translatomatic/ja.yml +22 -11
- data/config/locales/translatomatic/ko.yml +22 -11
- data/config/locales/translatomatic/ms.yml +22 -11
- data/config/locales/translatomatic/pt.yml +22 -11
- data/config/locales/translatomatic/ru.yml +22 -11
- data/config/locales/translatomatic/sv.yml +22 -11
- data/config/locales/translatomatic/zh.yml +22 -11
- data/db/migrate/201712170000_initial.rb +25 -25
- data/lib/translatomatic/cli/base.rb +81 -73
- data/lib/translatomatic/cli/config.rb +110 -81
- data/lib/translatomatic/cli/main.rb +85 -72
- data/lib/translatomatic/cli/translate.rb +141 -106
- data/lib/translatomatic/cli.rb +8 -8
- data/lib/translatomatic/config.rb +302 -155
- data/lib/translatomatic/converter.rb +28 -260
- data/lib/translatomatic/database.rb +134 -134
- data/lib/translatomatic/define_options.rb +22 -0
- data/lib/translatomatic/escaped_unicode.rb +0 -0
- data/lib/translatomatic/extractor/base.rb +16 -16
- data/lib/translatomatic/extractor/ruby.rb +6 -6
- data/lib/translatomatic/extractor.rb +5 -5
- data/lib/translatomatic/file_translator.rb +269 -0
- data/lib/translatomatic/http_request.rb +162 -162
- data/lib/translatomatic/locale.rb +76 -76
- data/lib/translatomatic/logger.rb +23 -23
- data/lib/translatomatic/model/locale.rb +25 -25
- data/lib/translatomatic/model/text.rb +19 -19
- data/lib/translatomatic/model.rb +1 -1
- data/lib/translatomatic/option.rb +37 -41
- data/lib/translatomatic/progress_updater.rb +13 -13
- data/lib/translatomatic/resource_file/base.rb +269 -192
- data/lib/translatomatic/resource_file/csv.rb +37 -0
- data/lib/translatomatic/resource_file/html.rb +54 -47
- data/lib/translatomatic/resource_file/markdown.rb +50 -55
- data/lib/translatomatic/resource_file/plist.rb +153 -19
- data/lib/translatomatic/resource_file/po.rb +107 -0
- data/lib/translatomatic/resource_file/properties.rb +91 -90
- data/lib/translatomatic/resource_file/resw.rb +50 -30
- data/lib/translatomatic/resource_file/subtitle.rb +75 -0
- data/lib/translatomatic/resource_file/text.rb +24 -30
- data/lib/translatomatic/resource_file/xcode_strings.rb +75 -80
- data/lib/translatomatic/resource_file/xml.rb +98 -91
- data/lib/translatomatic/resource_file/yaml.rb +94 -116
- data/lib/translatomatic/resource_file.rb +87 -78
- data/lib/translatomatic/string.rb +188 -188
- data/lib/translatomatic/tmx/document.rb +99 -99
- data/lib/translatomatic/translation_result.rb +63 -63
- data/lib/translatomatic/{converter_stats.rb → translation_stats.rb} +17 -17
- data/lib/translatomatic/translator/base.rb +1 -1
- data/lib/translatomatic/translator/google.rb +2 -0
- data/lib/translatomatic/translator.rb +10 -2
- data/lib/translatomatic/util.rb +45 -45
- data/lib/translatomatic/version.rb +7 -7
- data/lib/translatomatic.rb +52 -49
- data/translatomatic.gemspec +3 -2
- 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
|
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
|
data/lib/translatomatic/model.rb
CHANGED
@@ -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 [
|
11
|
-
#
|
12
|
-
attr_reader :
|
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
|
-
@
|
39
|
-
@
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
@
|
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
|
-
|
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
|