localeapp 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rvmrc +1 -1
- data/.travis.yml +3 -6
- data/CONTRIBUTING.md +27 -0
- data/README.md +42 -80
- data/features/step_definitions/cli_steps.rb +27 -0
- data/features/update.feature +16 -22
- data/lib/localeapp/api_caller.rb +1 -0
- data/lib/localeapp/cli/update.rb +18 -5
- data/lib/localeapp/rails.rb +39 -24
- data/lib/localeapp/version.rb +1 -1
- data/spec/localeapp/api_caller_spec.rb +1 -0
- data/spec/localeapp/cli/update_spec.rb +30 -9
- metadata +44 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODgxZTYzZjkxY2VlZDBiM2E4ODI5ZjU3MTMxNGRkMjNiMGM0MTNlZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDc5YzViOWJjNTVlNGU5NGNiNjI1MjI4MTM1ZDQyN2E0OWMwZWY1ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDYyOWNkNDBiZTRjODI0MmYxZDc5MjA2YjkwY2NmZWNmMmZkZGU3MjYzN2My
|
10
|
+
YTJiZDJmYzAzMjRmYWUzYzU2NWJjMjRlYTQ5MTUwNWZkNjQ3YTA4ZThhNmNl
|
11
|
+
ZmQ1ZDY2MGRiN2Y3NzQ1ODNlYTQxMWVmMzM1N2Q5OTA3ZDdkMjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjhjZTlkNDJmMzE4ODQ0NzNhMmI2ZjA1OWY1ZjNlYTRlOTY2ZmI1MjgyZjEy
|
14
|
+
NmU3N2JiNTJhYjQ3YjQ5ZjAxMjljYmUyNmE1YzMwMzJjNzgyYzk3NmRhNTM3
|
15
|
+
MzRiMzNlYzhhMDg1ZDA5OGI3MWZiMTNlNzdjNjYxNDBlNzk1Mjk=
|
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm ruby-1.9.3@localeapp
|
1
|
+
rvm use --create ruby-1.9.3@localeapp
|
data/.travis.yml
CHANGED
@@ -3,9 +3,8 @@ rvm:
|
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
5
|
- 2.1.0
|
6
|
-
- jruby
|
7
|
-
- jruby-
|
8
|
-
- jruby-21mode
|
6
|
+
- jruby
|
7
|
+
- jruby-head
|
9
8
|
gemfile:
|
10
9
|
- Gemfile.i18n_037
|
11
10
|
- Gemfile.i18n_050
|
@@ -16,7 +15,5 @@ matrix:
|
|
16
15
|
gemfile: Gemfile.i18n_037
|
17
16
|
- rvm: 2.1.0
|
18
17
|
gemfile: Gemfile.i18n_037
|
19
|
-
- rvm: jruby-
|
20
|
-
gemfile: Gemfile.i18n_037
|
21
|
-
- rvm: jruby-21mode
|
18
|
+
- rvm: jruby-head
|
22
19
|
gemfile: Gemfile.i18n_037
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
|
4
|
+
|
5
|
+
Here are some ways *you* can contribute:
|
6
|
+
|
7
|
+
* by using prerelease versions
|
8
|
+
* by reporting [bugs][2]
|
9
|
+
* by suggesting new features
|
10
|
+
* by writing or editing documentation
|
11
|
+
* by writing specifications
|
12
|
+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
|
13
|
+
* by refactoring code
|
14
|
+
* by resolving [issues][2]
|
15
|
+
* by reviewing patches
|
16
|
+
|
17
|
+
Starting point:
|
18
|
+
|
19
|
+
* Fork the repo
|
20
|
+
* Clone your repo
|
21
|
+
* Run `bundle install`
|
22
|
+
* Make your changes
|
23
|
+
* Ensure specs pass by running `bundle exec rake`
|
24
|
+
* Submit your pull request
|
25
|
+
|
26
|
+
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
27
|
+
[2]: https://github.com/Locale/localeapp/issues
|
data/README.md
CHANGED
@@ -1,23 +1,16 @@
|
|
1
1
|
# Locale
|
2
2
|
|
3
|
-
[![Build status](https://secure.travis-ci.org/Locale/localeapp.png)](http://travis-ci.org/Locale/localeapp)
|
3
|
+
[![Build status](https://secure.travis-ci.org/Locale/localeapp.png)](http://travis-ci.org/Locale/localeapp)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/Locale/localeapp.png)](https://codeclimate.com/github/Locale/localeapp)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/localeapp.png)](http://badge.fury.io/rb/localeapp)
|
4
6
|
|
5
|
-
The localeapp gem connects your rails app to the Locale service on
|
6
|
-
http://www.localeapp.com. Locale makes hand editing translation files something
|
7
|
-
you don't have to do.
|
7
|
+
The localeapp gem connects your rails app to the Locale service on http://www.localeapp.com. Locale makes hand editing translation files something you don't have to do.
|
8
8
|
|
9
|
-
The gem hooks into the i18n exception mechanism to send missing translations to
|
10
|
-
the app. When translated content has been added it's automatically pulled down
|
11
|
-
so you can see it straight away.
|
9
|
+
The gem hooks into the i18n exception mechanism to send missing translations to the app. When translated content has been added it's automatically pulled down so you can see it straight away.
|
12
10
|
|
13
11
|
## Security
|
14
12
|
|
15
|
-
Though the i18n gem uses YAML as it's default file format it doesn't require
|
16
|
-
serialization of ruby objects. To prevent the kind of security problems
|
17
|
-
detailed in [CVE-2013-0156][1] the localeapp gem will not load any YAML containing
|
18
|
-
the string !ruby/ as of version 0.6.9.
|
19
|
-
|
20
|
-
[1]: https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/61bkgvnSGTQ
|
13
|
+
Though the i18n gem uses YAML as it's default file format it doesn't require serialization of ruby objects. To prevent the kind of security problems detailed in [CVE-2013-0156][1] the localeapp gem will not load any YAML containing the string !ruby/ as of version 0.6.9.
|
21
14
|
|
22
15
|
## Installation
|
23
16
|
|
@@ -32,8 +25,7 @@ Create a project on localeapp.com and get the api key. Then run:
|
|
32
25
|
|
33
26
|
bundle exec localeapp install <YOUR_API_KEY>
|
34
27
|
|
35
|
-
This will check everything looks good and create
|
36
|
-
`config/initializers/localeapp.rb` for you.
|
28
|
+
This will check everything looks good and create `config/initializers/localeapp.rb` for you.
|
37
29
|
|
38
30
|
### Rails 2.3
|
39
31
|
|
@@ -48,13 +40,13 @@ Install the gem:
|
|
48
40
|
Create a project on localeapp.com and get the api key. Then run:
|
49
41
|
|
50
42
|
localeapp install <YOUR_API_KEY>
|
51
|
-
|
43
|
+
|
52
44
|
### Non rails projects
|
53
45
|
|
54
46
|
Install the gem and run:
|
55
47
|
|
56
48
|
localeapp install --standalone <YOUR_API_KEY>
|
57
|
-
|
49
|
+
|
58
50
|
This will create a `.localeapp` directory for your configuration files.
|
59
51
|
|
60
52
|
### Public projects
|
@@ -63,45 +55,33 @@ Install the gem and run:
|
|
63
55
|
|
64
56
|
localeapp install --github <YOUR_API_KEY>
|
65
57
|
|
66
|
-
This will create a skeleton project you can push to `<your_gem>-i18n` on
|
67
|
-
github. You get a `.localeapp` directory for your configuration files, a
|
68
|
-
`locales` directory for the yaml, a `.gitignore` file that ignores `.localeapp`
|
69
|
-
and a `README.md` explaining to translators how to find the project on
|
70
|
-
localeapp.com.
|
58
|
+
This will create a skeleton project you can push to `<your_gem>-i18n` on github. You get a `.localeapp` directory for your configuration files, a `locales` directory for the yaml, a `.gitignore` file that ignores `.localeapp` and a `README.md` explaining to translators how to find the project on localeapp.com.
|
71
59
|
|
72
60
|
## Importing existing content
|
73
61
|
|
74
|
-
You can import via localeapp.com or with the command line tool. To import
|
75
|
-
existing translations do:
|
62
|
+
You can import via localeapp.com or with the command line tool. To import existing translations do:
|
76
63
|
|
77
64
|
localeapp push config/locales/en.yml
|
78
65
|
|
79
|
-
This will queue importing the file. The projects pages on localeapp.com will
|
80
|
-
automatically refresh so you can see the import progress.
|
66
|
+
This will queue importing the file. The projects pages on localeapp.com will automatically refresh so you can see the import progress.
|
81
67
|
|
82
|
-
If you've more than one locale to import you can import all files in a directory
|
68
|
+
If you've more than one locale to import you can import all files in a directory:
|
83
69
|
|
84
70
|
localeapp push config/locales/
|
85
71
|
|
86
72
|
## Default Rails Translations
|
87
73
|
|
88
|
-
Locale will automatically add the standard rails translations when a project is
|
89
|
-
created. If for some reason you don't want these, you can remove them using in
|
90
|
-
the project libraries area on localeapp.com
|
74
|
+
Locale will automatically add the standard rails translations when a project is created. If for some reason you don't want these, you can remove them using in the project libraries area on localeapp.com
|
91
75
|
|
92
76
|
## Automatically sending missing translations
|
93
77
|
|
94
|
-
Missing translations are automatically sent only in the development environment
|
95
|
-
by default. When a page is refreshed any missing translations will be sent to
|
96
|
-
localeapp.com.
|
78
|
+
Missing translations are automatically sent only in the development environment by default. When a page is refreshed any missing translations will be sent to localeapp.com.
|
97
79
|
|
98
|
-
If you want to disable sending missing translations in the development
|
99
|
-
environment then edit `config/initializers/localeapp.rb` to include:
|
80
|
+
If you want to disable sending missing translations in the development environment then edit `config/initializers/localeapp.rb` to include:
|
100
81
|
|
101
82
|
config.sending_environments = []
|
102
83
|
|
103
|
-
This is just an array, so you can configure it to match send in any environment
|
104
|
-
you wish.
|
84
|
+
This is just an array, so you can configure it to match send in any environment you wish.
|
105
85
|
|
106
86
|
## Manually create translations
|
107
87
|
|
@@ -109,27 +89,19 @@ You can create translations on the command line by running:
|
|
109
89
|
|
110
90
|
localeapp add key.name en:"test content" es:"spanish content"
|
111
91
|
|
112
|
-
You must provide at least one translation and the locale code must already
|
113
|
-
exist in the project.
|
92
|
+
You must provide at least one translation and the locale code must already exist in the project.
|
114
93
|
|
115
94
|
## Automatically pulling translations
|
116
95
|
|
117
|
-
There are two ways to do this, one that suits a single developer working the
|
118
|
-
code locally and one where the translations are being pulled down to a staging
|
119
|
-
(or live) server.
|
96
|
+
There are two ways to do this, one that suits a single developer working the code locally and one where the translations are being pulled down to a staging (or live) server.
|
120
97
|
|
121
98
|
### Single developer
|
122
99
|
|
123
|
-
In this mode the gem pulls any updated translations from localeapp.com at the
|
124
|
-
beginning of each request. This is the default setting so you don't need to do
|
125
|
-
anything special.
|
100
|
+
In this mode the gem pulls any updated translations from localeapp.com at the beginning of each request. This is the default setting so you don't need to do anything special.
|
126
101
|
|
127
102
|
### Staging server
|
128
103
|
|
129
|
-
In this mode you configure the individual listeners to not poll every request
|
130
|
-
and instead run localeapp in daemon mode to fetch updated translations. This is
|
131
|
-
useful when you have more than one listener and don't want them to race to
|
132
|
-
update the translations.
|
104
|
+
In this mode you configure the individual listeners to not poll every request and instead run localeapp in daemon mode to fetch updated translations. This is useful when you have more than one listener and don't want them to race to update the translations.
|
133
105
|
|
134
106
|
#### Disabling polling
|
135
107
|
|
@@ -141,49 +113,34 @@ Run the daemon with:
|
|
141
113
|
|
142
114
|
localeapp daemon
|
143
115
|
|
144
|
-
The listeners will automatically reload translations when they see there are
|
145
|
-
new ones. The daemon has two options:
|
116
|
+
The listeners will automatically reload translations when they see there are new ones. The daemon has two options:
|
146
117
|
|
147
118
|
-b will run in the background and put a pid file in tmp/pids/localeapp.pid
|
148
119
|
-i X will change the polling interval to X from it's default five seconds.
|
149
120
|
|
150
121
|
### Disabling Reloading
|
151
122
|
|
152
|
-
Automatic reloading is only enabled in the development environment by default and
|
153
|
-
can be disabled in a similar way to polling and sending:
|
123
|
+
Automatic reloading is only enabled in the development environment by default and can be disabled in a similar way to polling and sending:
|
154
124
|
|
155
125
|
config.reloading_environments = []
|
156
126
|
|
157
127
|
### Caching
|
158
128
|
|
159
|
-
To prevent localeapp from sending translations every time they are missing,
|
160
|
-
add this config setting:
|
129
|
+
To prevent localeapp from sending translations every time they are missing, add this config setting:
|
161
130
|
|
162
131
|
config.cache_missing_translations = true
|
163
132
|
|
164
133
|
## Inviting other developers and translators
|
165
134
|
|
166
|
-
You can invite other developers and translators via localeapp.com. Developers
|
167
|
-
have access to all the content and all the locales. Translators are restricted
|
168
|
-
to editing only the locales you give them access too.
|
135
|
+
You can invite other developers and translators via localeapp.com. Developers have access to all the content and all the locales. Translators are restricted to editing only the locales you give them access too.
|
169
136
|
|
170
137
|
## Adding a locale
|
171
138
|
|
172
|
-
If we find an unknown locale during an import we'll add it to your project.
|
173
|
-
You can also add a new locale to a project via localeapp.com. This will create
|
174
|
-
missing translations for every translation key. You will need to restart any
|
175
|
-
listeners completely to pick up the new locale.
|
139
|
+
If we find an unknown locale during an import we'll add it to your project. You can also add a new locale to a project via localeapp.com. This will create missing translations for every translation key. You will need to restart any listeners completely to pick up the new locale.
|
176
140
|
|
177
141
|
## Syck, Psych, and creating YAML
|
178
142
|
|
179
|
-
Since ruby 1.9.3-p0 Psych has been the default YAML engine in Ruby. Psych is
|
180
|
-
based on libyaml and fixes a number of issues with the previous YAML library,
|
181
|
-
Syck. localeapp.com uses 1.9.3 and Psych for all its YAML processing. The
|
182
|
-
localeapp gem will use Psych if it is available but falls back to the ya2yaml
|
183
|
-
library if not. ya2yaml supports UTF-8 (which Syck doesn't handle very well)
|
184
|
-
but it does write YAML differently to Psych so you will notice differences
|
185
|
-
between exporting directly from localeapp.com and doing localeapp pull on the
|
186
|
-
command line unless you're using 1.9.3+ or have installed Psych as a gem.
|
143
|
+
Since ruby 1.9.3-p0 Psych has been the default YAML engine in Ruby. Psych is based on libyaml and fixes a number of issues with the previous YAML library, Syck. localeapp.com uses 1.9.3 and Psych for all its YAML processing. The localeapp gem will use Psych if it is available but falls back to the ya2yaml library if not. ya2yaml supports UTF-8 (which Syck doesn't handle very well) but it does write YAML differently to Psych so you will notice differences between exporting directly from localeapp.com and doing localeapp pull on the command line unless you're using 1.9.3+ or have installed Psych as a gem.
|
187
144
|
|
188
145
|
## Proxies
|
189
146
|
|
@@ -193,23 +150,28 @@ If you need to go through a proxy server, you can configure it with:
|
|
193
150
|
|
194
151
|
## SSL Certificate verification
|
195
152
|
|
196
|
-
localeapp.com uses https everywhere but certificate validation is turned off by
|
197
|
-
default. This is because ruby doesn't know how to read the certs from the OSX
|
198
|
-
keychain. You can turn verification on and tell the gem where the latest CA
|
199
|
-
certificates are by adding:
|
153
|
+
localeapp.com uses https everywhere but certificate validation is turned off by default. This is because ruby doesn't know how to read the certs from the OSX keychain. You can turn verification on and tell the gem where the latest CA certificates are by adding:
|
200
154
|
|
201
155
|
config.ssl_verify = true
|
202
156
|
config.ssl_ca_file = /path/to/ca_cert.pm
|
203
157
|
|
204
|
-
See [this article on Ruby Inside][
|
205
|
-
|
206
|
-
[1]: http://www.rubyinside.com/how-to-cure-nethttps-risky-default-https-behavior-4010.html
|
158
|
+
See [this article on Ruby Inside][2] for some more details.
|
207
159
|
|
208
160
|
## Support and feedback
|
209
161
|
|
210
|
-
You can contact us via the support link at the bottom of the page or emailing
|
211
|
-
|
162
|
+
You can contact us via the support link at the bottom of the page or emailing support@localeapp.com
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
See corresponding [contributing guidelines][3].
|
212
167
|
|
213
168
|
## License
|
214
169
|
|
215
|
-
|
170
|
+
Copyright (c) 2014 [Locale][5] and other [contributors][6], released under the [MIT License][4].
|
171
|
+
|
172
|
+
[1]: https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/61bkgvnSGTQ
|
173
|
+
[2]: http://www.rubyinside.com/how-to-cure-nethttps-risky-default-https-behavior-4010.html
|
174
|
+
[3]: https://github.com/Locale/localeapp/blob/master/CONTRIBUTING.md
|
175
|
+
[4]: http://opensource.org/licenses/MIT
|
176
|
+
[5]: https://github.com/Locale
|
177
|
+
[6]: https://github.com/Locale/localeapp/graphs/contributors
|
@@ -34,6 +34,11 @@ When /^new translations for the api key "([^"]*)" since "([^"]*)" with time "([^
|
|
34
34
|
add_fake_web_uri(:get, uri, ['200', 'OK'], body, 'date' => Time.at(new_time.to_i).httpdate)
|
35
35
|
end
|
36
36
|
|
37
|
+
When /^new translations for the api key "([^"]*)" since last fetch with time "([^"]*)" seconds later$/ do |api_key, time_shift|
|
38
|
+
steps %Q{
|
39
|
+
When new translations for the api key "#{api_key}" since "#{@timestamp}" with time "#{@timestamp + time_shift.to_i}"
|
40
|
+
}
|
41
|
+
end
|
37
42
|
|
38
43
|
When /^I have a valid project on localeapp\.com with api key "([^"]*)" and the translation key "([^"]*)"/ do |api_key, key_name|
|
39
44
|
uri = "https://api.localeapp.com/v1/projects/#{api_key}/translations/#{key_name.gsub(/\./, '%2E')}"
|
@@ -78,3 +83,25 @@ When /^help should not be displayed$/ do
|
|
78
83
|
"""
|
79
84
|
}
|
80
85
|
end
|
86
|
+
|
87
|
+
When /^the timestamp is (\d+) months? old$/ do |months|
|
88
|
+
@timestamp = Time.now.to_i - months.to_i * 2592000
|
89
|
+
steps %Q{
|
90
|
+
And a file named "log/localeapp.yml" with:
|
91
|
+
"""
|
92
|
+
---
|
93
|
+
:updated_at: #{@timestamp}
|
94
|
+
:polled_at: #{@timestamp}
|
95
|
+
"""
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
Then /^translations should be fetched since last fetch only$/ do
|
100
|
+
steps %Q{
|
101
|
+
Then the output should contain:
|
102
|
+
"""
|
103
|
+
Localeapp update: checking for translations since #{@timestamp}
|
104
|
+
Found and updated new translations
|
105
|
+
"""
|
106
|
+
}
|
107
|
+
end
|
data/features/update.feature
CHANGED
@@ -4,20 +4,11 @@ Feature: Getting new translations
|
|
4
4
|
In order to receive the translations that have been updated since the last check
|
5
5
|
When I have a valid project on localeapp.com with api key "MYAPIKEY"
|
6
6
|
And an initializer file
|
7
|
-
And
|
8
|
-
"""
|
9
|
-
---
|
10
|
-
:updated_at: 120
|
11
|
-
:polled_at: 130
|
12
|
-
"""
|
13
|
-
And new translations for the api key "MYAPIKEY" since "120" with time "140"
|
7
|
+
And the timestamp is 2 months old
|
8
|
+
And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
|
14
9
|
And a directory named "config/locales"
|
15
10
|
When I run `localeapp update`
|
16
|
-
Then
|
17
|
-
"""
|
18
|
-
Localeapp update: checking for translations since 120
|
19
|
-
Found and updated new translations
|
20
|
-
"""
|
11
|
+
Then translations should be fetched since last fetch only
|
21
12
|
And help should not be displayed
|
22
13
|
And a file named "config/locales/en.yml" should exist
|
23
14
|
# check the content here
|
@@ -26,19 +17,22 @@ Feature: Getting new translations
|
|
26
17
|
Scenario: Running update with no initializer file, passing the key on the command line
|
27
18
|
In order to receive the translations that have been updated since the last check
|
28
19
|
When I have a valid project on localeapp.com with api key "MYAPIKEY"
|
29
|
-
And
|
30
|
-
"""
|
31
|
-
---
|
32
|
-
:updated_at: 120
|
33
|
-
:polled_at: 130
|
34
|
-
"""
|
35
|
-
And new translations for the api key "MYAPIKEY" since "120" with time "140"
|
20
|
+
And the timestamp is 2 months old
|
21
|
+
And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
|
36
22
|
And a directory named "config/locales"
|
37
23
|
When I run `localeapp -k MYAPIKEY update`
|
24
|
+
Then translations should be fetched since last fetch only
|
25
|
+
And help should not be displayed
|
26
|
+
And a file named "config/locales/en.yml" should exist
|
27
|
+
|
28
|
+
Scenario: Running update with a too old timestamp
|
29
|
+
In order to receive the translations that have been updated since the last check
|
30
|
+
When I have a valid project on localeapp.com with api key "MYAPIKEY"
|
31
|
+
And an initializer file
|
32
|
+
And the timestamp is 8 months old
|
33
|
+
When I run `localeapp update`
|
38
34
|
Then the output should contain:
|
39
35
|
"""
|
40
|
-
|
41
|
-
Found and updated new translations
|
36
|
+
Timestamp is missing or too old
|
42
37
|
"""
|
43
38
|
And help should not be displayed
|
44
|
-
And a file named "config/locales/en.yml" should exist
|
data/lib/localeapp/api_caller.rb
CHANGED
@@ -70,6 +70,7 @@ module Localeapp
|
|
70
70
|
RestClient::InternalServerError,
|
71
71
|
RestClient::BadGateway,
|
72
72
|
RestClient::ServiceUnavailable,
|
73
|
+
RestClient::UnprocessableEntity,
|
73
74
|
RestClient::GatewayTimeout => error
|
74
75
|
return error.response
|
75
76
|
rescue RestClient::ServerBrokeConnection => error
|
data/lib/localeapp/cli/update.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
module Localeapp
|
2
2
|
module CLI
|
3
3
|
class Update < Command
|
4
|
+
attr_accessor :poller
|
5
|
+
|
4
6
|
def execute
|
5
|
-
poller = Localeapp::Poller.new
|
6
|
-
|
7
|
-
|
8
|
-
@output.puts "Found and updated new translations"
|
7
|
+
self.poller = Localeapp::Poller.new
|
8
|
+
if timestamp_too_old?
|
9
|
+
@output.puts("Timestamp is missing or too old. Please run `localeapp pull` first.")
|
9
10
|
else
|
10
|
-
@output.puts
|
11
|
+
@output.puts("Localeapp update: checking for translations since #{poller.updated_at}")
|
12
|
+
success = poller.poll!
|
13
|
+
@output.puts(success ? "Found and updated new translations" : "No new translations")
|
11
14
|
end
|
12
15
|
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def timestamp_too_old?
|
20
|
+
poller.updated_at < six_months_ago
|
21
|
+
end
|
22
|
+
|
23
|
+
def six_months_ago
|
24
|
+
Time.now.to_i - 15552000 # This is 6.months.to_i according to ActiveRecord
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
data/lib/localeapp/rails.rb
CHANGED
@@ -3,34 +3,14 @@ require 'fileutils'
|
|
3
3
|
module Localeapp
|
4
4
|
module Rails
|
5
5
|
def self.initialize
|
6
|
-
if defined?(::Rails.logger)
|
7
|
-
rails_logger = ::Rails.logger
|
8
|
-
elsif defined?(RAILS_DEFAULT_LOGGER)
|
9
|
-
rails_logger = RAILS_DEFAULT_LOGGER
|
10
|
-
end
|
11
|
-
|
12
|
-
if defined?(::Rails.env)
|
13
|
-
rails_env = ::Rails.env
|
14
|
-
elsif defined?(RAILS_ENV)
|
15
|
-
rails_env = RAILS_ENV
|
16
|
-
end
|
17
|
-
|
18
|
-
if defined?(::Rails.root)
|
19
|
-
rails_root = ::Rails.root
|
20
|
-
elsif defined?(RAILS_ROOT)
|
21
|
-
rails_root = RAILS_ROOT
|
22
|
-
end
|
23
6
|
|
24
7
|
ActionController::Base.send(:include, Localeapp::Rails::Controller)
|
25
8
|
|
26
|
-
if
|
9
|
+
if rails_version_matches? '~> 2.3' # TODO: Check previous rails versions if required
|
27
10
|
require 'localeapp/rails/2_3_translation_helper_monkeypatch'
|
28
11
|
end
|
29
12
|
|
30
|
-
|
31
|
-
# ie: after CVE-2013-4491 patch (https://github.com/rails/rails/commit/78790e4bceedc632cb40f9597792d7e27234138a)
|
32
|
-
if (::Rails::VERSION::MAJOR == 4 && (::Rails::VERSION::MINOR > 0 or (::Rails::VERSION::MINOR == 0 && ::Rails::VERSION::TINY >= 2))) or
|
33
|
-
(::Rails::VERSION::MAJOR == 3 && (::Rails::VERSION::MINOR > 2 or (::Rails::VERSION::MINOR == 2 && ::Rails::VERSION::TINY >= 16)))
|
13
|
+
if rails_version_matches_any? '~> 3.2.16', '~> 4.0.2' # ie: after CVE-2013-4491 patch (https://github.com/rails/rails/commit/78790e4bceedc632cb40f9597792d7e27234138a)
|
34
14
|
require 'localeapp/rails/force_exception_handler_in_translation_helper'
|
35
15
|
require 'localeapp/rails/mimic_rails_missing_translation_display'
|
36
16
|
end
|
@@ -39,8 +19,8 @@ module Localeapp
|
|
39
19
|
config.logger = rails_logger
|
40
20
|
config.environment_name = rails_env
|
41
21
|
config.project_root = rails_root
|
42
|
-
config.synchronization_data_file = File.join([
|
43
|
-
config.translation_data_directory = File.join([
|
22
|
+
config.synchronization_data_file = File.join([config.project_root, 'log', 'localeapp.yml'])
|
23
|
+
config.translation_data_directory = File.join([config.project_root, 'config', 'locales'])
|
44
24
|
end
|
45
25
|
initialize_synchronization_data_file
|
46
26
|
end
|
@@ -54,6 +34,41 @@ module Localeapp
|
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def self.rails_logger
|
41
|
+
if defined?(::Rails.logger)
|
42
|
+
::Rails.logger
|
43
|
+
elsif defined?(RAILS_DEFAULT_LOGGER)
|
44
|
+
RAILS_DEFAULT_LOGGER
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.rails_env
|
49
|
+
if defined?(::Rails.env)
|
50
|
+
::Rails.env
|
51
|
+
elsif defined?(RAILS_ENV)
|
52
|
+
RAILS_ENV
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.rails_root
|
57
|
+
if defined?(::Rails.root)
|
58
|
+
::Rails.root
|
59
|
+
elsif defined?(RAILS_ROOT)
|
60
|
+
RAILS_ROOT
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.rails_version_matches?(requirement)
|
65
|
+
Gem::Requirement.new(requirement).satisfied_by? Gem::Version.new(::Rails::VERSION::STRING)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.rails_version_matches_any?(*requirements)
|
69
|
+
requirements.map{ |r| rails_version_matches?(r) }.reduce(:|)
|
70
|
+
end
|
71
|
+
|
57
72
|
end
|
58
73
|
end
|
59
74
|
|
data/lib/localeapp/version.rb
CHANGED
@@ -197,6 +197,7 @@ describe Localeapp::ApiCaller, "#call(object)" do
|
|
197
197
|
{
|
198
198
|
304 => 'Not Modified',
|
199
199
|
404 => 'Resource Not Found',
|
200
|
+
422 => 'Unprocessable Entity',
|
200
201
|
500 => 'Internal Server Error',
|
201
202
|
# Work out when this could happen
|
202
203
|
# 501 => 'Not Implemented',
|
@@ -2,17 +2,38 @@ require 'spec_helper'
|
|
2
2
|
require 'localeapp/cli/update'
|
3
3
|
|
4
4
|
describe Localeapp::CLI::Update, "#execute" do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let(:output) { StringIO.new }
|
6
|
+
let(:updater) { Localeapp::CLI::Update.new(:output => output) }
|
7
|
+
let(:poller) { Localeapp::Poller.new }
|
8
|
+
|
9
|
+
before(:each) { Localeapp::Poller.stub(:new => poller) }
|
10
|
+
|
11
|
+
context "when timestamp is recent" do
|
12
|
+
before(:each) { poller.stub(:updated_at => Time.now.to_i - 60) }
|
13
|
+
|
14
|
+
it "creates a Poller and calls poll! on it" do
|
15
|
+
with_configuration do
|
16
|
+
poller.should_receive(:poll!)
|
17
|
+
updater.execute
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
context "when timestamp is too old" do
|
23
|
+
before(:each) { poller.stub(:updated_at => 0) }
|
24
|
+
|
25
|
+
it "warns the user" do
|
26
|
+
with_configuration do
|
27
|
+
updater.execute
|
28
|
+
output.string.should include("Timestamp is missing or too old.")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not even call the API" do
|
33
|
+
with_configuration do
|
34
|
+
poller.should_not_receive(:poll!)
|
35
|
+
updater.execute
|
36
|
+
end
|
16
37
|
end
|
17
38
|
end
|
18
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localeapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Dell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- .rvmrc
|
196
196
|
- .travis.yml
|
197
197
|
- CHANGELOG.md
|
198
|
+
- CONTRIBUTING.md
|
198
199
|
- Gemfile
|
199
200
|
- Gemfile.github_project.rb
|
200
201
|
- Gemfile.i18n_037
|
@@ -295,9 +296,48 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
296
|
version: '0'
|
296
297
|
requirements: []
|
297
298
|
rubyforge_project: localeapp
|
298
|
-
rubygems_version: 2.2.
|
299
|
+
rubygems_version: 2.2.2
|
299
300
|
signing_key:
|
300
301
|
specification_version: 4
|
301
302
|
summary: Easy i18n translation management with localeapp.com
|
302
|
-
test_files:
|
303
|
+
test_files:
|
304
|
+
- features/add.feature
|
305
|
+
- features/bad_command.feature
|
306
|
+
- features/help.feature
|
307
|
+
- features/install.feature
|
308
|
+
- features/mv.feature
|
309
|
+
- features/pull.feature
|
310
|
+
- features/push.feature
|
311
|
+
- features/rm.feature
|
312
|
+
- features/step_definitions/cli_steps.rb
|
313
|
+
- features/support/env.rb
|
314
|
+
- features/support/hooks.rb
|
315
|
+
- features/update.feature
|
316
|
+
- spec/fixtures/empty_log.yml
|
317
|
+
- spec/fixtures/en.yml
|
318
|
+
- spec/fixtures/es.yml
|
319
|
+
- spec/localeapp/api_call_spec.rb
|
320
|
+
- spec/localeapp/api_caller_spec.rb
|
321
|
+
- spec/localeapp/cli/add_spec.rb
|
322
|
+
- spec/localeapp/cli/daemon_spec.rb
|
323
|
+
- spec/localeapp/cli/install_spec.rb
|
324
|
+
- spec/localeapp/cli/pull_spec.rb
|
325
|
+
- spec/localeapp/cli/push_spec.rb
|
326
|
+
- spec/localeapp/cli/rename_spec.rb
|
327
|
+
- spec/localeapp/cli/update_spec.rb
|
328
|
+
- spec/localeapp/configuration_spec.rb
|
329
|
+
- spec/localeapp/default_value_handler_spec.rb
|
330
|
+
- spec/localeapp/exception_handler_spec.rb
|
331
|
+
- spec/localeapp/key_checker_spec.rb
|
332
|
+
- spec/localeapp/missing_translations_spec.rb
|
333
|
+
- spec/localeapp/poller_spec.rb
|
334
|
+
- spec/localeapp/rails/controller_spec.rb
|
335
|
+
- spec/localeapp/routes_spec.rb
|
336
|
+
- spec/localeapp/sender_spec.rb
|
337
|
+
- spec/localeapp/updater_spec.rb
|
338
|
+
- spec/localeapp_spec.rb
|
339
|
+
- spec/spec_helper.rb
|
340
|
+
- spec/support/i18n/missing_translation.rb
|
341
|
+
- spec/support/localeapp_integration_data.rb
|
342
|
+
- spec/support/localeapp_synchronization_data.rb
|
303
343
|
has_rdoc:
|