i18n-backend-http 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36137a83ff8e2c9c616f494ab4b84c55f6751f1c
4
+ data.tar.gz: 827f9ac3ed6688b05ca39dee9a90cc3f55ca2c61
5
+ SHA512:
6
+ metadata.gz: 73bba6050a343f6c5fdcb44add77fd1a00c05e9fbdd6ba74b138533d1e3a66ae171140672982f23af13a242d5182874c349ff3e26aa7f30fe1915f29da196986
7
+ data.tar.gz: b372946bcb397e949af0218b86fa9f4ccdfdfdc254437fdea4dd2b1bf892a06d238bf8b1cf3b9ecca4c7abf7957377898a899dffa045ab30ca2e27f3701da447
@@ -28,6 +28,10 @@ module I18n
28
28
  start_polling if @options[:poll]
29
29
  end
30
30
 
31
+ def available_locales
32
+ @translations.keys.map(&:to_sym).select { |l| l != :i18n }
33
+ end
34
+
31
35
  def stop_polling
32
36
  @stop_polling = true
33
37
  end
@@ -1,7 +1,7 @@
1
1
  module I18n
2
2
  module Backend
3
3
  class Http
4
- VERSION = Version = "0.1.2"
4
+ VERSION = Version = "0.1.3"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,128 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: i18n-backend-http
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Michael Grosser
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-08-02 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: i18n
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
25
17
  - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
31
20
  type: :runtime
32
- requirement: *id001
33
21
  prerelease: false
34
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
35
28
  name: gem_of_thrones
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
39
31
  - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
45
34
  type: :runtime
46
- requirement: *id002
47
35
  prerelease: false
48
- - !ruby/object:Gem::Dependency
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
49
42
  name: faraday
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
53
45
  - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
59
48
  type: :runtime
60
- requirement: *id003
61
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
62
55
  description:
63
56
  email: michael@grosser.it
64
57
  executables: []
65
-
66
58
  extensions: []
67
-
68
59
  extra_rdoc_files: []
69
-
70
- files:
71
- - .travis.yml
72
- - Appraisals
73
- - Gemfile
74
- - Gemfile.lock
75
- - Rakefile
76
- - Readme.md
77
- - gemfiles/rails2.gemfile
78
- - gemfiles/rails2.gemfile.lock
79
- - gemfiles/rails3.gemfile
80
- - gemfiles/rails3.gemfile.lock
81
- - i18n-backend-http.gemspec
60
+ files:
82
61
  - lib/i18n/backend/http.rb
83
62
  - lib/i18n/backend/http/etag_http_client.rb
84
63
  - lib/i18n/backend/http/lru_cache.rb
85
64
  - lib/i18n/backend/http/null_cache.rb
86
65
  - lib/i18n/backend/http/version.rb
87
- - test/fixtures/static/testing.yml
88
- - test/fixtures/vcr/error.yml
89
- - test/fixtures/vcr/matching_etag.yml
90
- - test/fixtures/vcr/multiple_locales.yml
91
- - test/fixtures/vcr/simple.yml
92
- - test/i18n/backend/http_test.rb
93
- - test/test_helper.rb
94
- homepage: http://github.com/grosser/i18n-backend-http
95
- licenses:
66
+ homepage: https://github.com/grosser/i18n-backend-http
67
+ licenses:
96
68
  - MIT
69
+ metadata: {}
97
70
  post_install_message:
98
71
  rdoc_options: []
99
-
100
- require_paths:
72
+ require_paths:
101
73
  - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
105
76
  - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
111
- required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
- requirements:
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
114
81
  - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
120
84
  requirements: []
121
-
122
85
  rubyforge_project:
123
- rubygems_version: 1.8.24
86
+ rubygems_version: 2.2.2
124
87
  signing_key:
125
- specification_version: 3
126
- summary: Rails I18n Backend for Http APIs with etag-aware background polling and memory+[memcache] caching
88
+ specification_version: 4
89
+ summary: Rails I18n Backend for Http APIs with etag-aware background polling and memory+[memcache]
90
+ caching
127
91
  test_files: []
128
-
@@ -1,5 +0,0 @@
1
- script: "bundle exec rake"
2
- rvm:
3
- - ree
4
- - 1.9.2
5
- - 1.9.3
data/Appraisals DELETED
@@ -1,7 +0,0 @@
1
- appraise "rails2" do
2
- gem 'i18n', '~>0.4.0'
3
- end
4
-
5
- appraise "rails3" do
6
- gem 'i18n'
7
- end
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source :rubygems
2
- gemspec
3
-
4
- gem 'rake'
5
- gem 'shoulda'
6
- gem 'vcr'
7
- gem 'webmock'
8
- gem 'mocha'
9
- gem 'appraisal'
10
- gem 'mynyml-redgreen'
11
- gem 'json'
@@ -1,52 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- i18n-backend-http (0.1.2)
5
- faraday
6
- gem_of_thrones
7
- i18n
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- addressable (2.2.8)
13
- appraisal (0.4.1)
14
- bundler
15
- rake
16
- crack (0.3.1)
17
- faraday (0.8.1)
18
- multipart-post (~> 1.1)
19
- gem_of_thrones (0.2.1)
20
- i18n (0.6.0)
21
- json (1.7.1)
22
- metaclass (0.0.1)
23
- mocha (0.11.4)
24
- metaclass (~> 0.0.1)
25
- multipart-post (1.1.5)
26
- mynyml-redgreen (0.7.1)
27
- term-ansicolor (>= 1.0.4)
28
- rake (0.9.2)
29
- shoulda (3.0.1)
30
- shoulda-context (~> 1.0.0)
31
- shoulda-matchers (~> 1.0.0)
32
- shoulda-context (1.0.0)
33
- shoulda-matchers (1.0.0)
34
- term-ansicolor (1.0.7)
35
- vcr (2.1.1)
36
- webmock (1.8.6)
37
- addressable (>= 2.2.7)
38
- crack (>= 0.1.7)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- appraisal
45
- i18n-backend-http!
46
- json
47
- mocha
48
- mynyml-redgreen
49
- rake
50
- shoulda
51
- vcr
52
- webmock
data/Rakefile DELETED
@@ -1,30 +0,0 @@
1
- require 'appraisal'
2
- require 'bundler/gem_tasks'
3
-
4
- task :default do
5
- sh "bundle exec rake appraisal:install && bundle exec rake appraisal test"
6
- end
7
-
8
- require 'rake/testtask'
9
- Rake::TestTask.new(:test) do |test|
10
- test.libs << 'lib'
11
- test.pattern = 'test/**/*_test.rb'
12
- test.verbose = true
13
- end
14
-
15
- # extracted from https://github.com/grosser/project_template
16
- rule /^version:bump:.*/ do |t|
17
- sh "git status | grep 'nothing to commit'" # ensure we are not dirty
18
- index = ['major', 'minor','patch'].index(t.name.split(':').last)
19
- file = 'lib/i18n/backend/http/version.rb'
20
-
21
- version_file = File.read(file)
22
- old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
23
- version_parts[index] = version_parts[index].to_i + 1
24
- version_parts[2] = 0 if index < 2 # remove patch for minor
25
- version_parts[1] = 0 if index < 1 # remove minor for major
26
- new_version = version_parts * '.'
27
- File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
28
-
29
- sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
30
- end
data/Readme.md DELETED
@@ -1,85 +0,0 @@
1
- Rails I18n Backend for Http APIs with etag-aware distributed background polling and lru-memory+[memcache] caching.<br/>
2
- Very few request, always up to date + fast.
3
-
4
- Install
5
- =======
6
-
7
- gem install i18n-backend-http
8
- Or
9
-
10
- rails plugin install git://github.com/grosser/i18n-backend-http.git
11
-
12
- Usage
13
- =====
14
-
15
- ```Ruby
16
- class MyBackend < I18n::Backend::Http
17
- def initialize(options={})
18
- super({
19
- :host => "https://api.host.com",
20
- :cache => Rails.cache,
21
- :http_open_timeout => 5, # default: 1
22
- :http_read_timeout => 5, # default: 1
23
- # :exception_handler => lambda{|e| Rails.logger.error e },
24
- # :memory_cache_size => ??, # default: 10 locales
25
- }.merge(options))
26
- end
27
-
28
- def parse_response(body)
29
- JSON.load(body)["translations"]
30
- end
31
-
32
- def path(locale)
33
- "/path/to/api/#{locale}.json"
34
- end
35
- end
36
-
37
- I18n.backend = MyBackend.new
38
- ```
39
-
40
- ### Polling
41
- Tries to update all used translations every 10 minutes (using ETag and :cache), can be stopped via `I18n.backend.stop_polling`.<br/>
42
- If a :cache is given, all backends pick one master to do the polling, all others refresh from :cache
43
-
44
- ```Ruby
45
- I18n.backend = MyBackend.new(:polling_interval => 30.minutes, :cache => Rails.cache)
46
-
47
- I18n.t('some.key') == "Old value"
48
- # change in backend + wait 30 minutes
49
- I18n.t('some.key') == "New value"
50
- ```
51
-
52
- ### :cache
53
- If you pass `:cache => Rails.cache`, translations will be loaded from cache and updated in the cache.<br/>
54
- The cache **MUST** support :unless_exist, so [gem_of_thrones](https://github.com/grosser/gem_of_thrones) can do its job,<br/>
55
- MemCacheStore + LibmemcachedStore + ActiveSupport::Cache::MemoryStore (edge) work.
56
-
57
- ### Exceptions
58
- To handle http exceptions provide e.g. `:exception_handler => lambda{|e| puts e }` (prints to stderr by default).
59
-
60
- ### Limited memory cache
61
- The backend stores the 10 least recently used locales in memory, if you want to mess with this `:memory_cache_size => 100`
62
-
63
- ### Fallback
64
- If the http backend is down, it does not translate, but also does not constantly try to query -> your app is untranslated but not down.</br>
65
- You should either use :default for all I18n.t or use a Chain, so when http is down e.g. english is used.
66
-
67
- ```Ruby
68
- I18n.backend = I18n::Backend::Chain.new(
69
- MyBackend.new(options),
70
- I18n::Backend::Simple.new
71
- )
72
- ```
73
-
74
-
75
- TODO
76
- ====
77
- - available_locales is not implemented, since we did not need it
78
- - `reload` -> all caches should be cleared
79
-
80
- Author
81
- ======
82
- [Michael Grosser](http://grosser.it)<br/>
83
- michael@grosser.it<br/>
84
- License: MIT<br/>
85
- [![Build Status](https://secure.travis-ci.org/grosser/i18n-backend-http.png)](http://travis-ci.org/grosser/i18n-backend-http)
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "shoulda"
7
- gem "vcr"
8
- gem "webmock"
9
- gem "mocha"
10
- gem "appraisal"
11
- gem "mynyml-redgreen"
12
- gem "json"
13
- gem "i18n", "~>0.4.0"
14
-
15
- gemspec :path=>"../"
@@ -1,53 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/i18n-backend-http
3
- specs:
4
- i18n-backend-http (0.1.0)
5
- faraday
6
- gem_of_thrones
7
- i18n
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- addressable (2.2.8)
13
- appraisal (0.4.1)
14
- bundler
15
- rake
16
- crack (0.3.1)
17
- faraday (0.8.1)
18
- multipart-post (~> 1.1)
19
- gem_of_thrones (0.2.1)
20
- i18n (0.4.2)
21
- json (1.7.1)
22
- metaclass (0.0.1)
23
- mocha (0.11.4)
24
- metaclass (~> 0.0.1)
25
- multipart-post (1.1.5)
26
- mynyml-redgreen (0.7.1)
27
- term-ansicolor (>= 1.0.4)
28
- rake (0.9.2.2)
29
- shoulda (3.0.1)
30
- shoulda-context (~> 1.0.0)
31
- shoulda-matchers (~> 1.0.0)
32
- shoulda-context (1.0.0)
33
- shoulda-matchers (1.0.0)
34
- term-ansicolor (1.0.7)
35
- vcr (2.1.1)
36
- webmock (1.8.7)
37
- addressable (>= 2.2.7)
38
- crack (>= 0.1.7)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- appraisal
45
- i18n (~> 0.4.0)
46
- i18n-backend-http!
47
- json
48
- mocha
49
- mynyml-redgreen
50
- rake
51
- shoulda
52
- vcr
53
- webmock