web_translate_it 2.6.3.pre1 → 2.6.4
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/bin/wti +87 -87
- data/examples/locale.rb +2 -0
- data/generators/webtranslateit/webtranslateit_generator.rb +3 -1
- data/history.md +6 -1
- data/lib/web_translate_it/auto_fetch.rb +4 -0
- data/lib/web_translate_it/command_line.rb +30 -26
- data/lib/web_translate_it/configuration.rb +8 -4
- data/lib/web_translate_it/connection.rb +4 -0
- data/lib/web_translate_it/project.rb +5 -1
- data/lib/web_translate_it/string.rb +6 -2
- data/lib/web_translate_it/term.rb +6 -2
- data/lib/web_translate_it/term_translation.rb +4 -0
- data/lib/web_translate_it/translation.rb +4 -0
- data/lib/web_translate_it/translation_file.rb +6 -2
- data/lib/web_translate_it/util/array_util.rb +2 -0
- data/lib/web_translate_it/util/hash_util.rb +4 -0
- data/lib/web_translate_it/util/string_util.rb +2 -0
- data/lib/web_translate_it/util.rb +19 -16
- data/lib/web_translate_it.rb +2 -0
- data/readme.md +1 -1
- metadata +5 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186304899ba3932f5c4152b0a02bc34fbdb47d0392c88d8931e30976e66ea916
|
4
|
+
data.tar.gz: 90cdef9f2d193d4d00a34a2362a7af85e2f7fb010d0455f47c1991935d7e0b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d78a7788bec607b0722bce91668ea89bfb6c05c6c2c5a1baaeb34fbfbc446f16817ac84f5a902c7edb6860fe626f6de2fd03dde9dd6cb96076c3f703fccb1a0
|
7
|
+
data.tar.gz: 22ae36a655963dfc12092951c2aee41fa29612e1a69ae05ce0bb79b9361ce1eb81755cdaf3a7b53152e46971d5af322989424f22ff6eb9428f7b961fb1dcbcd0
|
data/bin/wti
CHANGED
@@ -34,93 +34,93 @@ end
|
|
34
34
|
|
35
35
|
command = ARGV.shift # get the subcommand
|
36
36
|
command_options = case command
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
37
|
+
when 'pull'
|
38
|
+
Optimist.options do
|
39
|
+
banner <<~BANNER
|
40
|
+
wti pull [filename] - Pull target language file(s)
|
41
|
+
[options] are:
|
42
|
+
BANNER
|
43
|
+
opt :locale, 'ISO code of locale(s) to pull, space-separated', type: :string
|
44
|
+
opt :all, 'Pull all files'
|
45
|
+
opt :force, 'Force pull (bypass conditional requests to WTI)'
|
46
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
47
|
+
opt :debug, 'Display debug information'
|
48
|
+
end
|
49
|
+
when 'push'
|
50
|
+
Optimist.options do
|
51
|
+
banner <<~BANNER
|
52
|
+
wti push [filename] - Push master language file(s)
|
53
|
+
[options] are:
|
54
|
+
BANNER
|
55
|
+
opt :locale, 'ISO code of locale(s) to push, space-separated', type: :string
|
56
|
+
opt :target, 'Upload all target files'
|
57
|
+
opt :force, 'Force push (bypass conditional requests to WTI)'
|
58
|
+
opt :low_priority, 'WTI will process this file with a low priority'
|
59
|
+
opt :merge, 'Force WTI to merge this file'
|
60
|
+
opt :ignore_missing, 'Force WTI to not obsolete missing strings'
|
61
|
+
opt :minor, 'Minor Changes. When pushing a master file, prevents target translations to be flagged as `to_verify`.'
|
62
|
+
opt :label, 'Apply a label to the changes', type: :string
|
63
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
64
|
+
opt :all, 'DEPRECATED -- See `wti push --target` instead'
|
65
|
+
opt :debug, 'Display debug information'
|
66
|
+
end
|
67
|
+
when 'add'
|
68
|
+
Optimist.options do
|
69
|
+
banner 'wti add filename - Create and push a new master language file'
|
70
|
+
opt :low_priority, 'WTI will process this file with a low priority'
|
71
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
72
|
+
opt :debug, 'Display debug information'
|
73
|
+
end
|
74
|
+
when 'rm'
|
75
|
+
Optimist.options do
|
76
|
+
banner 'wti rm filename - Delete a master language file'
|
77
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
78
|
+
opt :debug, 'Display debug information'
|
79
|
+
end
|
80
|
+
when 'mv'
|
81
|
+
Optimist.options do
|
82
|
+
banner 'wti mv filename - Moves a master language file and its target files'
|
83
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
84
|
+
opt :debug, 'Display debug information'
|
85
|
+
end
|
86
|
+
when 'addlocale'
|
87
|
+
Optimist.options do
|
88
|
+
banner 'wti addlocale localename - Add a new locale to the project'
|
89
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
90
|
+
opt :debug, 'Display debug information'
|
91
|
+
end
|
92
|
+
when 'rmlocale'
|
93
|
+
Optimist.options do
|
94
|
+
banner 'wti rmlocale localename Delete a locale from the project'
|
95
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
96
|
+
opt :debug, 'Display debug information'
|
97
|
+
end
|
98
|
+
when 'status'
|
99
|
+
Optimist.options do
|
100
|
+
banner "wti status - Fetch and display project statistics.\nReturns 100 if untranslated segments exist in project\nReturns 101 if unproofread segments exist in project."
|
101
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
102
|
+
opt :debug, 'Display debug information'
|
103
|
+
end
|
104
|
+
when 'init'
|
105
|
+
Optimist.options do
|
106
|
+
banner 'wti init [api_token] - Configure your project to sync'
|
107
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
108
|
+
opt :debug, 'Display debug information'
|
109
|
+
end
|
110
|
+
when 'match'
|
111
|
+
Optimist.options do
|
112
|
+
banner 'wti match - Display matching of local files with File Manager'
|
113
|
+
opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
|
114
|
+
opt :debug, 'Display debug information'
|
115
|
+
end
|
116
|
+
else
|
117
|
+
if command.nil?
|
118
|
+
puts show_commands
|
119
|
+
exit
|
120
|
+
else
|
121
|
+
Optimist.die "Unknown subcommand #{command.inspect}"
|
122
|
+
end
|
123
|
+
end
|
124
124
|
|
125
125
|
begin
|
126
126
|
WebTranslateIt::Connection.turn_debug_on if command_options.debug
|
data/examples/locale.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/lib/insert_commands.rb")
|
2
2
|
|
3
3
|
class WebtranslateitGenerator < Rails::Generator::Base
|
4
|
+
|
4
5
|
def add_options!(opt)
|
5
6
|
opt.on('-k', '--api-key=key', String, 'Your Web Translate It API key') { |v| options[:api_key] = v }
|
6
7
|
end
|
@@ -14,7 +15,7 @@ class WebtranslateitGenerator < Rails::Generator::Base
|
|
14
15
|
if options[:api_key]
|
15
16
|
project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
|
16
17
|
m.template '.wti', '.wti',
|
17
|
-
assigns: {
|
18
|
+
assigns: {api_key: options[:api_key], project: project_details['project']}
|
18
19
|
m.append_to 'Rakefile', "require 'web_translate_it' rescue LoadError"
|
19
20
|
end
|
20
21
|
end
|
@@ -23,4 +24,5 @@ class WebtranslateitGenerator < Rails::Generator::Base
|
|
23
24
|
def api_key_configured?
|
24
25
|
File.exist?('config/translations.yml')
|
25
26
|
end
|
27
|
+
|
26
28
|
end
|
data/history.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
## Version 2.6.
|
1
|
+
## Version 2.6.4 / 2022-09-22
|
2
|
+
|
3
|
+
* Move development dependencies to Gemfile and commit Gemfile.lock to version control.
|
4
|
+
* wti now sends a `User-Agent` header.
|
5
|
+
|
6
|
+
## Version 2.6.3 / 2022-06-14
|
2
7
|
|
3
8
|
* Fix deprecation warning. #181
|
4
9
|
* Set minimum ruby version to 2.6. It is [EOL since December 2018](https://endoflife.date/ruby), but it’s still the default ruby shipped with Mac OS Monterey.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
# Class to automatically fetch the last translations from Web Translate It
|
3
4
|
# for every page requested.
|
4
5
|
# This can be used as a rack middleware.
|
@@ -8,6 +9,7 @@ module WebTranslateIt
|
|
8
9
|
# config.middleware.use "WebTranslateIt::AutoFetch"
|
9
10
|
#
|
10
11
|
class AutoFetch
|
12
|
+
|
11
13
|
def initialize(app)
|
12
14
|
@app = app
|
13
15
|
end
|
@@ -27,5 +29,7 @@ module WebTranslateIt
|
|
27
29
|
def valid_request?(env)
|
28
30
|
env['PATH_INFO'] !~ /\.(js|css|jpeg|jpg|gif|png|woff)$/
|
29
31
|
end
|
32
|
+
|
30
33
|
end
|
34
|
+
|
31
35
|
end
|
@@ -1,31 +1,33 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
class CommandLine # rubocop:todo Metrics/ClassLength
|
4
|
+
|
3
5
|
require 'fileutils'
|
4
6
|
require 'set'
|
5
7
|
attr_accessor :configuration, :global_options, :command_options, :parameters
|
6
8
|
|
7
|
-
def initialize(command, command_options,
|
9
|
+
def initialize(command, command_options, _global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
|
8
10
|
self.command_options = command_options
|
9
11
|
self.parameters = parameters
|
10
12
|
unless command == 'init'
|
11
13
|
message = case command
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
when 'pull'
|
15
|
+
'Pulling files'
|
16
|
+
when 'push'
|
17
|
+
'Pushing files'
|
18
|
+
when 'add'
|
19
|
+
'Creating master files'
|
20
|
+
when 'rm'
|
21
|
+
'Deleting files'
|
22
|
+
when 'mv'
|
23
|
+
'Moving files'
|
24
|
+
when 'addlocale'
|
25
|
+
'Adding locale'
|
26
|
+
when 'rmlocale'
|
27
|
+
'Deleting locale'
|
28
|
+
else
|
29
|
+
'Gathering information'
|
30
|
+
end
|
29
31
|
throb do
|
30
32
|
print " #{message}"
|
31
33
|
self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path)
|
@@ -107,10 +109,10 @@ module WebTranslateIt
|
|
107
109
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
108
110
|
fetch_locales_to_push(configuration).each do |locale|
|
109
111
|
files = if parameters.any?
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
configuration.files.find_all { |file| parameters.include?(file.file_path) }.sort { |a, b| a.file_path <=> b.file_path }
|
113
|
+
else
|
114
|
+
configuration.files.find_all { |file| file.locale == locale }.sort { |a, b| a.file_path <=> b.file_path }
|
115
|
+
end
|
114
116
|
if files.empty?
|
115
117
|
puts "Couldn't find any local files registered on WebTranslateIt to push."
|
116
118
|
else
|
@@ -295,10 +297,10 @@ module WebTranslateIt
|
|
295
297
|
end
|
296
298
|
FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
|
297
299
|
project = if RUBY_VERSION >= '3.1'
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
300
|
+
YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
|
301
|
+
else
|
302
|
+
YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
303
|
+
end
|
302
304
|
project_info = project['project']
|
303
305
|
if File.exist?(path) && !File.writable?(path)
|
304
306
|
puts StringUtil.failure("Error: `#{path}` file is not writable.")
|
@@ -470,5 +472,7 @@ module WebTranslateIt
|
|
470
472
|
puts "\r\e[0G#\e[?25h"
|
471
473
|
end
|
472
474
|
end
|
475
|
+
|
473
476
|
end
|
477
|
+
|
474
478
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
# Handles the configuration of your project, both via the the configuration file
|
3
4
|
# and via the API.
|
4
5
|
# Implementation example, assuming you have a valid .wti file:
|
@@ -6,6 +7,7 @@ module WebTranslateIt
|
|
6
7
|
# configuration = WebTranslateIt::Configuration.new
|
7
8
|
#
|
8
9
|
class Configuration
|
10
|
+
|
9
11
|
require 'yaml'
|
10
12
|
require 'fileutils'
|
11
13
|
require 'erb'
|
@@ -24,10 +26,10 @@ module WebTranslateIt
|
|
24
26
|
self.after_push = configuration['after_push']
|
25
27
|
self.ignore_files = configuration['ignore_files']
|
26
28
|
project_info = if RUBY_VERSION >= '3.1.0'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
|
30
|
+
else
|
31
|
+
YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
32
|
+
end
|
31
33
|
set_locales_to_ignore(configuration)
|
32
34
|
set_locales_needed(configuration)
|
33
35
|
set_files(project_info['project'])
|
@@ -116,5 +118,7 @@ module WebTranslateIt
|
|
116
118
|
def parse_erb_in_configuration
|
117
119
|
ERB.new(File.read(File.expand_path(path_to_config_file, path))).result
|
118
120
|
end
|
121
|
+
|
119
122
|
end
|
123
|
+
|
120
124
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'English'
|
2
2
|
module WebTranslateIt
|
3
|
+
|
3
4
|
class Project
|
5
|
+
|
4
6
|
def self.fetch_info(api_key) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
5
7
|
success = true
|
6
8
|
tries ||= 3
|
@@ -56,7 +58,7 @@ module WebTranslateIt
|
|
56
58
|
begin
|
57
59
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/locales")
|
58
60
|
WebTranslateIt::Util.add_fields(request)
|
59
|
-
request.set_form_data({
|
61
|
+
request.set_form_data({'id' => locale_code}, ';')
|
60
62
|
Util.handle_response(Connection.http_connection.request(request), true)
|
61
63
|
rescue Timeout::Error
|
62
64
|
puts 'Request timeout. Will retry in 5 seconds.'
|
@@ -88,5 +90,7 @@ module WebTranslateIt
|
|
88
90
|
end
|
89
91
|
success
|
90
92
|
end
|
93
|
+
|
91
94
|
end
|
95
|
+
|
92
96
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
class String # rubocop:todo Metrics/ClassLength
|
4
|
+
|
3
5
|
require 'multi_json'
|
4
6
|
|
5
7
|
attr_accessor :id, :key, :plural, :type, :dev_comment, :word_count, :status, :category, :labels, :file,
|
@@ -265,7 +267,7 @@ module WebTranslateIt
|
|
265
267
|
success
|
266
268
|
end
|
267
269
|
|
268
|
-
def to_json(with_translations = false) # rubocop:todo Metrics/AbcSize
|
270
|
+
def to_json(with_translations = false) # rubocop:todo Metrics/AbcSize
|
269
271
|
hash = {
|
270
272
|
'id' => id,
|
271
273
|
'key' => key,
|
@@ -278,12 +280,14 @@ module WebTranslateIt
|
|
278
280
|
'file' => file
|
279
281
|
}
|
280
282
|
if translations.any? && with_translations
|
281
|
-
hash.update({
|
283
|
+
hash.update({'translations' => []})
|
282
284
|
translations.each do |translation|
|
283
285
|
hash['translations'].push(translation.to_hash)
|
284
286
|
end
|
285
287
|
end
|
286
288
|
MultiJson.dump(hash)
|
287
289
|
end
|
290
|
+
|
288
291
|
end
|
292
|
+
|
289
293
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
class Term # rubocop:todo Metrics/ClassLength
|
4
|
+
|
3
5
|
require 'net/https'
|
4
6
|
require 'multi_json'
|
5
7
|
|
@@ -255,19 +257,21 @@ module WebTranslateIt
|
|
255
257
|
success
|
256
258
|
end
|
257
259
|
|
258
|
-
def to_json(with_translations = false)
|
260
|
+
def to_json(with_translations = false)
|
259
261
|
hash = {
|
260
262
|
'id' => id,
|
261
263
|
'text' => text,
|
262
264
|
'description' => description
|
263
265
|
}
|
264
266
|
if translations.any? && with_translations
|
265
|
-
hash.update({
|
267
|
+
hash.update({'translations' => []})
|
266
268
|
translations.each do |translation|
|
267
269
|
hash['translations'].push(translation.to_hash)
|
268
270
|
end
|
269
271
|
end
|
270
272
|
MultiJson.dump(hash)
|
271
273
|
end
|
274
|
+
|
272
275
|
end
|
276
|
+
|
273
277
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
# A TranslationFile is the representation of a master language file
|
3
4
|
# on Web Translate It.
|
4
5
|
#
|
@@ -6,6 +7,7 @@ module WebTranslateIt
|
|
6
7
|
# If you pass a Locale to the master language file you will be able to
|
7
8
|
# manipulate a _target_ language file.
|
8
9
|
class TranslationFile # rubocop:todo Metrics/ClassLength
|
10
|
+
|
9
11
|
require 'net/https'
|
10
12
|
require 'net/http/post/multipart'
|
11
13
|
require 'time'
|
@@ -99,7 +101,7 @@ module WebTranslateIt
|
|
99
101
|
if File.exist?(file_path)
|
100
102
|
if force || (remote_checksum != local_checksum)
|
101
103
|
File.open(file_path) do |file|
|
102
|
-
params = {
|
104
|
+
params = {'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes}
|
103
105
|
params['name'] = destination_path unless destination_path.nil?
|
104
106
|
params['rename_others'] = rename_others
|
105
107
|
request = Net::HTTP::Put::Multipart.new(api_url, params)
|
@@ -150,7 +152,7 @@ module WebTranslateIt
|
|
150
152
|
display.push "#{StringUtil.checksumify(local_checksum.to_s)}..[ ]"
|
151
153
|
if File.exist?(file_path)
|
152
154
|
File.open(file_path) do |file|
|
153
|
-
request = Net::HTTP::Post::Multipart.new(api_url_for_create, {
|
155
|
+
request = Net::HTTP::Post::Multipart.new(api_url_for_create, {'name' => file_path, 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority})
|
154
156
|
WebTranslateIt::Util.add_fields(request)
|
155
157
|
display.push Util.handle_response(http_connection.request(request))
|
156
158
|
puts ArrayUtil.to_columns(display)
|
@@ -239,5 +241,7 @@ module WebTranslateIt
|
|
239
241
|
''
|
240
242
|
end
|
241
243
|
end
|
244
|
+
|
242
245
|
end
|
246
|
+
|
243
247
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class HashUtil
|
2
|
+
|
2
3
|
def self.to_params(hash) # rubocop:todo Metrics/MethodLength
|
3
4
|
params = ''
|
4
5
|
stack = []
|
@@ -24,9 +25,11 @@ class HashUtil
|
|
24
25
|
params.chop! # trailing &
|
25
26
|
params
|
26
27
|
end
|
28
|
+
|
27
29
|
end
|
28
30
|
|
29
31
|
class Hash
|
32
|
+
|
30
33
|
# Destructively convert all keys to strings.
|
31
34
|
def stringify_keys!
|
32
35
|
keys.each do |key|
|
@@ -34,4 +37,5 @@ class Hash
|
|
34
37
|
end
|
35
38
|
self
|
36
39
|
end
|
40
|
+
|
37
41
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class StringUtil
|
2
|
+
|
2
3
|
def self.backward_truncate(str)
|
3
4
|
return '...' << str[str.length - 50 + 3..str.length] if str.length > 50
|
4
5
|
|
@@ -26,4 +27,5 @@ class StringUtil
|
|
26
27
|
def self.important(str)
|
27
28
|
WebTranslateIt::Util.can_display_colors? ? "\e[1m#{str}\e[0m" : str
|
28
29
|
end
|
30
|
+
|
29
31
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module WebTranslateIt
|
2
|
+
|
2
3
|
# A few useful functions
|
3
4
|
class Util
|
5
|
+
|
4
6
|
require 'multi_json'
|
5
7
|
|
6
8
|
# Return a string representing the gem version
|
@@ -41,8 +43,7 @@ module WebTranslateIt
|
|
41
43
|
# rubocop:enable Metrics/PerceivedComplexity
|
42
44
|
|
43
45
|
def self.add_fields(request)
|
44
|
-
request.add_field('
|
45
|
-
request.add_field('X-Client-Version', version)
|
46
|
+
request.add_field('User-Agent', "wti v#{version}")
|
46
47
|
request.add_field('Content-Type', 'application/json')
|
47
48
|
end
|
48
49
|
|
@@ -51,26 +52,26 @@ module WebTranslateIt
|
|
51
52
|
|
52
53
|
def self.ask_yes_no(question, default = nil) # rubocop:todo Metrics/MethodLength
|
53
54
|
qstr = case default
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
when nil
|
56
|
+
'yn'
|
57
|
+
when true
|
58
|
+
'Yn'
|
59
|
+
else
|
60
|
+
'yN'
|
61
|
+
end
|
61
62
|
|
62
63
|
result = nil
|
63
64
|
|
64
65
|
while result.nil?
|
65
66
|
result = ask("#{question} [#{qstr}]")
|
66
67
|
result = case result
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
when /^[Yy].*/
|
69
|
+
true
|
70
|
+
when /^[Nn].*/
|
71
|
+
false
|
72
|
+
when '', nil
|
73
|
+
default
|
74
|
+
end
|
74
75
|
end
|
75
76
|
|
76
77
|
result
|
@@ -96,5 +97,7 @@ module WebTranslateIt
|
|
96
97
|
def self.can_display_colors?
|
97
98
|
!RUBY_PLATFORM.downcase.include?('mingw32')
|
98
99
|
end
|
100
|
+
|
99
101
|
end
|
102
|
+
|
100
103
|
end
|
data/lib/web_translate_it.rb
CHANGED
@@ -16,6 +16,7 @@ require 'web_translate_it/project'
|
|
16
16
|
require 'English'
|
17
17
|
|
18
18
|
module WebTranslateIt
|
19
|
+
|
19
20
|
def self.fetch_translations # rubocop:todo Metrics/AbcSize
|
20
21
|
config = Configuration.new
|
21
22
|
locale = I18n.locale.to_s
|
@@ -28,4 +29,5 @@ module WebTranslateIt
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
31
33
|
end
|
data/readme.md
CHANGED
@@ -217,7 +217,7 @@ There are 4 hooks:
|
|
217
217
|
* `before_push`
|
218
218
|
* `after_push`
|
219
219
|
|
220
|
-
Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/
|
220
|
+
Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/main/examples/.wti#L21-L28) file for implementation.
|
221
221
|
|
222
222
|
## Exit codes
|
223
223
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_translate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Briere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -52,76 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard-rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 2.6.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 2.6.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
55
|
description: A Command Line Interface tool to push and pull language files to WebTranslateIt.com.
|
126
56
|
email: support@webtranslateit.com
|
127
57
|
executables:
|
@@ -180,11 +110,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
110
|
version: '2.6'
|
181
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
112
|
requirements:
|
183
|
-
- - "
|
113
|
+
- - ">="
|
184
114
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
115
|
+
version: '0'
|
186
116
|
requirements: []
|
187
|
-
rubygems_version: 3.3.
|
117
|
+
rubygems_version: 3.3.21
|
188
118
|
signing_key:
|
189
119
|
specification_version: 4
|
190
120
|
summary: A CLI tool to sync locale files with WebTranslateIt.com.
|