i18n-migrations 2.0.1 → 2.0.6
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/README.md +8 -17
- data/bin/i18n-migrate +57 -52
- data/lib/i18n/migrations/backends/crowd_translate_backend.rb +1 -3
- data/lib/i18n/migrations/backends/crowd_translate_client.rb +21 -13
- data/lib/i18n/migrations/locale.rb +1 -1
- data/lib/i18n/migrations/metadata.rb +2 -0
- data/lib/i18n/migrations/migration_factory.rb +21 -10
- data/lib/i18n/migrations/migrator.rb +25 -4
- data/lib/i18n/migrations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 274cc2afe088dd6f3222a02373b5e7cffe919a49aa927a837bc73170f06ad4e9
|
4
|
+
data.tar.gz: 15bae7e096587080bab7333d8ec2e6cb5e6c94e664ade5f62b67dc5fed284673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b346021869b4ac4c8fb89c0798589bd9102380181d6c5b0c2bce095a5bbf249c1d1447227714dff46fa4534e7fdc90688ef8d1ebbc8a6e23b72dd370390941c
|
7
|
+
data.tar.gz: 444444d2a9ee2f2e0fa60330a1505f01746b7e1eadd6e8f2dc662f10c22f94ead1ad5a7b91d623d4536177b5c15d2a6667b77c9b3977a8bf7fe4bad45451270a
|
data/README.md
CHANGED
@@ -47,20 +47,10 @@ Let's imagine that your config file look like this:
|
|
47
47
|
|
48
48
|
In your project file, you should then have all your english terms in ```config/locales/en.yml```
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
1. Translate all the terms w/ google translate
|
53
|
-
|
54
|
-
> i18n-migrate new_locale es
|
55
|
-
|
56
|
-
2. Create a spreadsheet that is world editable (for now). You'll want to add the link to it to your config file. It should look like:
|
57
|
-
|
58
|
-
| key | en | es | notes |
|
59
|
-
|
60
|
-
2. Push this to your google spreadsheet (the -f means it won't try to pull first)
|
61
|
-
|
62
|
-
> i18n-migrate push -f es
|
50
|
+
You can:
|
63
51
|
|
52
|
+
* [Create a new locale](https://github.com/transparentclassroom/i18n-migrations/wiki/Create-a-new-locale-(language))
|
53
|
+
* [Add a migration](https://github.com/transparentclassroom/i18n-migrations/wiki/Add-a-migration)
|
64
54
|
|
65
55
|
## Development
|
66
56
|
|
@@ -71,8 +61,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
71
61
|
## Contributing
|
72
62
|
|
73
63
|
1. Fork it ( https://github.com/[my-github-username]/i18n-migrations/fork )
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
64
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
1. Make sure tests are passing (`rake`)
|
66
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
1. Create a new Pull Request
|
78
69
|
|
data/bin/i18n-migrate
CHANGED
@@ -10,59 +10,60 @@ def extract_option(name)
|
|
10
10
|
!!ARGV.delete(name)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
13
|
+
begin
|
14
|
+
case ARGV.shift
|
15
|
+
when 'setup'
|
16
|
+
puts 'Where should we create a default config file? [.]'
|
17
|
+
dir = gets.chomp
|
18
|
+
dir = dir == '' ? '.' : dir
|
19
|
+
file = I18n::Migrations::Config.copy_default_config_file(dir)
|
20
|
+
|
21
|
+
puts 'You will need to configure this file before you can get going.'
|
22
|
+
puts File.expand_path(file)
|
23
|
+
|
24
|
+
when 'new'
|
25
|
+
name = ARGV.shift
|
26
|
+
if name
|
27
|
+
migrator.new_migration name
|
28
|
+
else
|
29
|
+
STDERR.puts 'Usage: im new [name]'
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
when 'migrate'
|
34
|
+
migrator.migrate(ARGV[0] || 'all')
|
35
|
+
|
36
|
+
when 'rollback'
|
37
|
+
migrator.rollback(ARGV[0] || 'all')
|
38
|
+
|
39
|
+
when 'redo'
|
40
|
+
migrator.rollback(ARGV[0] || 'all')
|
41
|
+
migrator.migrate(ARGV[0] || 'all')
|
42
|
+
|
43
|
+
when 'pull'
|
44
|
+
migrator.pull(ARGV[0] || 'all')
|
45
|
+
|
46
|
+
when 'push'
|
47
|
+
force = extract_option('-f')
|
48
|
+
migrator.push(ARGV[0] || 'all', force)
|
49
|
+
|
50
|
+
when 'validate'
|
51
|
+
migrator.validate(ARGV[0] || 'all')
|
52
|
+
|
53
|
+
when 'new_locale'
|
54
|
+
locale = ARGV.shift
|
55
|
+
if locale
|
56
|
+
migrator.new_locale(locale)
|
57
|
+
else
|
58
|
+
STDERR.puts 'Usage: im new_locale [name]'
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
|
62
|
+
when 'version'
|
63
|
+
migrator.version
|
44
64
|
|
45
|
-
when 'push'
|
46
|
-
force = extract_option('-f')
|
47
|
-
migrator.push(ARGV[0] || 'all', force)
|
48
|
-
|
49
|
-
when 'validate'
|
50
|
-
migrator.validate(ARGV[0] || 'all')
|
51
|
-
|
52
|
-
when 'new_locale'
|
53
|
-
locale = ARGV.shift
|
54
|
-
if locale
|
55
|
-
migrator.new_locale(locale)
|
56
65
|
else
|
57
|
-
|
58
|
-
exit 1
|
59
|
-
end
|
60
|
-
|
61
|
-
when 'version'
|
62
|
-
migrator.version
|
63
|
-
|
64
|
-
else
|
65
|
-
puts <<-USAGE
|
66
|
+
puts <<-USAGE
|
66
67
|
Usage: i18n-migrate [command]
|
67
68
|
|
68
69
|
Commands:
|
@@ -78,5 +79,9 @@ Commands:
|
|
78
79
|
version - Print version of locales.
|
79
80
|
|
80
81
|
i18n-migrations version #{I18n::Migrations::VERSION}
|
81
|
-
|
82
|
+
USAGE
|
83
|
+
end
|
84
|
+
rescue Exception
|
85
|
+
puts "Error\n#{$!.message}".red
|
86
|
+
exit 1
|
82
87
|
end
|
@@ -53,9 +53,7 @@ module I18n
|
|
53
53
|
begin
|
54
54
|
client.put_migration(version: version, ruby_file: migrations.get_migration(version: version))
|
55
55
|
rescue
|
56
|
-
|
57
|
-
puts " #{migrations.migration_file(version: version)}".bold
|
58
|
-
raise
|
56
|
+
raise CrowdTranslateError, "... while updating migration: #{migrations.migration_file(version: version)}\n#{$!.message}"
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
@@ -4,16 +4,16 @@ require 'active_support/core_ext/object'
|
|
4
4
|
module I18n
|
5
5
|
module Migrations
|
6
6
|
module Backends
|
7
|
+
class CrowdTranslateError < StandardError
|
8
|
+
end
|
9
|
+
|
7
10
|
class CrowdTranslateClient
|
8
11
|
def initialize
|
9
12
|
token = ENV['CROWD_TRANSLATE_API_TOKEN']
|
10
13
|
raise("You must define CROWD_TRANSLATE_API_TOKEN in order to talk to Crowd Translate") unless token.present?
|
11
14
|
|
12
|
-
server = ENV['CROWD_TRANSLATE_SERVER'] || 'https://crowd-translate.herokuapp.com'
|
13
|
-
@faraday = Faraday.new(
|
14
|
-
url: "#{server}/api/v1",
|
15
|
-
headers: { 'X-CrowdTranslateApiToken' => token },
|
16
|
-
)
|
15
|
+
@server = ENV['CROWD_TRANSLATE_SERVER'] || 'https://crowd-translate.herokuapp.com'
|
16
|
+
@faraday = Faraday.new(url: base_url, headers: { 'X-CrowdTranslateApiToken' => token })
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_locale_file(locale_code)
|
@@ -37,26 +37,34 @@ module I18n
|
|
37
37
|
|
38
38
|
def get(path)
|
39
39
|
puts "GET #{path}".bold
|
40
|
-
parse_response @faraday.get
|
40
|
+
parse_response 'GET', path, @faraday.get(path)
|
41
41
|
end
|
42
42
|
|
43
43
|
def put(path, params = {})
|
44
44
|
puts "PUT #{path} #{params.to_s[0..50]}#{'...' if params.to_s.length > 50}".bold
|
45
|
-
parse_response @faraday.put
|
45
|
+
parse_response 'PUT', path, @faraday.put(path, params)
|
46
46
|
end
|
47
47
|
|
48
|
-
def parse_response(response)
|
48
|
+
def parse_response(method, path, response)
|
49
49
|
if response.success?
|
50
50
|
response.body
|
51
51
|
else
|
52
|
-
error =
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
error = if response.status == 503
|
53
|
+
'Server timed out - your request may have succeed, check the server for more details'
|
54
|
+
else
|
55
|
+
begin
|
56
|
+
JSON.parse(response.body)['error']
|
57
|
+
rescue
|
58
|
+
response.body
|
59
|
+
end
|
56
60
|
end
|
57
|
-
raise error
|
61
|
+
raise CrowdTranslateError, "... while calling #{method} #{File.join(base_url, path)}\n#{error}"
|
58
62
|
end
|
59
63
|
end
|
64
|
+
|
65
|
+
def base_url
|
66
|
+
"#{@server}/api/v1"
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -27,15 +27,15 @@ module I18n
|
|
27
27
|
raise("Can't parse version: #{version}") unless version =~ /^(\d{12})_(.*)/
|
28
28
|
migration_class_name = "#{$2.camelcase}#{$1}"
|
29
29
|
|
30
|
-
translations = Translations.new(data: data, metadata: metadata)
|
30
|
+
translations = Translations.new(locale_code: locale, data: data, metadata: metadata)
|
31
31
|
migration = begin
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
migration_class_name.constantize.new(locale_code: locale,
|
33
|
+
translations: translations,
|
34
|
+
dictionary: dictionary,
|
35
|
+
direction: direction)
|
36
|
+
rescue
|
37
|
+
raise "Couldn't load migration #{migration_class_name} in #{filename}"
|
38
|
+
end
|
39
39
|
|
40
40
|
migration.change
|
41
41
|
end
|
@@ -44,8 +44,8 @@ module I18n
|
|
44
44
|
# data = all keys -> all translations in this locale
|
45
45
|
# metadata = some keys -> metadata about the translation in this locale
|
46
46
|
class Translations
|
47
|
-
def initialize(data:, metadata:)
|
48
|
-
@data, @metadata = data, metadata
|
47
|
+
def initialize(locale_code:, data:, metadata:)
|
48
|
+
@locale_code, @data, @metadata = locale_code, data, metadata
|
49
49
|
end
|
50
50
|
|
51
51
|
def get_term(key)
|
@@ -63,6 +63,17 @@ module I18n
|
|
63
63
|
@metadata[key].errors = errors
|
64
64
|
@metadata[key].notes = nil
|
65
65
|
@metadata[key].autotranslated = autotranslated
|
66
|
+
if errors.present?
|
67
|
+
puts [
|
68
|
+
"=" * 100,
|
69
|
+
"#{@locale_code}: #{key}",
|
70
|
+
value,
|
71
|
+
errors.map { |e| "Error: #{e}".red }.join("\n"),
|
72
|
+
"=" * 100,
|
73
|
+
].compact.join("\n")
|
74
|
+
# puts ["Error with #{@locale_code}: #{key}: \n #{errors.join("\n ")}".red,
|
75
|
+
# value].compact.join("\n")
|
76
|
+
end
|
66
77
|
end
|
67
78
|
|
68
79
|
def delete_term(key)
|
@@ -72,7 +72,7 @@ end
|
|
72
72
|
|
73
73
|
def pull(locale_or_all)
|
74
74
|
each_locale(locale_or_all) do |locale|
|
75
|
-
next if locale.main_locale?
|
75
|
+
# next if locale.main_locale?
|
76
76
|
backend.pull(locale)
|
77
77
|
end
|
78
78
|
end
|
@@ -104,23 +104,44 @@ end
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
private def report_locale_on_error(locale, &block)
|
108
|
+
begin
|
109
|
+
block.call locale
|
110
|
+
rescue Backends::CrowdTranslateError
|
111
|
+
puts "Error\n... while working with #{locale.name}\n#{$!.message}".red
|
112
|
+
# we want a readable error for our users, and the error happened in an external system,
|
113
|
+
# so don't give them a stack trace
|
114
|
+
rescue
|
115
|
+
puts "Error\n... while working with #{locale.name}\n#{$!.message}".red
|
116
|
+
raise
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
107
120
|
private def each_locale(name = 'all',
|
108
121
|
async: true,
|
109
|
-
concurrency: config.concurrency
|
122
|
+
concurrency: config.concurrency,
|
123
|
+
&block)
|
110
124
|
locale_names = name == 'all' ? all_locale_names : [name]
|
111
125
|
|
126
|
+
# do the main locale first, so we aren't updating it and reading it for other locales at the same time
|
127
|
+
if locale_names.include?(config.main_locale)
|
128
|
+
locale_names -= [config.main_locale]
|
129
|
+
|
130
|
+
report_locale_on_error(locale_for(config.main_locale), &block)
|
131
|
+
end
|
132
|
+
|
112
133
|
if async
|
113
134
|
puts "Using #{concurrency} concurrency"
|
114
135
|
locale_names.each_slice(concurrency) do |some_locale_names|
|
115
136
|
threads = some_locale_names.map do |l|
|
116
137
|
locale = locale_for(l)
|
117
|
-
Thread.new {
|
138
|
+
Thread.new { report_locale_on_error(locale, &block) }
|
118
139
|
end
|
119
140
|
threads.each(&:join)
|
120
141
|
end
|
121
142
|
else
|
122
143
|
locale_names.each do |l|
|
123
|
-
|
144
|
+
report_locale_on_error(locale_for(l), &block)
|
124
145
|
end
|
125
146
|
end
|
126
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Lightsmith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|