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.
- checksums.yaml +5 -5
- data/.gitattributes +20 -20
- data/.gitignore +19 -15
- data/.rspec +3 -3
- data/.rubocop.yml +28 -0
- data/.translatomatic/config.yml +4 -0
- data/.travis.yml +4 -6
- data/.yardopts +9 -9
- data/Gemfile +8 -4
- data/Guardfile +4 -5
- data/README.de.md +55 -50
- data/README.en.md +177 -0
- data/README.es.md +53 -48
- data/README.fr.md +53 -48
- data/README.it.md +54 -49
- data/README.ja.md +63 -58
- data/README.ko.md +59 -54
- data/README.md +17 -13
- data/README.ms.md +50 -45
- data/README.pt.md +54 -49
- data/README.ru.md +57 -52
- data/README.sv.md +51 -46
- data/README.zh.md +60 -55
- data/Rakefile +3 -3
- data/TODO.txt +6 -0
- data/bin/console +3 -3
- data/bin/translatomatic +4 -2
- data/config/i18n-tasks.yml +130 -0
- data/config/locales/translatomatic/de.yml +141 -99
- data/config/locales/translatomatic/en.yml +129 -89
- data/config/locales/translatomatic/es.yml +136 -99
- data/config/locales/translatomatic/fr.yml +139 -100
- data/config/locales/translatomatic/it.yml +135 -97
- data/config/locales/translatomatic/ja.yml +137 -98
- data/config/locales/translatomatic/ko.yml +138 -98
- data/config/locales/translatomatic/ms.yml +138 -100
- data/config/locales/translatomatic/pt.yml +137 -101
- data/config/locales/translatomatic/ru.yml +136 -98
- data/config/locales/translatomatic/sv.yml +134 -96
- data/config/locales/translatomatic/zh.yml +136 -97
- data/db/migrate/201712170000_initial.rb +2 -3
- data/lib/translatomatic.rb +40 -25
- data/lib/translatomatic/cli.rb +5 -1
- data/lib/translatomatic/cli/base.rb +61 -58
- data/lib/translatomatic/cli/common_options.rb +14 -11
- data/lib/translatomatic/cli/config.rb +96 -91
- data/lib/translatomatic/cli/database.rb +85 -23
- data/lib/translatomatic/cli/main.rb +158 -104
- data/lib/translatomatic/cli/thor.rb +29 -0
- data/lib/translatomatic/cli/translate.rb +134 -157
- data/lib/translatomatic/config.rb +10 -301
- data/lib/translatomatic/config/display.rb +78 -0
- data/lib/translatomatic/config/files.rb +60 -0
- data/lib/translatomatic/config/location_settings.rb +133 -0
- data/lib/translatomatic/config/options.rb +68 -0
- data/lib/translatomatic/config/selector.rb +127 -0
- data/lib/translatomatic/config/settings.rb +148 -0
- data/lib/translatomatic/converter.rb +40 -28
- data/lib/translatomatic/database.rb +127 -110
- data/lib/translatomatic/define_options.rb +4 -5
- data/lib/translatomatic/escaped_unicode.rb +86 -76
- data/lib/translatomatic/extractor.rb +5 -2
- data/lib/translatomatic/extractor/base.rb +12 -12
- data/lib/translatomatic/extractor/ruby.rb +7 -6
- data/lib/translatomatic/file_translator.rb +101 -244
- data/lib/translatomatic/flattenation.rb +39 -0
- data/lib/translatomatic/http.rb +13 -0
- data/lib/translatomatic/http/client.rb +144 -0
- data/lib/translatomatic/http/exception.rb +43 -0
- data/lib/translatomatic/http/file_param.rb +27 -0
- data/lib/translatomatic/http/param.rb +37 -0
- data/lib/translatomatic/http/request.rb +91 -0
- data/lib/translatomatic/i18n.rb +43 -0
- data/lib/translatomatic/locale.rb +71 -59
- data/lib/translatomatic/logger.rb +43 -28
- data/lib/translatomatic/metadata.rb +58 -0
- data/lib/translatomatic/model.rb +4 -2
- data/lib/translatomatic/model/locale.rb +5 -5
- data/lib/translatomatic/model/text.rb +5 -5
- data/lib/translatomatic/option.rb +57 -34
- data/lib/translatomatic/path_utils.rb +126 -0
- data/lib/translatomatic/progress_updater.rb +13 -16
- data/lib/translatomatic/provider.rb +101 -0
- data/lib/translatomatic/provider/base.rb +136 -0
- data/lib/translatomatic/provider/frengly.rb +55 -0
- data/lib/translatomatic/provider/google.rb +78 -0
- data/lib/translatomatic/provider/google_web.rb +50 -0
- data/lib/translatomatic/provider/microsoft.rb +144 -0
- data/lib/translatomatic/provider/my_memory.rb +75 -0
- data/lib/translatomatic/provider/yandex.rb +61 -0
- data/lib/translatomatic/resource_file.rb +59 -53
- data/lib/translatomatic/resource_file/base.rb +171 -237
- data/lib/translatomatic/resource_file/csv.rb +176 -24
- data/lib/translatomatic/resource_file/html.rb +21 -42
- data/lib/translatomatic/resource_file/key_value_support.rb +117 -0
- data/lib/translatomatic/resource_file/markdown.rb +36 -38
- data/lib/translatomatic/resource_file/plist.rb +121 -126
- data/lib/translatomatic/resource_file/po.rb +104 -82
- data/lib/translatomatic/resource_file/properties.rb +48 -77
- data/lib/translatomatic/resource_file/properties.treetop +87 -0
- data/lib/translatomatic/resource_file/resw.rb +56 -41
- data/lib/translatomatic/resource_file/subtitle.rb +86 -54
- data/lib/translatomatic/resource_file/text.rb +18 -18
- data/lib/translatomatic/resource_file/xcode_strings.rb +32 -63
- data/lib/translatomatic/resource_file/xcode_strings.treetop +85 -0
- data/lib/translatomatic/resource_file/xml.rb +94 -81
- data/lib/translatomatic/resource_file/yaml.rb +54 -68
- data/lib/translatomatic/retry_executor.rb +37 -0
- data/lib/translatomatic/slurp.rb +32 -0
- data/lib/translatomatic/string_batcher.rb +50 -0
- data/lib/translatomatic/string_escaping.rb +61 -0
- data/lib/translatomatic/text.rb +263 -0
- data/lib/translatomatic/text_collection.rb +66 -0
- data/lib/translatomatic/tmx.rb +5 -3
- data/lib/translatomatic/tmx/document.rb +107 -82
- data/lib/translatomatic/tmx/translation_unit.rb +19 -18
- data/lib/translatomatic/translation.rb +8 -28
- data/lib/translatomatic/translation/collection.rb +199 -0
- data/lib/translatomatic/translation/fetcher.rb +123 -0
- data/lib/translatomatic/translation/munging.rb +112 -0
- data/lib/translatomatic/translation/result.rb +50 -0
- data/lib/translatomatic/translation/sharer.rb +32 -0
- data/lib/translatomatic/translation/stats.rb +44 -0
- data/lib/translatomatic/translator.rb +91 -88
- data/lib/translatomatic/type_cast.rb +63 -0
- data/lib/translatomatic/util.rb +37 -33
- data/lib/translatomatic/version.rb +2 -2
- data/translatomatic.gemspec +57 -46
- metadata +136 -59
- data/lib/translatomatic/http_request.rb +0 -162
- data/lib/translatomatic/string.rb +0 -188
- data/lib/translatomatic/translation_result.rb +0 -86
- data/lib/translatomatic/translation_stats.rb +0 -31
- data/lib/translatomatic/translator/base.rb +0 -128
- data/lib/translatomatic/translator/frengly.rb +0 -62
- data/lib/translatomatic/translator/google.rb +0 -37
- data/lib/translatomatic/translator/microsoft.rb +0 -41
- data/lib/translatomatic/translator/my_memory.rb +0 -68
- data/lib/translatomatic/translator/yandex.rb +0 -56
@@ -1,36 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
26
|
+
private
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
def respond_to_missing?(name, include_private = false)
|
29
|
+
@logger.respond_to?(name, include_private) || super
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
data/lib/translatomatic/model.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
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:
|
6
|
+
has_many :texts, class_name: 'Translatomatic::Model::Text'
|
7
7
|
validates_presence_of :language
|
8
|
-
validates_uniqueness_of :language, scope: [
|
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:
|
7
|
-
belongs_to :from_text, class_name:
|
8
|
-
has_many :translations, class_name:
|
9
|
-
|
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
|
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
|
32
|
-
|
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
|
36
|
+
# @param attributes [Hash<Symbol,Object>] Attributes as above
|
36
37
|
# @return [Translatomatic::Option] A new option instance
|
37
|
-
def initialize(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@
|
43
|
-
@type
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@
|
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
|
-
|
54
|
-
type = @type == :array ? :string : @type
|
55
|
-
|
56
|
-
{ name: @name,
|
53
|
+
{
|
57
54
|
required: @required,
|
58
|
-
type:
|
55
|
+
type: thor_type,
|
59
56
|
desc: @description,
|
60
57
|
default: @default,
|
61
58
|
aliases: @aliases,
|
62
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|