yatapp 0.5.4 → 0.5.5
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 +2 -5
- data/README.md +7 -0
- data/lib/yatapp.rb +3 -1
- data/lib/yatapp/configuration.rb +2 -1
- data/lib/yatapp/socket.rb +6 -28
- data/lib/yatapp/store.rb +43 -0
- data/lib/yatapp/version.rb +1 -1
- data/lib/yatapp/yata_api_caller.rb +5 -18
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 2a249b5fc32c1f49f433436623f3c5d9d761966e
|
4
|
-
data.tar.gz: b529a6dc36bcf54a685c9e628e87c8f35736bc3d
|
5
2
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bacf21524a200dabb5f1fa4b45781770cb5ec31251151d61f5d8249e0cb0fd1b695df577306ec16e6824e2033234969b1dc45dcdac9c00ee8d462b7e548c7c3
|
4
|
+
data.tar.gz: cb3e5fb173d47fb0ac1e660772d395a15bb2314b312b8a3d620d349dbb525741d287eb6707650d17d7a030d47228264c4bfc5ecc25efc0dae87dfede2c19f99e
|
data/README.md
CHANGED
@@ -33,6 +33,7 @@ Gem can be used in two ways:
|
|
33
33
|
* `save_to_path` - you can define where files should be saved. Default: `/config/locales/`
|
34
34
|
* `root` - add locale as root to file with translations. Default: `false`
|
35
35
|
* `strip_empty` - generates only keys that have text and skip empty ones. Default `false`
|
36
|
+
* `download_on_start` - download all translations on start to i18n from Yata when Websocket is enabled. Default: `false`
|
36
37
|
|
37
38
|
First two parameters are required and the rest is optional.
|
38
39
|
|
@@ -158,7 +159,13 @@ Yatapp.start_websocket
|
|
158
159
|
|
159
160
|
```
|
160
161
|
|
162
|
+
### Download translations at the start of the application
|
161
163
|
|
164
|
+
If you want to download translations at the start of the application add to `Procfile` line:
|
165
|
+
```bash
|
166
|
+
task: rake yata:fetch_translations
|
167
|
+
```
|
168
|
+
It will download all translations to files.
|
162
169
|
|
163
170
|
## Development
|
164
171
|
|
data/lib/yatapp.rb
CHANGED
data/lib/yatapp/configuration.rb
CHANGED
data/lib/yatapp/socket.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
require 'faye/websocket'
|
2
2
|
require 'eventmachine'
|
3
3
|
require 'yatapp/inbox'
|
4
|
+
require 'yatapp/store'
|
4
5
|
require 'json'
|
5
6
|
require 'cgi'
|
6
7
|
require 'uri'
|
7
|
-
begin
|
8
|
-
require 'rails-i18n'
|
9
|
-
rescue
|
10
|
-
puts "WARNING: Failed to require rails-i18n gem, websocket integration may fail."
|
11
|
-
end
|
12
8
|
|
13
9
|
module Phoenix
|
14
10
|
class Socket
|
@@ -107,25 +103,6 @@ module Phoenix
|
|
107
103
|
@topic_joined = false # The initial join request has been acked by the remote server
|
108
104
|
end
|
109
105
|
|
110
|
-
def add_new_key_to_i18n(key, values)
|
111
|
-
values.each do |value|
|
112
|
-
unless I18n.available_locales.include?(value['lang'].to_sym)
|
113
|
-
add_new_locale(value['lang'])
|
114
|
-
end
|
115
|
-
|
116
|
-
key_array = key.split(".")
|
117
|
-
translation_hash = key_array.reverse.inject(value['text']) {|acc, n| {n => acc}}
|
118
|
-
I18n.backend.store_translations(value['lang'].to_sym, translation_hash)
|
119
|
-
puts "new translation added: #{value['lang']} => #{key}: #{value['text']}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def add_new_locale(lang)
|
124
|
-
existing_locales = I18n.config.available_locales
|
125
|
-
new_locales = existing_locales << lang.to_sym
|
126
|
-
I18n.config.available_locales = new_locales.uniq
|
127
|
-
end
|
128
|
-
|
129
106
|
def handle_message(event)
|
130
107
|
data = JSON.parse(event.data)
|
131
108
|
log event.data
|
@@ -135,12 +112,12 @@ module Phoenix
|
|
135
112
|
handle_close(event)
|
136
113
|
elsif data['event'] == 'new_translation'
|
137
114
|
payload = data['payload']
|
138
|
-
|
115
|
+
Store.add_new_key(payload['key'], payload['values'])
|
139
116
|
elsif data['event'] == 'updated_translation'
|
140
117
|
payload = data['payload']
|
141
|
-
|
142
|
-
elsif data['event'] == '
|
143
|
-
puts
|
118
|
+
Store.add_new_key(payload['new_key'], payload['values'])
|
119
|
+
elsif data['event'] == 'deleted_translation'
|
120
|
+
puts "deleted translation: #{data['payload']['key']}"
|
144
121
|
elsif data['ref'] == @join_ref && data['event'] == 'phx_error'
|
145
122
|
# NOTE: For some reason, on errors phx will send the join ref instead of the message ref
|
146
123
|
inbox_cond.broadcast
|
@@ -162,6 +139,7 @@ module Phoenix
|
|
162
139
|
@dead = false
|
163
140
|
thread_ready.broadcast
|
164
141
|
end
|
142
|
+
|
165
143
|
Yatapp.download_translations
|
166
144
|
end
|
167
145
|
|
data/lib/yatapp/store.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
begin
|
2
|
+
require 'rails-i18n'
|
3
|
+
rescue
|
4
|
+
puts "WARNING: Failed to require rails-i18n gem, websocket integration may fail."
|
5
|
+
end
|
6
|
+
|
7
|
+
module Yatapp
|
8
|
+
class Store
|
9
|
+
def self.store_translations(lang, api_response)
|
10
|
+
unless I18n.available_locales.include?(lang.to_sym)
|
11
|
+
add_new_locale(lang)
|
12
|
+
end
|
13
|
+
|
14
|
+
translations = api_response[lang]
|
15
|
+
|
16
|
+
I18n.backend.store_translations(lang.to_sym, translations)
|
17
|
+
puts "Loaded all #{lang} translations."
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add_new_key(key, values)
|
21
|
+
values.each do |value|
|
22
|
+
unless I18n.available_locales.include?(value['lang'].to_sym)
|
23
|
+
add_new_locale(value['lang'])
|
24
|
+
end
|
25
|
+
|
26
|
+
key_array = key.split(".")
|
27
|
+
translation_hash = key_array.reverse.inject(value['text']) {|acc, n| {n => acc}}
|
28
|
+
|
29
|
+
I18n.backend.store_translations(value['lang'].to_sym, translation_hash)
|
30
|
+
puts "new translation added: #{value['lang']} => #{key}: #{value['text']}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.add_new_locale(lang)
|
37
|
+
existing_locales = I18n.config.available_locales
|
38
|
+
new_locales = existing_locales << lang.to_sym
|
39
|
+
|
40
|
+
I18n.config.available_locales = new_locales.uniq
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/yatapp/version.rb
CHANGED
@@ -27,14 +27,14 @@ module Yatapp
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def download_translations_and_store
|
31
31
|
languages.each do |lang|
|
32
32
|
puts "Getting translation for #{lang}"
|
33
33
|
api_url = download_url_websocket(lang)
|
34
34
|
puts api_url
|
35
35
|
api_response = HTTParty.get(api_url)
|
36
36
|
next if !should_save_the_translation?(api_response)
|
37
|
-
|
37
|
+
Store.store_translations(lang, JSON.parse(api_response.body))
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -52,6 +52,9 @@ module Yatapp
|
|
52
52
|
Configuration::CONFIGURATION_OPTIONS.each do |key|
|
53
53
|
send("#{key}=", options[key])
|
54
54
|
end
|
55
|
+
|
56
|
+
raise ArgumentError.new("Missing API_ACCESS_TOKEN") unless api_access_token
|
57
|
+
raise ArgumentError.new("Missing PROJECT_ID") unless project_id
|
55
58
|
end
|
56
59
|
|
57
60
|
def save_translation(lang, response)
|
@@ -85,21 +88,5 @@ module Yatapp
|
|
85
88
|
url = url.sub(':lang', lang)
|
86
89
|
url = url + "?apiToken=#{api_access_token}&root=true"
|
87
90
|
end
|
88
|
-
|
89
|
-
def add_new_key_to_i18n(lang, api_response)
|
90
|
-
unless I18n.available_locales.include?(lang.to_sym)
|
91
|
-
add_new_locale(lang)
|
92
|
-
end
|
93
|
-
|
94
|
-
translations = api_response[lang]
|
95
|
-
I18n.backend.store_translations(lang.to_sym, translations)
|
96
|
-
puts "Loaded all #{lang} translations."
|
97
|
-
end
|
98
|
-
|
99
|
-
def add_new_locale(lang)
|
100
|
-
existing_locales = I18n.config.available_locales
|
101
|
-
new_locales = existing_locales << lang.to_sym
|
102
|
-
I18n.config.available_locales = new_locales.uniq
|
103
|
-
end
|
104
91
|
end
|
105
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yatapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- luki3k5
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/yatapp/inbox.rb
|
161
161
|
- lib/yatapp/railtie.rb
|
162
162
|
- lib/yatapp/socket.rb
|
163
|
+
- lib/yatapp/store.rb
|
163
164
|
- lib/yatapp/version.rb
|
164
165
|
- lib/yatapp/yata_api_caller.rb
|
165
166
|
- yatapp.gemspec
|
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
184
|
version: '0'
|
184
185
|
requirements: []
|
185
186
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.7.8
|
187
188
|
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: This gem allows for easy integration with Yata to fetch translation files
|