i18n-migrations 1.2.3 → 1.2.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/lib/i18n/migrations/backends/crowd_translate_backend.rb +40 -6
- data/lib/i18n/migrations/backends/crowd_translate_client.rb +11 -21
- data/lib/i18n/migrations/backends/google_spreadsheets_backend.rb +1 -1
- data/lib/i18n/migrations/locale.rb +10 -7
- data/lib/i18n/migrations/migrator.rb +1 -1
- data/lib/i18n/migrations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b8b7ac35780cf4cf39728ec9c140324a1df5b21868fbeff0d8082eb2b612e1e
|
4
|
+
data.tar.gz: c8c7f5867dc9d8485d527d0b9286a3925eaa69eea40e82ae5ee0a6ca2240f89e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
19
|
-
|
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
|
-
|
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 =
|
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
|
20
|
-
|
21
|
-
|
19
|
+
def get_locale_file(locale_code)
|
20
|
+
get("locales/#{locale_code}.yml")
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
def get_migration_versions
|
24
|
+
JSON.parse(get('migrations.json'))
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
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
|
43
|
-
|
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
|
@@ -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(
|
195
|
+
add_to_hash(hash, YAML.load(contents)[@name.to_s])
|
193
196
|
hash
|
194
197
|
rescue
|
195
198
|
puts "Error loading #{filename}"
|