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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 053d7282ee9ff71a5208ab798f26bc52545f0a6efea6122371e6a8fa1ab088d5
4
- data.tar.gz: 92271dac44fff97ed25c200bd33ff0fbd000cdc391b54480a409763f87c4d43d
3
+ metadata.gz: 274cc2afe088dd6f3222a02373b5e7cffe919a49aa927a837bc73170f06ad4e9
4
+ data.tar.gz: 15bae7e096587080bab7333d8ec2e6cb5e6c94e664ade5f62b67dc5fed284673
5
5
  SHA512:
6
- metadata.gz: 67e99b9e00a2cfc83105c813e5bcd09aecdd89fb2314e7f8490d82bc3e730b098991bddf7b2ddfb0ed554a912922be2b61068399141dfe81b435ce92fffa8fef
7
- data.tar.gz: '039751914e92608313ff570365910ce05472124e582711b67bf55382412f333d6e51c83109a34aae91f8d1c0b5866282886cc57b69146196165587244993e010'
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
- To create a new locale (like es.yml):
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
- 2. Create your feature branch (`git checkout -b my-new-feature`)
75
- 3. Commit your changes (`git commit -am 'Add some feature'`)
76
- 4. Push to the branch (`git push origin my-new-feature`)
77
- 5. Create a new Pull Request
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
 
@@ -10,59 +10,60 @@ def extract_option(name)
10
10
  !!ARGV.delete(name)
11
11
  end
12
12
 
13
- case ARGV.shift
14
- when 'setup'
15
- puts 'Where should we create a default config file? [.]'
16
- dir = gets.chomp
17
- dir = dir == '' ? '.' : dir
18
- file = I18n::Migrations::Config.copy_default_config_file(dir)
19
-
20
- puts 'You will need to configure this file before you can get going.'
21
- puts File.expand_path(file)
22
-
23
- when 'new'
24
- name = ARGV.shift
25
- if name
26
- migrator.new_migration name
27
- else
28
- STDERR.puts 'Usage: im new [name]'
29
- exit 1
30
- end
31
-
32
- when 'migrate'
33
- migrator.migrate(ARGV[0] || 'all')
34
-
35
- when 'rollback'
36
- migrator.rollback(ARGV[0] || 'all')
37
-
38
- when 'redo'
39
- migrator.rollback(ARGV[0] || 'all')
40
- migrator.migrate(ARGV[0] || 'all')
41
-
42
- when 'pull'
43
- migrator.pull(ARGV[0] || 'all')
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
- STDERR.puts 'Usage: im new_locale [name]'
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
- USAGE
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
- puts "There was an error updating migration:".red
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 path
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 path, params
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 = begin
53
- JSON.parse(response.body)['error']
54
- rescue
55
- response.body
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
@@ -212,7 +212,7 @@ module I18n
212
212
  end
213
213
 
214
214
  def parse_yaml(string)
215
- YAML.load(string)
215
+ YAML.load(string) || {}
216
216
  end
217
217
 
218
218
  # flattens new_hash and adds it to hash
@@ -20,7 +20,9 @@ class Metadata
20
20
  end
21
21
 
22
22
  def delete(key)
23
+ metadatum = self[key]
23
24
  @hash.delete(key)
25
+ metadatum
24
26
  end
25
27
 
26
28
  def to_h
@@ -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
- 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
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 { yield locale }
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
- yield locale_for(l)
144
+ report_locale_on_error(locale_for(l), &block)
124
145
  end
125
146
  end
126
147
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Migrations
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.6"
4
4
  end
5
5
  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.1
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-03-18 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler