i18n-migrations 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13e2d9e3d4aa1ec30fa0584c624d96388fac4aa31e11a6705fa61c39f8ff9a6c
4
- data.tar.gz: a88a38c024f92727aaf57bff6950ae5a9d3665d9b86cd26a382cecdb13ec085e
3
+ metadata.gz: 0b8b7ac35780cf4cf39728ec9c140324a1df5b21868fbeff0d8082eb2b612e1e
4
+ data.tar.gz: c8c7f5867dc9d8485d527d0b9286a3925eaa69eea40e82ae5ee0a6ca2240f89e
5
5
  SHA512:
6
- metadata.gz: e9eec7ad2d69e380a74b03b26e95be54c9bfb5d59f69cc1115f457f0fbecd0c6f0cec334d2f92b8970550cf42e2e0e9a46818d6b69a2bb7bfbb2f7bd086320ea
7
- data.tar.gz: be7bac66cd9be3219e930e9568762c1ffe07b313d7712ab4f7ce424d85625c4770b35bbf749d69dd528dd656c29ab1b615f1cd337ef612d9e32221ec2d3716dc
6
+ metadata.gz: 3ebecbc35805df21ae0db20ac14931517fb6e55126a3a3b853d1486ab59264f38ea58e66077f665ed226b66afb828544866dae8810fd6c6c93c5ce52f9367d89
7
+ data.tar.gz: 5a449c05dd1f4d2a2a5492cf0e0ff6fb016344fc1db735e51eaeff4bc9466f62cfb1979c381ad8d35fa503e58d8964fbe044438e9ec1ac51a09fb1483d4356bc
@@ -6,8 +6,8 @@ module I18n
6
6
  class CrowdTranslateBackend
7
7
  attr_reader :client
8
8
 
9
- def initialize
10
- @client = CrowdTranslateClient.new
9
+ def initialize(client: CrowdTranslateClient.new)
10
+ @client = client
11
11
  end
12
12
 
13
13
  def pull(locale)
@@ -15,22 +15,56 @@ module I18n
15
15
  locale.migrate!
16
16
  end
17
17
 
18
- def push(locale, force = false)
19
- raise "CrowdTranslate does not support -f flag yet" if force
18
+ def push(locale, force: false)
19
+ if force
20
+ force_push(locale)
21
+ end
20
22
 
21
23
  # do this just once
22
24
  unless @migrations_synced
23
- @client.sync_migrations(locale.migrations)
25
+ sync_migrations(locale.migrations)
24
26
  @migrations_synced = true
25
27
  end
26
28
  pull(locale)
27
29
  end
28
30
 
31
+ # this will replace everything about a locale, it will create a locale that does not yet exist
32
+ def force_push(locale)
33
+ data, notes = locale.read_data_and_notes(parse: false)
34
+ client.put_locale(locale.name,
35
+ name: locale.name,
36
+ yaml_file: data,
37
+ yaml_notes_file: notes)
38
+
39
+ end
40
+
29
41
  def pull_from_crowd_translate(locale)
30
- data = @client.get_locale_file(locale.name)
42
+ data = client.get_locale_file(locale.name)
31
43
  locale.write_raw_data("#{locale.name}.yml", data)
32
44
  locale.write_remote_version(YAML::load(data)[locale.name])
33
45
  end
46
+
47
+ def sync_migrations(migrations)
48
+ local_versions = migrations.all_versions
49
+ remote_versions = client.get_migration_versions
50
+
51
+ if (extra_versions = remote_versions - local_versions).present?
52
+ raise("You may not upload migrations to the server because it has migrations not found locally: " +
53
+ "#{extra_versions.join(', ')}")
54
+ end
55
+
56
+ if (versions_to_add = local_versions - remote_versions).present?
57
+ versions_to_add.each do |version|
58
+ begin
59
+ client.put_migration(version: version, ruby_file: migrations.get_migration(version: version))
60
+ rescue
61
+ puts "There was an error updating migration:".red
62
+ puts " #{migrations.migration_file(version: version)}".bold
63
+ raise
64
+ end
65
+ end
66
+ end
67
+ end
34
68
  end
35
69
  end
36
70
  end
@@ -16,31 +16,21 @@ module I18n
16
16
  )
17
17
  end
18
18
 
19
- def sync_migrations(migrations)
20
- local_versions = migrations.all_versions
21
- remote_versions = JSON.parse(get('migrations.json'))
19
+ def get_locale_file(locale_code)
20
+ get("locales/#{locale_code}.yml")
21
+ end
22
22
 
23
- if (extra_versions = remote_versions - local_versions).present?
24
- raise("You may not upload migrations to the server because it has migrations not found locally: " +
25
- "#{extra_versions.join(', ')}")
26
- end
23
+ def get_migration_versions
24
+ JSON.parse(get('migrations.json'))
25
+ end
27
26
 
28
- if (versions_to_add = local_versions - remote_versions).present?
29
- versions_to_add.each do |version|
30
- begin
31
- put("migrations/#{version}.json",
32
- migration: { ruby_file: migrations.get_migration(version: version) })
33
- rescue
34
- puts "There was an error updating migration:".red
35
- puts " #{migrations.migration_file(version: version)}".bold
36
- raise
37
- end
38
- end
39
- end
27
+ def put_migration(version:, ruby_file:)
28
+ put("migrations/#{version}.json", migration: { ruby_file: ruby_file })
40
29
  end
41
30
 
42
- def get_locale_file(locale_code)
43
- get("locales/#{locale_code}.yml")
31
+ def put_locale(locale_code, name:, yaml_file:, yaml_notes_file:)
32
+ put("locales/#{locale_code}",
33
+ locale: { name: name, yaml_file: yaml_file, yaml_notes_file: yaml_notes_file })
44
34
  end
45
35
 
46
36
  private
@@ -16,7 +16,7 @@ module I18n
16
16
  locale.migrate!
17
17
  end
18
18
 
19
- def push(locale, force = false)
19
+ def push(locale, force: false)
20
20
  return if locale.main_locale?
21
21
 
22
22
  sheet = get_google_spreadsheet(locale.name)
@@ -106,13 +106,13 @@ module I18n
106
106
  read_versions(read_data).last
107
107
  end
108
108
 
109
- def read_data
110
- read_from_file("#{@name}.yml")
109
+ def read_data(parse: true)
110
+ read_from_file("#{@name}.yml", parse: parse)
111
111
  end
112
112
 
113
- def read_data_and_notes
114
- data = read_data
115
- notes = main_locale? ? {} : read_from_file("../#{@name}_notes.yml")
113
+ def read_data_and_notes(parse: true)
114
+ data = read_data(parse: parse)
115
+ notes = main_locale? ? (parse ? {} : '--- {}') : read_from_file("../#{@name}_notes.yml", parse: parse)
116
116
  [data, notes]
117
117
  end
118
118
 
@@ -185,11 +185,14 @@ module I18n
185
185
  (data['VERSION'] && data['VERSION'].split("\n")) || []
186
186
  end
187
187
 
188
- def read_from_file(filename)
188
+ def read_from_file(filename, parse: true)
189
189
  filename = File.join(@locales_dir, filename)
190
190
  begin
191
+ contents = File.read(filename)
192
+ return contents unless parse
193
+
191
194
  hash = {}
192
- add_to_hash(hash, YAML.load(File.read(filename))[@name.to_s])
195
+ add_to_hash(hash, YAML.load(contents)[@name.to_s])
193
196
  hash
194
197
  rescue
195
198
  puts "Error loading #{filename}"
@@ -79,7 +79,7 @@ end
79
79
 
80
80
  def push(locale_or_all, force = false)
81
81
  each_locale(locale_or_all, concurrency: config.push_concurrency) do |locale|
82
- backend.push(locale, force)
82
+ backend.push(locale, force: force)
83
83
  wait
84
84
  end
85
85
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Migrations
3
- VERSION = "1.2.3"
3
+ VERSION = "1.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Lightsmith