phraseapp_updater 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +1 -1
- data/bin/phraseapp_updater +16 -3
- data/lib/phraseapp_updater.rb +86 -30
- data/lib/phraseapp_updater/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b4b5ca69acb3ee2e8aa1b40c1325872ac307c50
|
4
|
+
data.tar.gz: 0f1e8961e0e35908ab8c8094ee845a9d71c8badf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c04afe5d8a011e3f7d68872f82bfa7a67150c6868d29f2b7b2a0990647a9496a92165c1d44f7753ec72b59b4fd5649f0e93b41ca68c8041829f830033d3715
|
7
|
+
data.tar.gz: b6880095d635a3b72dade7bbe19ea363b6c1fb38db91cae84f230e307f34f9f7757e6b9a3bfdcdeeb208a36f3d8689705f5bc58211916bf1f68df44db5c60720
|
data/README.markdown
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/iknow/phraseapp_updater.svg?branch=master)](https://travis-ci.org/iknow/phraseapp_updater)
|
4
4
|
|
5
|
-
**Version** 0.1.
|
5
|
+
**Version** 0.1.4
|
6
6
|
|
7
7
|
This is a tool for merging PhraseApp locale data with locale data
|
8
8
|
committed in your project.
|
data/bin/phraseapp_updater
CHANGED
@@ -28,7 +28,7 @@ class PhraseAppUpdaterCLI < Thor
|
|
28
28
|
validate_writable_path!('store_phraseapp_originals_path', store_phraseapp_originals_path)
|
29
29
|
|
30
30
|
begin
|
31
|
-
result = PhraseAppUpdater.
|
31
|
+
result = PhraseAppUpdater.new(phraseapp_api_key, phraseapp_project_id).push(previous_locales_path, new_locales_path)
|
32
32
|
|
33
33
|
unless store_results_path.empty?
|
34
34
|
write_locale_files(store_results_path, result.resolved_files)
|
@@ -65,18 +65,31 @@ class PhraseAppUpdaterCLI < Thor
|
|
65
65
|
validate_writable_path!('destination_path', destination_path)
|
66
66
|
|
67
67
|
begin
|
68
|
-
files = PhraseAppUpdater.
|
68
|
+
files = PhraseAppUpdater.new(phraseapp_api_key, phraseapp_project_id).pull(fallback_path)
|
69
69
|
write_locale_files(destination_path, files)
|
70
70
|
rescue PhraseAppUpdater::PhraseAppAPI::BadAPIKeyError => e
|
71
71
|
puts "Bad PhraseApp API key."
|
72
72
|
rescue PhraseAppUpdater::PhraseAppAPI::BadProjectIDError => e
|
73
73
|
puts "Bad PhraseApp project ID: #{phraseapp_project_id}"
|
74
74
|
rescue StandardError => e
|
75
|
-
puts "Unknown error when
|
75
|
+
puts "Unknown error when pulling files"
|
76
76
|
raise e
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
desc "default", "Prints gem information"
|
81
|
+
option :version, aliases: [:v]
|
82
|
+
|
83
|
+
def default
|
84
|
+
if options[:v] || options[:version]
|
85
|
+
puts PhraseAppUpdater::VERSION
|
86
|
+
else
|
87
|
+
help
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
default_command :default
|
92
|
+
|
80
93
|
private
|
81
94
|
|
82
95
|
def load_phraseapp_credentials(options)
|
data/lib/phraseapp_updater.rb
CHANGED
@@ -9,12 +9,23 @@ require 'phraseapp_updater/yml_config_loader'
|
|
9
9
|
class PhraseAppUpdater
|
10
10
|
using IndexBy
|
11
11
|
|
12
|
-
def
|
13
|
-
phraseapp_api
|
14
|
-
|
12
|
+
def initialize(phraseapp_api_key, phraseapp_project_id)
|
13
|
+
@phraseapp_api = PhraseAppAPI.new(phraseapp_api_key, phraseapp_project_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_config(config_file_path)
|
17
|
+
YMLConfigLoader.new(config_file_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def push(previous_locales_path, new_locales_path)
|
21
|
+
phraseapp_locales = @phraseapp_api.download_locales
|
15
22
|
|
16
|
-
phraseapp_files
|
17
|
-
|
23
|
+
phraseapp_files = load_phraseapp_files(phraseapp_locales, false)
|
24
|
+
|
25
|
+
(previous_locale_files, new_locale_files) =
|
26
|
+
load_locale_files(previous_locales_path, new_locales_path)
|
27
|
+
|
28
|
+
validate_files!([phraseapp_files, previous_locale_files, new_locale_files])
|
18
29
|
|
19
30
|
new_locale_files = new_locale_files.index_by(&:name)
|
20
31
|
phraseapp_files = phraseapp_files.index_by(&:name)
|
@@ -45,39 +56,45 @@ class PhraseAppUpdater
|
|
45
56
|
file.parsed_content != phraseapp_files[file.name].parsed_content
|
46
57
|
end
|
47
58
|
|
48
|
-
upload_ids = phraseapp_api.upload_files(changed_files)
|
49
|
-
phraseapp_api.remove_keys_not_in_uploads(upload_ids)
|
59
|
+
upload_ids = @phraseapp_api.upload_files(changed_files)
|
60
|
+
@phraseapp_api.remove_keys_not_in_uploads(upload_ids)
|
50
61
|
|
51
62
|
puts "Uploading #{default_locale_file}"
|
52
|
-
upload_id = phraseapp_api.upload_file(default_locale_file)
|
63
|
+
upload_id = @phraseapp_api.upload_file(default_locale_file)
|
53
64
|
|
54
65
|
puts "Removing keys not in upload #{upload_id}"
|
55
|
-
phraseapp_api.remove_keys_not_in_upload(upload_id)
|
66
|
+
@phraseapp_api.remove_keys_not_in_upload(upload_id)
|
56
67
|
|
57
68
|
LocaleFileUpdates.new(phraseapp_files.values, [default_locale_file] + resolved_files)
|
58
69
|
end
|
59
70
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
71
|
+
def pull(fallback_locales_path)
|
72
|
+
phraseapp_locales = @phraseapp_api.download_locales
|
73
|
+
|
74
|
+
phraseapp_files_without_unverified = load_phraseapp_files(phraseapp_locales, true)
|
75
|
+
phraseapp_files_with_unverified = load_phraseapp_files(phraseapp_locales, false)
|
76
|
+
fallback_files = load_locale_files(fallback_locales_path).first
|
63
77
|
|
64
|
-
|
65
|
-
load_files(phraseapp_api, phraseapp_locales, true, fallback_locales_path)
|
78
|
+
validate_files!([phraseapp_files_with_unverified, phraseapp_files_without_unverified, fallback_files])
|
66
79
|
|
67
|
-
|
80
|
+
phraseapp_files_with_unverified = phraseapp_files_with_unverified.index_by(&:name)
|
81
|
+
fallback_files = fallback_files.index_by(&:name)
|
68
82
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
83
|
+
# Clean empty strings from the data and merge the fallback data in:
|
84
|
+
# we want to replace unverified keys with their values in the fallback
|
85
|
+
phraseapp_files_without_unverified.map do |phraseapp_without_unverified_file|
|
86
|
+
without_unverified = clear_empty_strings!(phraseapp_without_unverified_file.parsed_content)
|
87
|
+
with_unverified = clear_empty_strings!(phraseapp_files_with_unverified[phraseapp_without_unverified_file.name].parsed_content)
|
88
|
+
fallback = clear_empty_strings!(fallback_files[phraseapp_without_unverified_file.name].parsed_content)
|
89
|
+
|
90
|
+
restore_unverified_originals!(fallback, with_unverified, without_unverified)
|
91
|
+
LocaleFile.from_hash(phraseapp_without_unverified_file.name, without_unverified)
|
73
92
|
end
|
74
93
|
end
|
75
94
|
|
76
|
-
|
77
|
-
YMLConfigLoader.new(config_file_path)
|
78
|
-
end
|
95
|
+
private
|
79
96
|
|
80
|
-
def
|
97
|
+
def find_default_locale_file(locales, files)
|
81
98
|
default_locale = locales.find(&:default?)
|
82
99
|
|
83
100
|
default_locale_file = files.find do |file|
|
@@ -85,14 +102,18 @@ class PhraseAppUpdater
|
|
85
102
|
end
|
86
103
|
end
|
87
104
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
end
|
105
|
+
def load_phraseapp_files(phraseapp_locales, skip_unverified)
|
106
|
+
@phraseapp_api.download_files(phraseapp_locales, skip_unverified)
|
107
|
+
end
|
92
108
|
|
93
|
-
|
109
|
+
def load_locale_files(*paths)
|
110
|
+
paths.map do |path|
|
111
|
+
LocaleFileLoader.filenames(path).map { |l| LocaleFileLoader.load(l) }
|
112
|
+
end
|
113
|
+
end
|
94
114
|
|
95
|
-
|
115
|
+
def validate_files!(file_groups)
|
116
|
+
file_name_lists = file_groups.map do |files|
|
96
117
|
files.map(&:name).to_set
|
97
118
|
end
|
98
119
|
|
@@ -102,8 +123,43 @@ class PhraseAppUpdater
|
|
102
123
|
or removing langauges: #{file_name_lists}"
|
103
124
|
raise RuntimeError.new(message)
|
104
125
|
end
|
126
|
+
end
|
105
127
|
|
106
|
-
|
128
|
+
# Mutates without_verified to include the fallbacks where needed.
|
129
|
+
#
|
130
|
+
# For any keys in both `with_unverified` and `originals` but not present in
|
131
|
+
# `without_unverified`, restore the version from `originals` to
|
132
|
+
# `without_unverified`
|
133
|
+
def restore_unverified_originals!(fallback, with_unverified, without_unverified)
|
134
|
+
fallback.each do |key, value|
|
135
|
+
with_value = with_unverified[key]
|
136
|
+
|
137
|
+
case value
|
138
|
+
when Hash
|
139
|
+
if with_value.is_a?(Hash)
|
140
|
+
without_value = (without_unverified[key] ||= {})
|
141
|
+
restore_unverified_originals!(value, with_value, without_value)
|
142
|
+
end
|
143
|
+
else
|
144
|
+
if with_value && !with_value.is_a?(Hash) && !without_unverified.has_key?(key)
|
145
|
+
without_unverified[key] = value
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def clear_empty_strings!(hash)
|
152
|
+
hash.delete_if do |key, value|
|
153
|
+
if value == ""
|
154
|
+
true
|
155
|
+
elsif value.is_a?(Hash)
|
156
|
+
clear_empty_strings!(value)
|
157
|
+
value.empty?
|
158
|
+
else
|
159
|
+
false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
hash
|
107
163
|
end
|
108
164
|
|
109
165
|
class LocaleFileUpdates
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phraseapp_updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Griffin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|